JSPM

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

Universal CRUD Generator - Database-first code generation tool with Settings page, ORM selection, and advanced filtering

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 with comprehensive Swagger/OpenAPI documentation.

๐Ÿš€ Features

  • Database-First Approach: Introspect existing databases to generate code
  • Multiple Database Support: PostgreSQL, MySQL, SQLite, MongoDB
  • Multiple ORM Support: Prisma, Sequelize, Mongoose adapters
  • Comprehensive Swagger Documentation: Auto-generated OpenAPI specs with examples
  • 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
  • Modern UI: Clean, responsive dashboard with preview capabilities
  • No File Pollution: Everything served from the plugin, minimal host project changes

๐Ÿ“ฆ Installation & Downloads

Latest Release

npm install ucg@latest

Get the latest features and improvements with comprehensive Swagger documentation:

npm install ucg@beta

Development Version

npm install ucg@1.2.1-beta.7

Download Summary

Version Features Database Support Swagger Docs
1.2.1-beta.7 Latest beta with complete Swagger documentation PostgreSQL, MySQL, SQLite, MongoDB โœ… Complete
1.2.1-beta.6 Previous beta PostgreSQL, MySQL, SQLite, MongoDB โš ๏ธ Basic
1.2.0 Stable release PostgreSQL, MySQL, SQLite, MongoDB โŒ Limited

NPM Distribution Tags

  • latest - Stable release
  • beta - Beta releases with new features
  • alpha - Development releases

๐ŸŽฏ 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

UCG supports multiple databases with comprehensive adapters:

PostgreSQL โœ…

  • Prisma: Full introspection, model generation, CRUD operations, Swagger docs
  • Sequelize: Table structure detection, model/controller generation, Swagger docs
  • Mongoose: Mock adapter (demonstrates architecture)

MySQL โœ…

  • Prisma: Full introspection, model generation, CRUD operations, Swagger docs
  • Sequelize: Table structure detection, model/controller generation
  • TypeORM: Coming soon

SQLite โœ…

  • Prisma: Full introspection, model generation, CRUD operations, Swagger docs
  • Sequelize: Table structure detection, model/controller generation
  • Better-SQLite3: Coming soon

MongoDB โœ…

  • Prisma: Full document introspection, schema generation, CRUD operations, Swagger docs
  • Mongoose: Native MongoDB adapter with full ODM support
  • Native Driver: Coming soon

Database Features Comparison

Database Introspection CRUD Generation Swagger Docs Relationships Migrations
PostgreSQL โœ… โœ… โœ… โœ… โœ…
MySQL โœ… โœ… โœ… โœ… โœ…
SQLite โœ… โœ… โœ… โœ… โœ…
MongoDB โœ… โœ… โœ… โœ… โš ๏ธ

Connection Examples

PostgreSQL

{
  "database": "postgresql",
  "orm": "prisma",
  "credentials": {
    "host": "localhost",
    "port": 5432,
    "database": "myapp",
    "user": "postgres",
    "password": "password"
  }
}

MySQL

{
  "database": "mysql",
  "orm": "prisma",
  "credentials": {
    "host": "localhost",
    "port": 3306,
    "database": "myapp",
    "user": "root",
    "password": "password"
  }
}

SQLite

{
  "database": "sqlite",
  "orm": "prisma",
  "credentials": {
    "database": "./data/app.db"
  }
}

MongoDB

{
  "database": "mongodb",
  "orm": "prisma",
  "credentials": {
    "host": "localhost",
    "port": 27017,
    "database": "myapp",
    "user": "admin",
    "password": "password"
  }
}

Extensible Architecture

The database-first folder structure makes it easy to add new databases:

src/databases/
โ”œโ”€โ”€ postgresql/          # PostgreSQL adapters
โ”‚   โ”œโ”€โ”€ prisma/         # Prisma adapter
โ”‚   โ”œโ”€โ”€ sequelize/      # Sequelize adapter
โ”‚   โ””โ”€โ”€ mongoose/       # Mock adapter
โ”œโ”€โ”€ mysql/              # MySQL adapters
โ”‚   โ”œโ”€โ”€ prisma/         # Prisma adapter
โ”‚   โ””โ”€โ”€ sequelize/      # Sequelize adapter
โ”œโ”€โ”€ sqlite/             # SQLite adapters
โ”‚   โ”œโ”€โ”€ prisma/         # Prisma adapter
โ”‚   โ””โ”€โ”€ sequelize/      # Sequelize adapter
โ””โ”€โ”€ mongodb/            # MongoDB adapters
    โ”œโ”€โ”€ prisma/         # Prisma adapter
    โ””โ”€โ”€ mongoose/       # Mongoose adapter

