- Overview
- Architecture
- Dependencies
- Core Components
- Project Templates
- Internal Workflow
- File Structure
- Command Execution
- Configuration System
- Error Handling
- Development Setup
- Performance Considerations
InitGen is a Node.js-based CLI tool that scaffolds modern web and backend projects with zero configuration. It provides an interactive interface for creating production-ready projects across multiple tech stacks.
- Interactive CLI with beautiful animations
- Support for 12+ tech stacks including shadcn/ui and Database ORMs
- Database ORM integration (Prisma, Drizzle) with PostgreSQL
- Automatic dependency installation
- TypeScript support
- Git integration
- Production-ready configurations
- Database migration and schema management tools
InitGen follows a modular architecture with clear separation of concerns:
┌─────────────────┐
│ Entry Point │ index.js (CLI Interface)
│ (index.js) │
└─────────┬───────┘
│
┌─────▼─────┐
│ Core │ Main orchestration logic
│ Engine │ User interaction & flow control
└─────┬─────┘
│
┌─────▼─────┐
│Templates │ Project-specific generators
│ System │ (React, Next.js, Python, etc.)
└─────┬─────┘
│
┌─────▼─────┐
│Utilities │ Common functions
│& Config │ (Commands, README, Git)
└───────────┘
- Entry Point (
index.js): CLI interface, user prompts, flow orchestration - Templates (
src/templates/): Stack-specific project generators - Configuration (
src/config/): Stack definitions and git templates - Utilities (
src/utils/): Shared functionality (commands, file operations)
- Purpose: Terminal string styling and coloring
- Usage: Error messages (
chalk.red()), success indicators (chalk.green()), colored output - Implementation: Used in spinners, warnings, success messages throughout CLI flow
- Purpose: Animated terminal text effects
- Usage: Welcome screen rainbow animation for "Project Structure Generator 🚀"
- Implementation:
chalkAnimation.rainbow()with 1000ms timeout inshowTitle()
- Purpose: ASCII art text generation for branding
- Usage: Generate large "InitGen" title display
- Implementation:
figlet.textSync('InitGen', { font: 'Standard' })with gradient overlay
- Purpose: Gradient color effects on ASCII text
- Usage: Pastel gradient applied to figlet ASCII title
- Implementation:
gradient.pastel.multiline(asciiText)for visual appeal
- Purpose: Interactive command-line user prompts
- Usage: Tech stack selection, project naming, TypeScript choice, Git initialization
- Implementation: Three separate prompt sequences with validation and conditional logic
- Purpose: Elegant terminal loading spinners with status updates
- Usage: Progress indication during project creation with success/error states
- Implementation:
createSpinner().start(),.success(),.error()pattern
- Purpose: Tailwind CSS v4 Vite plugin integration
- Usage: Automatically installs and configures in
vite-tailwindprojects - Implementation: Added to vite.config.js as
tailwindcss()plugin insetupTailwind()
- Purpose: Core Tailwind CSS v4 framework
- Usage: CSS framework installed with
--legacy-peer-depsflag in Tailwind projects - Implementation: Dynamically installed via
runCommand()during project setup
#!/usr/bin/env node
// Entry point with proper shebang for CLI execution
// Core flow:
showTitle() → mainMenu() → createProject() → postSetup()Key Functions:
showTitle(): 1000ms rainbow animation + ASCII "InitGen" with pastel gradientmainMenu(): 8 tech stack choices + project naming + TypeScript/Git promptscreateProjectStructure(): Main orchestrator handling manual vs command-based projectsrun(): Entry point coordinating title → menu → creation → success message
Each template module handles specific tech stack generation:
export async function setupReactViteTemplate(projectName, useTypeScript, projectPath)- Creates Vite + React project with optional TypeScript
- Configures development environment
- Sets up proper project structure
export async function setupTailwind(projectPath, useTypeScript)- Installs Tailwind CSS v4
- Configures Vite for Tailwind processing
- Creates optimized CSS configuration
export async function setupNextjsTemplate(projectName, useTypeScript, projectPath)- Uses
create-next-appwith appropriate flags - Configures TypeScript if selected
- Sets up development server
export async function setupVueTemplate(projectName, useTypeScript, projectPath)- Creates Vue 3 project with Vite
- TypeScript integration support
- Component-based architecture setup
export async function setupShadcn(projectPath, projectName, useTypeScript)- Installs Tailwind CSS v4 + @tailwindcss/vite + @types/node
- Configures path aliases (@/*) in vite.config and tsconfig files
- Runs
npx shadcn@latest initwith pre-configured components.json - Creates demo App component with Button variants
- Updates CSS with shadcn-compatible styling
Handles backend frameworks that require custom file generation:
// Node.js + Express
export async function createNodeExpressProject(projectName, useTypeScript, projectPath)
// Database ORM Projects (v2.1.0+)
export async function createNodePrismaProject(projectPath, projectName, useTypeScript)
export async function createNodeDrizzleProject(projectPath, projectName, useTypeScript)
// Python frameworks
export async function createPythonFlaskProject(projectName, projectPath)
export async function createPythonFastAPIProject(projectName, projectPath)
export async function createPythonDjangoProject(projectName, projectPath)Defines available tech stacks and their properties:
export const stackCommands = {
'react-vite': {
command: null, // Dynamically: `npm create vite@latest ${name} -- --template react[-ts]`
name: 'React (Vite)',
needsInstall: false, // Auto-installs via npm install + setupReactViteTemplate()
},
'vite-tailwind': {
command: null, // Same as react-vite but triggers setupTailwind()
name: 'Vite + React + Tailwind v4',
setupTailwind: true, // Installs Tailwind v4 + @tailwindcss/vite plugin
},
'vite-shadcn': {
command: null, // Vite + React + full shadcn/ui setup
name: 'Vite + React + Tailwind + shadcn/ui',
setupShadcn: true, // Full shadcn setup: Tailwind + path aliases + components
},
'nextjs-shadcn': {
command: null, // Next.js + shadcn/ui integration
name: 'Next.js + shadcn/ui',
setupShadcn: true, // Adds shadcn to existing Next.js setup
},
'node-express': {
name: 'Node.js + Express',
manual: true, // Creates files manually via createNodeExpressProject()
},
'node-prisma': {
name: 'Node.js + Express + Prisma (PostgreSQL)',
manual: true, // Creates files manually via createNodePrismaProject()
},
'node-drizzle': {
name: 'Node.js + Express + Drizzle (PostgreSQL)',
manual: true, // Creates files manually via createNodeDrizzleProject()
},
// ... 3 more Python stacks (flask, fastapi, django)
};Pre-configured .gitignore files for different project types:
export const gitignoreTemplates = {
javascript: `
# dependencies + production + misc + logs + editor + next.js + cache
node_modules/, .env variants, build/dist/, .DS_Store, npm logs,
.vscode/, .next/, .cache, .turbo (45 lines total)`,
python: `
# Byte-compiled + Virtual env + Django/Flask + Distribution + IDE + OS
__pycache__/, venv/, *.log, db.sqlite3, dist/, .vscode/, .DS_Store
(35 lines total with detailed Python-specific patterns)`,
};export async function runCommand(command, cwd) {
return execPromise(command, { cwd, maxBuffer: 1024 * 1024 * 10 });
}
// 10MB buffer for handling large npm/pip outputs
// Promisified child_process.exec with working directory support- Promisified
child_process.exec - Large buffer for handling npm/pip output
- Working directory support
export function createReadme(projectName, stack, useTypeScript)
export function createPythonReadme(projectName, framework)- Generates stack-specific README files
- Includes proper run commands and project structure
- Language-specific documentation
User runs `initgen` → Show animated title → Display main menu
Tech stack selection → Project naming → Language choice → Git preference
1. `npm create vite@latest ${name} -- --template react[-ts]`
2. `npm install` in project directory
3. setupReactViteTemplate() → Custom App.jsx/tsx + 214 lines CSS
4. setupTailwind() (if vite-tailwind) → Install v4 + configure vite.config
5. Generate custom README with stack info
1. `npx create-next-app@latest ${name} --typescript|js --tailwind --eslint --app --src-dir`
2. setupNextjsTemplate() → Custom page.tsx with 233 lines of styled components
3. No separate npm install (create-next-app handles it)
1. fs.mkdirSync() → Create src/, routes/, controllers/ directories
2. Generate package.json with dependencies (Express, CORS, dotenv)
3. Create index.ts/js with full Express server + routes (100+ lines)
4. `npm install` or `pip install -r requirements.txt`
5. Custom README with framework-specific run commands
1. Initialize Git repository (if requested)
2. Create appropriate .gitignore
3. Display success message with next steps
4. Provide run commands
my-react-app/
├── public/
│ └── vite.svg
├── src/
│ ├── App.tsx
│ ├── main.tsx
│ └── index.css
├── index.html
├── package.json
├── tsconfig.json
├── vite.config.ts
└── README.md
my-node-app/
├── src/
│ ├── index.ts
│ ├── routes/
│ │ └── api.ts
│ └── middleware/
│ └── cors.ts
├── package.json
├── tsconfig.json
├── .env.example
└── README.md
my-prisma-app/
├── src/
│ └── index.ts
├── prisma/
│ └── schema.prisma
├── package.json
├── tsconfig.json
├── .env.example
├── .gitignore
└── README.md
my-drizzle-app/
├── src/
│ ├── index.ts
│ └── db/
│ ├── index.ts # Database connection with dotenv.config()
│ ├── schema.ts # Database schema definitions
│ ├── create.ts # Auto database creation script
│ ├── migrate.ts # Migration runner
│ └── migrations/ # Generated migration files
├── drizzle.config.js # Drizzle configuration
├── package.json
├── tsconfig.json
├── .env.example
├── .gitignore
└── README.md
my-flask-app/
├── app.py
├── requirements.txt
├── .env.example
├── templates/
│ └── index.html
├── static/
│ └── style.css
└── README.md
project-scaffold-cli/
├── index.js # 439 lines - Main CLI entry point (updated v2.1.0)
├── package.json # 6 dependencies + 2 devDependencies
├── README.md # User-facing documentation (updated v2.1.0)
├── TECHNICAL_DOCS.md # Technical documentation (updated v2.1.0)
├── LICENSE # MIT license
├── .npmignore # Excludes docs/, node_modules/
└── src/
├── config/
│ ├── stackCommands.js # 12 tech stacks configuration (50+ lines, +2 DB stacks)
│ └── gitignoreTemplates.js # JS + Python + DB .gitignore templates (95+ lines)
├── templates/
│ ├── reactVite.js # 214 lines - React + CSS styling
│ ├── tailwind.js # 146 lines - Tailwind v4 setup + vite config
│ ├── shadcn.js # 300+ lines - shadcn/ui setup + components
│ ├── nextjs.js # 350+ lines - Next.js + optional shadcn support
│ ├── vue.js # 239 lines - Vue 3 SFC with styling
│ └── manualProjects.js # 1100+ lines - Node/Python/Database generators (+600 lines v2.1.0)
└── utils/
├── command.js # 12 lines - Enhanced exec with timeout & buffer (v2.1.0)
└── readme.js # 120+ lines - Dynamic README + Database docs (v2.1.0)
- Auto-generated Prisma Client with TypeScript support
- Database migration system via
prisma migrate dev - Prisma Studio for visual database management
- Schema-first approach with commented examples
- PostgreSQL integration with proper connection handling
- Lightweight ORM with excellent TypeScript support
- Auto database creation via custom
db:createscript - Schema generation and migration tools
- Drizzle Studio for database visualization
- Robust environment loading with
dotenv.config()in database connection - Zero-config Docker compatibility
// Fixed in v2.1.0: Environment variables now load properly in database connections
import dotenv from 'dotenv';
dotenv.config(); // Added to src/db/index.ts to fix DATABASE_URL undefined issues// New in v2.1.0: Automatic database creation script
export async function createDatabase() {
const databaseUrl = process.env.DATABASE_URL;
const url = new URL(databaseUrl);
const dbName = url.pathname.slice(1);
// Connect to postgres database to create target database
const adminUrl = databaseUrl.replace(`/${dbName}`, '/postgres');
const adminClient = postgres(adminUrl);
// Check if database exists, create if not
const result =
await adminClient`SELECT 1 FROM pg_database WHERE datname = ${dbName}`;
if (result.length === 0) {
await adminClient.unsafe(`CREATE DATABASE "${dbName}"`);
}
}Prisma Workflow:
npm run db:migrate # Run database migrations
npm run db:generate # Generate Prisma client
npm run db:studio # Launch Prisma StudioDrizzle Workflow:
npm run db:create # Auto-create database (New in v2.1.0)
npm run db:generate # Generate migration files
npm run db:push # Push schema to database
npm run db:studio # Launch Drizzle Studio
npm run db:migrate # Run existing migrations- Simplified schema with commented examples (no opinionated User/Post models)
- Basic Express server with health check endpoints
- Automatic Prisma Client generation during setup
- Environment-specific configuration
- Modular database setup with separate connection, schema, and migration files
- Auto database creation script for seamless Docker integration
- Lightweight schema definitions with example comments
- Enhanced error handling and environment variable loading
- Problem:
process.env.DATABASE_URLwasundefinedcausing "role Panka does not exist" errors - Solution: Added
dotenv.config()to database connection files before URL access - Impact: Reliable database connections across all environments
// Updated in command.js v2.1.0
export async function runCommand(command, cwd) {
return execPromise(command, {
cwd,
maxBuffer: 1024 * 1024 * 50, // Increased to 50MB
timeout: 300000, // Added 5 minute timeout
});
}- Eliminates need for manual
createdbor PostgreSQL setup - Works seamlessly with Docker PostgreSQL containers
- Matches Prisma's automatic database creation behavior
- Provides better developer experience for database projects
npm create vite@latest <name> --template react-tsnpm install <packages>npm run dev(for testing)
pip install flaskpython -m flask runpython manage.py runserver(Django)
git initgit add .git commit -m "Initial commit"
- Async/Await Pattern: All commands use promisified execution
- Error Handling: Comprehensive try-catch blocks
- Progress Indication: Spinners show command progress
- Working Directory: Commands run in correct project context
- Buffer Management: Large buffer for handling verbose output
{
command: null | string, // Base creation command
name: string, // Display name
needsInstall: boolean, // Auto-install dependencies
manual: boolean, // Requires custom file generation
setupTailwind: boolean // Special Tailwind setup flag
}Commands are built dynamically based on user choices:
// TypeScript flag adds to base command
const tsFlag = useTypeScript ? '-ts' : '';
const command = `npm create vite@latest ${projectName} --template react${tsFlag}`;- Empty project names
- Invalid characters in names
- Existing directory conflicts
- Missing Node.js/npm
- Network connectivity issues
- Permission problems
- Failed npm installations
- Git initialization failures
- File system errors
try {
await runCommand(command, projectPath);
spinner.success({ text: '✓ Success message' });
} catch (error) {
spinner.error({ text: '✗ Error occurred' });
console.error(chalk.red(`Error: ${error.message}`));
process.exit(1);
}- Node.js >= 14.0.0
- npm or yarn
- Git (for repository initialization)
# Clone repository
git clone https://github.com/PankajKumardev/initgen.git
cd initgen
# Install dependencies
npm install
# Test locally
node index.js
# Link globally for testing
npm link
initgen# Update version
npm version patch
# Publish to npm
npm publish- Only essential packages included
- No heavy frameworks or UI libraries
- ES modules for better tree-shaking
- Commands run one after another for reliability
- Optimized buffer sizes for large outputs
- Proper working directory management
- Template reuse and caching
- Minimal file I/O operations
- Streamlined dependency installation
- Promisified async operations
- Proper cleanup after command execution
- Limited buffer sizes for safety
- Source Code: ~1,800 lines total across all files
- Package size: ~15.4 KB compressed (6 runtime deps)
- Install time: ~2-3 seconds (
npm install -g initgen) - Project generation: 10-30 seconds (network dependent)
- Update Stack Commands (
stackCommands.js) - Create Template Module (
src/templates/newStack.js) - Add to Main Switch (in
index.js) - Update Documentation
export async function setupNewStackTemplate(
projectName,
useTypeScript,
projectPath
) {
const spinner = createSpinner('Setting up project...').start();
try {
// 1. Create base project
await runCommand('base-command', process.cwd());
// 2. Install dependencies
await runCommand('npm install dependencies', projectPath);
// 3. Configure files
// Create configs, update package.json, etc.
// 4. Generate README
const readme = createCustomReadme(projectName);
fs.writeFileSync(path.join(projectPath, 'README.md'), readme);
spinner.success({ text: '✓ Project created successfully!' });
} catch (error) {
spinner.error({ text: '✗ Error creating project' });
throw error;
}
}- npm download statistics available via API
- GitHub repository statistics
- Project creation success/failure rates
- Popular tech stack choices
- Performance benchmarks
- Project name sanitization
- Path traversal prevention
- Command injection protection
- Regular dependency updates
- Vulnerability scanning
- Minimal attack surface
- Safe file creation practices
- Proper permission handling
- Directory traversal prevention
- ES6+ modules
- Async/await preferred over callbacks
- Consistent error handling patterns
- Clear variable naming
- Manual testing across platforms
- Integration testing with real projects
- Performance benchmarking
- Cross-platform compatibility testing
- Keep technical docs in sync with code
- Update README for new features
- Maintain changelog for releases
- Plugin system for custom templates
- Configuration file support
- Interactive project customization
- Cloud deployment integration
- Docker containerization support
- Command caching
- Parallel processing implementation (currently sequential)
- Incremental updates
- Smart dependency management
This technical documentation provides a comprehensive overview of InitGen's architecture, internal workings, and extension capabilities. For user-facing documentation, visit https://initgen.pankajk.tech/.