JSPM

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

Express.js plugin and CLI tool for generating Node.js CRUD APIs with comprehensive Swagger documentation, RBAC authentication system, and enterprise-grade features

Package Exports

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

Express.js CRUD API Generator - Create production-ready REST APIs with authentication, RBAC, and comprehensive Swagger documentation.

npm version npm downloads

๐Ÿš€ Two Ways to Use UCG

Method 1: Add to Existing Project

Install UCG in your existing Express.js project:

# In your existing project directory
npm install ucg

# Dependencies are installed automatically
# Start UCG Dashboard
npx ucg start

# Open browser: http://localhost:3000/ucg
# Complete setup wizard and generate CRUDs visually

Method 2: Quick Setup (New Project)

Create a complete project from scratch:

# In an empty directory
npm install ucg@beta quick-setup

# Or with options
npm install ucg@beta quick-setup --name my-api --db postgres

# Start your API
npm start

# Open UCG Dashboard: http://localhost:3000/ucg

๐ŸŽฏ What You Get

UCG generates complete enterprise-grade APIs with optional authentication:

๐Ÿ”ง Core CRUD Generation

  • Database Models (Sequelize, TypeORM, Knex.js)
  • REST Controllers with full CRUD operations
  • Express Routes with middleware integration
  • Input Validation (express-validator)
  • Swagger Documentation (auto-generated)
  • Unit Tests (Jest test suites)

๐Ÿ” Optional Authentication System (47 endpoints)

When you choose to generate Auth CRUD, you get:

Authentication Endpoints (10)

POST   /api/auth/register           # User registration  
POST   /api/auth/login              # User login
POST   /api/auth/refresh            # Refresh JWT token
POST   /api/auth/forgot-password    # Request password reset
POST   /api/auth/reset-password     # Reset password with token
POST   /api/auth/verify-email       # Verify email address
POST   /api/auth/resend-verification # Resend verification email
GET    /api/auth/me                 # Get current user profile
PUT    /api/auth/change-password    # Change password
POST   /api/auth/logout             # Logout user

RBAC System (23 endpoints)

# Users (4 endpoints)
GET    /api/users                   # List users with filtering
GET    /api/users/:id               # Get user by ID
PUT    /api/users/:id               # Update user
DELETE /api/users/:id               # Delete user

# Roles (7 endpoints)
GET    /api/roles                   # List all roles
POST   /api/roles                   # Create new role
GET    /api/roles/:id               # Get role details
PUT    /api/roles/:id               # Update role
DELETE /api/roles/:id               # Delete role
POST   /api/roles/:id/clone         # Clone role
GET    /api/roles/stats             # Role statistics

# Permissions (10 endpoints)
GET    /api/permissions             # List permissions
POST   /api/permissions             # Create permission
GET    /api/permissions/:id         # Get permission
PUT    /api/permissions/:id         # Update permission
DELETE /api/permissions/:id         # Delete permission
POST   /api/permissions/bulk        # Bulk operations
GET    /api/permissions/resources   # Resource permissions  
POST   /api/permissions/check       # Check user permissions
GET    /api/permissions/user/:id    # User permissions
DELETE /api/permissions/bulk-delete # Bulk delete

# Permission Groups (6 endpoints)
GET    /api/permission-groups       # List permission groups
POST   /api/permission-groups       # Create group
GET    /api/permission-groups/:id   # Get group
PUT    /api/permission-groups/:id   # Update group
DELETE /api/permission-groups/:id   # Delete group
GET    /api/permission-groups/stats # Group statistics

Multi-Tenant Companies (10 endpoints)

GET    /api/companies               # List companies
POST   /api/companies               # Create company
GET    /api/companies/:id           # Get company
PUT    /api/companies/:id           # Update company
DELETE /api/companies/:id           # Delete company
GET    /api/companies/:id/users     # Company users
POST   /api/companies/:id/users     # Add user to company
DELETE /api/companies/:id/users/:userId # Remove user
GET    /api/companies/:id/settings  # Company settings
GET    /api/companies/stats         # Company statistics

Email System (4 endpoints)

POST   /api/email/send              # Send email
POST   /api/email/send-template     # Send template email
GET    /api/email/templates         # List templates
POST   /api/email/templates         # Create template

๐Ÿ–ฅ๏ธ UCG Dashboard (GUI)

After installation, access the visual interface:

  1. Start Dashboard: npx ucg start
  2. Open Browser: http://localhost:3000/ucg
  3. Complete Setup: Follow the setup wizard
  4. Generate CRUDs: Use visual interface to create APIs

Dashboard Features:

  • ๐ŸŽฏ Visual CRUD Generator - Point-and-click API creation
  • ๐Ÿ—„๏ธ Database Management - Visual schema designer
  • ๐Ÿ“Š API Overview - See all generated endpoints
  • ๐Ÿ”ง Configuration - Manage settings visually
  • ๐Ÿ“š Documentation - Interactive API docs

๐Ÿ’ป CLI Usage

Setup Commands

# Initialize UCG in your project (required for first use)
ucg init

# Check project status
ucg status

# Start dashboard
ucg start

Generation Commands

# Generate basic CRUD
ucg generate crud --model User --table users

