Skip to content

erishen/nsgm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

NSGM CLI

NSGM CLI License Node.js Downloads

A powerful full-stack development framework with intelligent code generation

Installation โ€ข Quick Start โ€ข Features โ€ข Documentation โ€ข Contributing

๐Ÿš€ Overview

NSGM CLI is a comprehensive full-stack development framework that combines the power of modern web technologies with intelligent code generation capabilities. It helps developers rapidly build scalable web applications through an interactive CLI wizard and automated code templates.

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Frontend      โ”‚    โ”‚   Backend       โ”‚    โ”‚   Database      โ”‚
โ”‚   Next.js       โ”‚โ—„โ”€โ”€โ–บโ”‚   Express.js    โ”‚โ—„โ”€โ”€โ–บโ”‚   MySQL         โ”‚
โ”‚   React         โ”‚    โ”‚   GraphQL       โ”‚    โ”‚   Native SQL    โ”‚
โ”‚   Styled-Comp   โ”‚    โ”‚   REST API      โ”‚    โ”‚   Relations     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐ŸŽฏ Key Features

๐Ÿง™โ€โ™‚๏ธ Intelligent CLI Wizard

  • Smart Mode Detection: Automatically switches between interactive and command-line modes
  • Beginner-Friendly: Step-by-step guided setup for newcomers
  • Expert-Efficient: Quick command-line shortcuts for experienced developers

โšก Rapid Development

  • Code Generation: Automatic CRUD operations, API endpoints, and database schemas
  • Hot Reload: Instant development feedback
  • Type Safety: Full TypeScript support throughout the stack

๐Ÿ”’ Production-Ready Security

  • CSRF Protection: Built-in cross-site request forgery prevention
  • Password Encryption: bcrypt-based secure authentication
  • Session Management: Robust user session handling
  • CSP Headers: Content Security Policy implementation

๐Ÿ—๏ธ Modern Tech Stack

  • Frontend: Next.js 13+, React 18+, Styled-components, Redux Toolkit
  • Backend: Express.js, GraphQL, REST APIs
  • Database: MySQL with native drivers
  • DevTools: TypeScript, ESLint, Prettier, Jest

๐Ÿ“ฆ Installation

Global Installation (Recommended)

# Using npm
npm install -g nsgm-cli

# Using yarn
yarn global add nsgm-cli

# Using pnpm
pnpm add -g nsgm-cli

Verify Installation

nsgm --version
# Should output: 2.1.13

๐Ÿš€ Quick Start

1. Initialize Your First Project

# Start the interactive wizard (recommended for beginners)
nsgm init

# Or specify project name directly
nsgm init my-awesome-app

The wizard will guide you through:

  • โœ… Project name and directory
  • โœ… Database configuration
  • โœ… Security settings
  • โœ… Initial controller setup

2. Environment Setup

cd your-project-name

# Copy environment template
cp .env.example .env

Default Login: admin/admin123

To change password (optional):

# Generate secure password hash
npm run generate-password yourNewPassword

# Edit .env file with generated hash
nano .env

3. Start Development

# Install dependencies
npm install

# Start development server
npm run dev

Your application will be available at http://localhost:3000 with:

  • ๐ŸŽ›๏ธ Admin dashboard with CRUD interface
  • ๐Ÿ“Š Data import/export functionality
  • ๐Ÿ—‘๏ธ Batch operations support
  • ๐Ÿ” Secure login system (Default: admin/admin123)

๐Ÿ› ๏ธ CLI Commands

Core Commands

Command Description Mode Example
nsgm init Initialize new project Interactive/CLI nsgm init blog-app
nsgm create Generate controller with CRUD Interactive/CLI nsgm create user
nsgm delete Remove controller and files Interactive/CLI nsgm delete product
nsgm dev Start development server CLI nsgm dev
nsgm build Build for production CLI nsgm build
nsgm start Start production server CLI nsgm start

Advanced Commands

# Database operations
nsgm deletedb user           # Delete controller + database table

# Project maintenance
nsgm upgrade                 # Upgrade project base files
nsgm export                  # Export static pages

