JSPM

  • Created
  • Published
  • Downloads 56
  • Score
    100M100P100Q62816F
  • License MIT

Universal CRUD Generator - Database-first code generation tool for Node.js projects

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 init and ucg quick-setup commands
  • 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 start

Option 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 output

ucg 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      # Delete

Features

  • 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/controllers

Package 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.md

Running 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

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Adding New Database Support

  1. Create folder: src/databases/your-database/
  2. 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


Made with โค๏ธ by the UCG team. Happy coding! ๐Ÿš€