๐ŸŽจ 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 & Swagger Documentation

Generated Endpoints

For each model, UCG generates RESTful endpoints with comprehensive Swagger documentation:

GET    /models          # List with pagination (clean - no filter examples)
GET    /models/:id      # Get by ID
POST   /models          # Create new (with request/response examples)
PUT    /models/:id      # Update (with request/response examples)
DELETE /models/:id      # Delete (with response examples)

Swagger Documentation Features

UCG generates comprehensive OpenAPI 3.0 specifications with:

โœ… Clean GET Operations

  • Pagination parameters only
  • No cluttered filter examples
  • Clear response schemas

โœ… Rich POST/PUT/DELETE Operations

  • Detailed request body examples
  • Response examples for all status codes
  • Error handling documentation

โœ… Complete Component Schemas

  • Model definitions with examples
  • Error response schemas
  • Pagination metadata schemas

โœ… Database-Specific Adaptations

  • MongoDB: ObjectId format handling
  • PostgreSQL/MySQL/SQLite: Integer ID autoincrement
  • All databases: Consistent schema patterns

Example Generated Swagger

# Clean GET endpoint (no examples)
/users:
  get:
    summary: Get all users
    parameters:
      - name: page
        in: query
        schema:
          type: integer
      - name: limit
        in: query
        schema:
          type: integer
    responses:
      '200':
        description: Users retrieved successfully

# Rich POST endpoint (with examples)
/users:
  post:
    summary: Create a new user
    requestBody:
      required: true
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UserCreate'
          example:
            name: "John Doe"
            email: "john@example.com"
            age: 30
    responses:
      '201':
        description: User created successfully
        content:
          application/json:
            example:
              id: 1
              name: "John Doe"
              email: "john@example.com"
              age: 30
              createdAt: "2024-01-01T00:00:00Z"

API Features

  • Pagination: Built-in pagination support with metadata
  • Validation: Input validation middleware with error responses
  • Relationships: Foreign key relationships populated automatically
  • Error Handling: Consistent error responses across all endpoints
  • Status Codes: Proper HTTP status codes (200, 201, 400, 404, 500)
  • Content Types: JSON request/response handling

๐Ÿงช Testing & Validation

Testing the UCG Package

# Test the plugin itself
npm test

# Test Swagger documentation templates
node test-swagger-documentation.js

# Test with real databases
node real-database-test.js

# Test SQLite with rich data
node sqlite-focus-test.js

Testing Generated Code

UCG generates unit tests for all generated code:

# Test generated code in your project
npm test  # Run tests for generated models/controllers

Validation Features

UCG includes comprehensive validation testing:

โœ… Template Validation

  • All 6 database adapter templates validated
  • Swagger documentation completeness checked
  • HTTP method coverage verified

โœ… Database Testing

  • Real database connection testing
  • CRUD operation validation
  • Relationship handling verification

โœ… Integration Testing

  • Dashboard functionality
  • API endpoint generation
  • Swagger UI integration

Package Testing Workflow

Before publishing, test the package:

# Create tarball
npm pack

# Install in test project
cd /path/to/test-project
npm install /path/to/ucg-1.2.1-beta.7.tgz

# Test functionality
npx ucg init
# Visit /ucg/setup and test dashboard
# Generate models and test API endpoints

Docker Testing

Test with multiple databases using Docker:

# PostgreSQL
docker run --name test-postgres -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgres:15

# MySQL
docker run --name test-mysql -e MYSQL_ROOT_PASSWORD=password -p 3306:3306 -d mysql:8

# MongoDB
docker run --name test-mongo -p 27017:27017 -d mongo:7

๐ŸŽฏ 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 & Changelog

Current Version (1.2.1-beta.7) - Latest Beta โœจ

  • โœ… Complete Swagger Documentation: Comprehensive OpenAPI specs for all database adapters
  • โœ… Clean GET Operations: No cluttered filter examples, pagination params only
  • โœ… Rich POST/PUT/DELETE: Detailed request/response examples for all mutations
  • โœ… Multi-Database Support: PostgreSQL, MySQL, SQLite, MongoDB with full CRUD
  • โœ… Database-Specific Handling: ObjectId for MongoDB, integer IDs for SQL databases
  • โœ… Template Validation: All 6 adapters pass comprehensive testing
  • โœ… Real Database Testing: Validated with Docker containers and rich test data