# Development tools
npm run lint                 # Code linting
npm run test                 # Run tests
npm run test:coverage        # Test coverage report

๐ŸŽจ Generated Controller Features

Each controller created with nsgm create includes:

๐Ÿ”ง Backend Components

  • GraphQL Schema: Typed queries and mutations
  • GraphQL Resolvers: Business logic implementation
  • REST API Endpoints: RESTful service layer
  • Database Models: MySQL schema definitions
  • Data Validation: Input sanitization and validation

๐ŸŽฏ Frontend Components

  • React Components: Modern functional components with hooks
  • Styled Components: CSS-in-JS styling
  • Redux Integration: State management
  • Form Handling: Create, edit, and validation forms
  • Data Tables: Sortable, filterable data grids

๐Ÿ“Š CRUD Operations

  • Create: Add new records with validation
  • Read: List, search, and pagination
  • Update: Edit existing records
  • Delete: Single and batch deletion
  • Import/Export: CSV and JSON data handling

๐Ÿ—๏ธ Project Structure

your-project/
โ”œโ”€โ”€ client/                 # Frontend code
โ”‚   โ”œโ”€โ”€ components/         # React components
โ”‚   โ”œโ”€โ”€ layout/            # Layout components
โ”‚   โ”œโ”€โ”€ redux/             # State management
โ”‚   โ”œโ”€โ”€ service/           # API services
โ”‚   โ”œโ”€โ”€ styled/            # Styled components
โ”‚   โ””โ”€โ”€ utils/             # Utility functions
โ”œโ”€โ”€ server/                # Backend code
โ”‚   โ”œโ”€โ”€ apis/              # REST API routes
โ”‚   โ”œโ”€โ”€ modules/           # GraphQL modules
โ”‚   โ”œโ”€โ”€ sql/               # Database scripts
โ”‚   โ””โ”€โ”€ utils/             # Server utilities
โ”œโ”€โ”€ pages/                 # Next.js pages
โ”œโ”€โ”€ public/                # Static assets
โ”œโ”€โ”€ scripts/               # Build and deployment scripts
โ”œโ”€โ”€ __tests__/             # Test files
โ”œโ”€โ”€ .env.example           # Environment template
โ”œโ”€โ”€ next.config.js         # Next.js configuration
โ”œโ”€โ”€ mysql.config.js        # Database configuration
โ””โ”€โ”€ package.json           # Dependencies

โš™๏ธ Configuration

Environment Variables

# .env file
NODE_ENV=development
LOGIN_USERNAME=admin
LOGIN_PASSWORD_HASH=your_generated_hash  # Default: admin123
DATABASE_URL=mysql://user:password@localhost:3306/dbname

# Optional
PORT=3000
NEXT_PUBLIC_API_URL=http://localhost:3000

Database Configuration

// mysql.config.js
module.exports = {
  mysqlOptions: {
    host: process.env.DB_HOST || 'localhost',
    port: process.env.DB_PORT || 3306,
    user: process.env.DB_USER || 'root',
    password: process.env.DB_PASSWORD || '',
    database: process.env.DB_NAME || 'nsgm_db',
  },
}

๐Ÿ”’ Security Setup

Default Authentication

Default Login Credentials: admin/admin123

Custom Password Setup (Optional)

# Generate secure hash for custom password
npm run generate-password yourNewPassword

# Add to .env file
LOGIN_PASSWORD_HASH=your_generated_hash_here

CSRF Protection

NSGM CLI includes built-in CSRF protection:

// Automatic CSRF token generation
app.use(csrfProtection)

// Custom CSP headers
app.use(
  createCSPMiddleware({
    directives: {
      defaultSrc: ["'self'"],
      styleSrc: ["'self'", "'unsafe-inline'"],
      scriptSrc: ["'self'"],
    },
  })
)

๐Ÿงช Testing

# Run all tests
npm test

# Watch mode
npm run test:watch

# Coverage report
npm run test:coverage

# Lint code
npm run lint

# Format code
npm run format

๐Ÿ“š Examples