# Generate Auth CRUD (complete authentication system)  
ucg generate auth

# Generate specific model
ucg generate model --table products

Database Commands

# Run migrations
ucg migrate

# Seed database  
ucg seed

# Test email configuration (if using auth)
ucg test:email

๐Ÿ“‹ Usage Examples

Example 1: Generate Basic CRUD

  1. Open http://localhost:3000/ucg
  2. Click "Generate CRUD"
  3. Enter model details:
    • Model: Product
    • Table: products
    • Fields: name, price, description
  4. Click "Generate"

Via CLI

ucg init                    # Complete setup first
ucg generate crud --model Product --table products

Generated endpoints:

GET    /api/products        # List products
POST   /api/products        # Create product
GET    /api/products/:id    # Get product
PUT    /api/products/:id    # Update product
DELETE /api/products/:id    # Delete product

Example 2: Generate Auth CRUD

  1. Open http://localhost:3000/ucg
  2. Click "Generate Auth System"
  3. Configure:
    • Database credentials
    • JWT secrets
    • Email settings (optional)
  4. Click "Generate Complete Auth System"

Via CLI

ucg init                    # Complete setup first
ucg generate auth          # Generates all 47 auth endpoints

Generated: Complete authentication system with 47 endpoints!

๐Ÿ—„๏ธ Database Setup

Supported Databases

  • PostgreSQL (recommended)
  • MySQL
  • SQLite (development)

Setup Steps

# 1. Create database (PostgreSQL example)
createdb my_api_db

# 2. Configure environment
cp .env.example .env
# Edit .env with your database credentials

# 3. Run migrations
ucg migrate

# 4. Seed initial data (optional)
ucg seed

Environment Configuration

# Database
DATABASE_URL=postgresql://user:pass@localhost:5432/my_db

# JWT (required for auth CRUD)
JWT_SECRET=your-super-secure-secret-minimum-32-characters
JWT_REFRESH_SECRET=your-refresh-secret-minimum-32-characters

# Email (required for auth CRUD)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your-email@gmail.com  
SMTP_PASS=your-16-digit-app-password
EMAIL_FROM=your-email@gmail.com

๐Ÿ“ง Email Configuration (For Auth CRUD)

Gmail Setup (5 minutes)

  1. Enable 2-Factor Authentication in Google Account
  2. Go to Google Account โ†’ Security โ†’ App Passwords
  3. Generate password for "Mail"
  4. Use the 16-digit code in your .env:
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your-email@gmail.com
SMTP_PASS=your-16-digit-app-password
EMAIL_FROM=your-email@gmail.com

Test Email Configuration

ucg test:email

๐Ÿงช Testing Your APIs

1. Basic API Test

# Health check
curl http://localhost:3000/health

# List generated APIs
curl http://localhost:3000/api

2. Auth System Test (if generated)

# Register user
curl -X POST http://localhost:3000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{"email":"test@example.com","password":"Test123!","name":"Test User"}'

# Login
curl -X POST http://localhost:3000/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"test@example.com","password":"Test123!"}'

# Use JWT token for protected endpoints
curl -X GET http://localhost:3000/api/users \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

3. CRUD API Test

# Create product (example)
curl -X POST http://localhost:3000/api/products \
  -H "Content-Type: application/json" \
  -d '{"name":"iPhone","price":999,"description":"Smartphone"}'

# List products
curl http://localhost:3000/api/products

๐Ÿ“š API Documentation

Swagger UI

Visit http://localhost:3000/docs for interactive API documentation with:

  • ๐Ÿ“‹ Complete endpoint list
  • ๐Ÿงช Interactive testing
  • ๐Ÿ“ Request/response examples
  • ๐Ÿ”’ Authentication testing

Postman Collection

UCG automatically generates Postman collections for all APIs.

๐Ÿš€ Production Deployment

Environment Variables

NODE_ENV=production
PORT=3000
DATABASE_URL=your-production-database-url
JWT_SECRET=your-production-jwt-secret
SMTP_HOST=your-production-smtp-server

Docker Deployment

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]

Deploy Commands

# Build for production
npm run build

# Start production server
npm start

# Run migrations in production
NODE_ENV=production ucg migrate

โ— Troubleshooting

Common Issues

Missing dependencies error?

# Reinstall UCG
npm uninstall ucg && npm install ucg

Database connection error?

# Check .env database settings
# Ensure database exists
# Run: ucg migrate

Email not working?

# Check SMTP settings in .env
# For Gmail: Use App Password, not regular password
# Test: ucg test:email

UCG Dashboard not loading?

# Complete setup first
ucg init

# Then start dashboard
ucg start

๐Ÿ”ง Advanced Configuration

Custom Middleware

// Add to your Express app
app.use('/api', yourCustomMiddleware);
app.use('/api', require('ucg').routes);

Custom Templates

UCG supports custom code templates for specific requirements.

Database Migrations

UCG automatically generates and runs migrations for all CRUD operations.

๐Ÿ“ž Support & Documentation

๐Ÿ“„ License

MIT License - see LICENSE file for details.


Made with โค๏ธ by Jithvar Consultancy Services

UCG - From zero to production-ready APIs in minutes!