Previous Versions

1.2.1-beta.6

  • โœ… Multi-database support foundation
  • โœ… Basic Swagger documentation
  • โš ๏ธ Limited API examples

1.2.0 - Stable Release

  • โœ… PostgreSQL + Prisma/Sequelize support
  • โœ… Web dashboard with modern UI
  • โœ… Model and CRUD generation
  • โœ… CLI tools (init, quick-setup)
  • โŒ Limited Swagger documentation

Upcoming Features

Next Release (1.2.2)

  • Enhanced UI: Code editor with syntax highlighting
  • Bulk Operations: Generate multiple models at once
  • Custom Templates: User-defined code templates
  • Migration Tools: Database schema migration support

Future Enhancements (1.3.0+)

  • More ORMs: TypeORM, Knex.js, DrizzleORM
  • GraphQL Generation: Auto-generated GraphQL schemas and resolvers
  • API Versioning: Support for multiple API versions
  • Advanced Relationships: Many-to-many, polymorphic relationships
  • Performance: Query optimization and caching
  • Testing: Generated test suites with coverage reports

UI/UX Improvements

  • Dark Mode: Theme switching capability
  • Mobile Responsive: Full mobile dashboard support
  • Real-time Preview: Live code preview as you configure
  • Diff Viewer: Compare generated code changes
  • Export/Import: Configuration backup and restore

Breaking Changes

  • 1.2.0 โ†’ 1.2.1: Configuration format updated for multi-database support
  • 1.1.x โ†’ 1.2.0: Dashboard routes restructured, CLI commands updated

๐Ÿค Contributing

We welcome contributions! Here's how to get started:

Quick Start

  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

Development Setup

# Clone and setup
git clone https://github.com/your-repo/ucg.git
cd ucg
npm install

# Run development server
npm run dev

# Run tests
npm test

# Lint code
npm run lint

# Test Swagger documentation
node test-swagger-documentation.js

# Test with real databases
node real-database-test.js

Adding New Database Support

  1. Create Database Folder

    src/databases/your-database/
    โ”œโ”€โ”€ prisma/           # Prisma adapter
    โ”œโ”€โ”€ sequelize/        # Sequelize adapter
    โ””โ”€โ”€ your-orm/         # Your ORM adapter
  2. Implement Required Interface Each adapter must implement:

    // Database connection and introspection
    async introspectTables(connectionConfig)
    async testConnection(connectionConfig)
    
    // Code generation
    async generateModelCode(table, options)
    async generateCRUD(model, options)
    
    // Swagger documentation
    generateSwaggerComponents(model)
    generateSwaggerPaths(model)
  3. Add Swagger Documentation

    • Component schemas with examples
    • Clean GET operations (no filter examples)
    • Rich POST/PUT/DELETE operations with examples
    • Database-specific ID handling (ObjectId vs integer)
  4. Create Tests

    // Add to test-swagger-documentation.js
    // Add real database test cases
    // Validate generated code works

Adding New ORM Support

  1. Create ORM Adapter Folder

    src/databases/database-name/your-orm/
    โ”œโ”€โ”€ index.js          # Main adapter
    โ”œโ”€โ”€ introspection.js  # Database introspection
    โ”œโ”€โ”€ generator.js      # Code generation
    โ””โ”€โ”€ templates/        # Code templates
        โ”œโ”€โ”€ model.js
        โ”œโ”€โ”€ controller.js
        โ”œโ”€โ”€ service.js
        โ””โ”€โ”€ routes.js
  2. Follow Template Patterns

    • Study existing adapters (Prisma, Sequelize)
    • Use consistent naming conventions
    • Include comprehensive Swagger documentation
    • Handle relationships properly

Testing Guidelines

  • Write tests for new database adapters
  • Test with real databases using Docker
  • Validate Swagger docs are complete and correct
  • Check generated code compiles and works
  • Follow existing patterns for consistency

Code Style

  • Use ES6+ features
  • Follow existing patterns
  • Add JSDoc comments for public functions
  • Use meaningful variable names
  • Keep functions small and focused

Documentation

  • Update README.md for new features
  • Add JSDoc comments for new functions
  • Include examples in pull requests
  • Update roadmap if adding major features

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿ™‹โ€โ™‚๏ธ Support & Resources

Documentation

Community

Getting Help

Release Information


Made with โค๏ธ by the UCG team

๐ŸŒŸ Star us on GitHub if UCG helps with your projects!
๐Ÿš€ Happy coding with Universal CRUD Generator!