Creating a Blog System

# 1. Initialize project
nsgm init my-blog

# 2. Create controllers
cd my-blog
nsgm create post
nsgm create category
nsgm create user

# 3. Start development
npm run dev

Adding Custom API Endpoint

// server/apis/custom.js
const express = require('express')
const router = express.Router()

router.get('/stats', (req, res) => {
  res.json({
    totalPosts: 42,
    totalUsers: 15,
    lastUpdate: new Date(),
  })
})

module.exports = router

Custom GraphQL Schema

// server/modules/blog/schema.js
module.exports = {
  query: `
    posts(limit: Int, offset: Int): [Post]
    post(id: ID!): Post
  `,
  mutation: `
    createPost(title: String!, content: String!): Post
    updatePost(id: ID!, title: String, content: String): Post
    deletePost(id: ID!): Boolean
  `,
  type: `
    type Post {
      id: ID!
      title: String!
      content: String!
      createdAt: Date!
      updatedAt: Date!
    }
  `,
}

๐Ÿš€ Performance & Production

Build Optimization

# Production build
npm run build

# Analyze bundle size
npm run analyze

# Export static site
npm run export

Production Deployment

Local Deployment

# Start production server
npm start

# Or use PM2
pm2 start npm --name "nsgm-app" -- start

Vercel Deployment (Recommended)

NSGM CLI ๅฎŒๅ…จๆ”ฏๆŒ Vercel ้ƒจ็ฝฒ๏ผŒๅŒ…ๆ‹ฌ่‡ชๅŠจๅŒ– CI/CD ๆต็จ‹ใ€‚

ๅฟซ้€Ÿๅผ€ๅง‹๏ผš

  1. ๆŽจ้€้กน็›ฎๅˆฐ GitHub
  2. ่ฎฟ้—ฎ Vercel Dashboard
  3. ๅฏผๅ…ฅ GitHub ไป“ๅบ“
  4. ้…็ฝฎ็Žฏๅขƒๅ˜้‡๏ผˆๅ‚่€ƒ .env.vercel.example๏ผ‰
  5. ็‚นๅ‡ป "Deploy"

่ฏฆ็ป†ๆŒ‡ๅ—๏ผš ๆŸฅ็œ‹ VERCEL_DEPLOYMENT.md

็‰นๆ€ง๏ผš

  • โœ… ่‡ชๅŠจ CI/CD ๆต็จ‹
  • โœ… ้ข„่งˆ็Žฏๅขƒ๏ผˆๆฏไธช PR๏ผ‰
  • โœ… ่‡ชๅŠจ HTTPS
  • โœ… ๅ…จ็ƒ CDN
  • โœ… ๆ— ๆœๅŠกๅ™จๅ‡ฝๆ•ฐ
  • โœ… ไธ€้”ฎๅ›žๆปš

็Žฏๅขƒๅ˜้‡้…็ฝฎ๏ผš

NODE_ENV=production
LOGIN_USERNAME=admin
LOGIN_PASSWORD_HASH=your_hash
DATABASE_URL=mysql://...

่Žทๅ–ๅฏ†็ ๅ“ˆๅธŒ๏ผš

npm run generate-password yourPassword

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

# Clone repository
git clone https://github.com/erishen/nsgm.git
cd nsgm

# Install dependencies
npm install

# Run tests
npm test

# Build CLI
npm run tsbuild

๐Ÿ“– Documentation

๐Ÿ› Troubleshooting

Common Issues

Port already in use

# Kill process on port 3000
lsof -ti:3000 | xargs kill -9

# Or use different port
PORT=3001 npm run dev

Database connection failed

# Check MySQL service
sudo systemctl status mysql

# Verify credentials in .env
cat .env | grep DB_

Permission denied

# Fix npm permissions
sudo chown -R $(whoami) ~/.npm

# Or use different install location
npm config set prefix '~/.local'

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments


Made with โค๏ธ by the NSGM Team

GitHub โ€ข npm โ€ข Issues

About

A powerful full-stack development framework with intelligent code generation

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published