Package Exports
- ucg
- ucg/src/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ucg) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
UCG (Universal CRUD Generator)
A powerful, database-first CRUD generator for Node.js applications. UCG provides an interactive CLI and web dashboard to generate models, controllers, services, and API endpoints for your database tables.
๐ Features
- Database-First Approach: Introspect existing databases to generate code
- Multiple ORM Support: Prisma, Sequelize, Mongoose adapters
- Web Dashboard: Interactive UI for code generation served from
node_modules - CLI Tools:
ucg initanducg quick-setupcommands - Pluggable Architecture: Easy to add new databases and ORMs
- Auto-Generated API Docs: Swagger/OpenAPI documentation
- Modern UI: Clean, responsive dashboard with preview capabilities
- No File Pollution: Everything served from the plugin, minimal host project changes
๐ฆ Installation
npm install ucg๐ฏ Quick Start
Option 1: Add to Existing Project
# Install in your existing Node.js project
npm install ucg
# Initialize UCG (adds routes to your app.js/server.js)
npx ucg init
# Start your application and visit /ucg/setup
npm startOption 2: Create New Project
# Create a new project with UCG pre-configured
npx ucg quick-setup
# Follow the prompts, then:
cd your-project-name
npm install
npm start
# Visit http://localhost:3000/ucg/setup๐ ๏ธ Usage
CLI Commands
ucg init
Adds UCG to an existing Node.js project by mounting the router.
npx ucg init [--json] # --json for machine-readable outputucg quick-setup
Creates a new Node.js project with UCG pre-configured.
npx ucg quick-setup [--json]Dashboard URLs
After running ucg init or ucg quick-setup, these URLs will be available:
/ucg/setup- First-time configuration wizard/ucg/login- Dashboard login/ucg/dashboard- Main dashboard with table overview/ucg/generate/model- Model generator/ucg/generate/crud- CRUD generator/ucg/api-docs- Auto-generated API documentation
๐๏ธ Database Support
PostgreSQL (Primary)
- Prisma: Full introspection, model generation, CRUD operations
- Sequelize: Table structure detection, model/controller generation
- Mongoose: Mock adapter (demonstrates architecture)
Extensible Architecture
The database-first folder structure makes it easy to add new databases:
src/databases/
โโโ postgresql/ # Database folder
โ โโโ prisma/ # ORM adapter
โ โโโ sequelize/ # ORM adapter
โ โโโ mongoose/ # ORM adapter
โโโ mysql/ # Future: Add MySQL support
โโโ prisma/
โโโ sequelize/
โโโ typeorm/๐จ Generated Code Structure
UCG generates clean, production-ready code:
your-project/
โโโ src/
โ โโโ controllers/ # Express controllers with full CRUD
โ โโโ services/ # Business logic layer
โ โโโ routes/ # Express routes with middleware
โ โโโ models/ # ORM models (Prisma/Sequelize/etc)
โ โโโ validation/ # Input validation middleware
โ โโโ tests/ # Unit tests for generated code๐ง Configuration
UCG stores its configuration in node_modules/ucg/.ucg/config.json - no files are created in your project root.
Example Configuration
{
"database": "postgresql",
"orm": "prisma",
"credentials": {
"host": "localhost",
"port": 5432,
"database": "myapp",
"user": "postgres",
"tablePrefix": "app_"
},
"user": {
"email": "admin@example.com"
}
}๐ฆ API Generation
Generated Endpoints
For each model, UCG generates RESTful endpoints:
GET /models # List with pagination
GET /models/:id # Get by ID
POST /models # Create new
PUT /models/:id # Update
DELETE /models/:id # DeleteFeatures
- Pagination: Built-in pagination support
- Validation: Input validation middleware
- Relationships: Foreign key relationships populated
- Error Handling: Consistent error responses
- Swagger Docs: Auto-generated API documentation
๐งช Testing
UCG generates unit tests for all generated code:
# Test the plugin itself
npm test
# Test generated code in your project
npm test # Run tests for generated models/controllersPackage Testing
Test the UCG package before publishing:
# Create tarball
npm pack
# Install in test project
cd /path/to/test-project
npm install /path/to/ucg-1.0.0.tgz
# Test functionality
npx ucg init
# ... test dashboard and generation๐ฏ Development
Project Structure
ucg/
โโโ package.json
โโโ bin/ucg # CLI entry point
โโโ src/
โ โโโ index.js # Main exports
โ โโโ server.js # Standalone server (dev)
โ โโโ cli/ # CLI implementations
โ โ โโโ init.js
โ โ โโโ quick-setup.js
โ โโโ databases/ # Database-first adapters
โ โ โโโ postgresql/
โ โ โโโ prisma/ # Prisma adapter
โ โ โโโ sequelize/ # Sequelize adapter
โ โ โโโ mongoose/ # Mongoose adapter
โ โโโ ui/ # Web dashboard
โ โ โโโ routes/ # Express routes
โ โ โโโ views/ # Handlebars templates
โ โ โโโ static/ # CSS/JS assets
โ โโโ lib/ # Utilities
โ โ โโโ config.js # Configuration management
โ โ โโโ utils.js # Helper functions
โ โโโ tests/ # Unit tests
โโโ .ucg-config.example.json # Example configuration
โโโ README.mdRunning in Development
# Clone and setup
git clone <repo>
cd ucg
npm install
# Run development server
npm run dev
# Run tests
npm test
# Lint code
npm run lint๐ Security
- Password Hashing: User passwords hashed with bcrypt
- Configuration Security: Database credentials stored in plugin directory
- Input Validation: All generated endpoints include validation
- No Secrets: No hardcoded secrets in the repository
๐ API Reference
CLI Integration
When you run ucg init, it adds these lines to your app:
// CommonJS
const ucg = require('ucg');
app.use('/ucg', ucg.router);
// ES Modules
import ucg from 'ucg';
app.use('/ucg', ucg.router);Programmatic Usage
const { router } = require('ucg');
const configManager = require('ucg/src/lib/config');
const utils = require('ucg/src/lib/utils');
// Mount UCG in your app
app.use('/admin/ucg', router);
// Access configuration
const config = await configManager.getConfig();
// Use utilities
const modelName = utils.tableNameToModelName('user_profiles');๐ฃ๏ธ Roadmap
Current Version (1.0.0)
- โ PostgreSQL + Prisma/Sequelize support
- โ Web dashboard with modern UI
- โ Model and CRUD generation
- โ
CLI tools (
init,quick-setup) - โ Auto-generated API documentation
Future Enhancements
- More Databases: MySQL, SQLite, MSSQL
- More ORMs: TypeORM, Knex.js
- Advanced Features:
- Custom templates
- Bulk operations
- API versioning
- GraphQL generation
- UI Improvements:
- Code editor with syntax highlighting
- Dark mode
- Mobile responsiveness
๐ค Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Adding New Database Support
- Create folder:
src/databases/your-database/ - Add ORM adapters following the interface:
introspectTables(connectionConfig)generateModelCode(table, options)generateCRUD(model, options)testConnection(connectionConfig)
๐ License
MIT License - see LICENSE file for details.
๐โโ๏ธ Support
- ๐ Documentation
- ๐ Issues
- ๐ฌ Discussions
Made with โค๏ธ by the UCG team. Happy coding! ๐