# Create Node MVC

A powerful CLI tool to scaffold complete Node.js MVC projects with multiple language and framework options, just like Laravel does.

## 🚀 Installation

```bash
npm install -g create-node-mvc
```

## 📋 Usage

```bash
create-node-mvc my-app
```

This will start an interactive prompt to configure your project:

### **Language Options**

- **🔷 TypeScript** (Recommended) - Full type safety and modern features
- **🟨 JavaScript** - Classic Node.js with CommonJS modules

### **Framework Options**

- **⚡ Express.js** - Simple & Fast traditional MVC framework
- **🏗️ NestJS** - Enterprise-grade framework with decorators and modules

### **Database Options**

- **🍃 MongoDB** with Mongoose ODM
- **🐬 MySQL** with Sequelize/TypeORM
- **🐘 PostgreSQL** with Sequelize/TypeORM
- **📱 SQLite** with Sequelize/TypeORM

### **Project Types**

- **🌐 API Only** - REST endpoints only
- **🎨 Full MVC** - With views and frontend assets
- **📊 GraphQL API** - GraphQL with Apollo (NestJS only)
- **🔄 Microservices** - Microservice architecture (NestJS only)

## ✨ Supported Combinations

| Language       | Framework   | Structure       | Best For                |
| -------------- | ----------- | --------------- | ----------------------- |
| **TypeScript** | **Express** | Traditional MVC | Full-stack web apps     |
| **JavaScript** | **Express** | Traditional MVC | Simple APIs & websites  |
| **TypeScript** | **NestJS**  | Module-based    | Enterprise applications |
| **JavaScript** | **NestJS**  | Module-based    | Modern APIs             |

## 🎯 Features

### **Core Features**

- **Multiple languages**: TypeScript & JavaScript support
- **Multiple frameworks**: Express.js & NestJS architectures
- **Authentication**: JWT tokens with bcrypt password hashing
- **Database flexibility**: MongoDB, MySQL, PostgreSQL, SQLite
- **Validation**: Joi (Express) or class-validator (NestJS)
- **Error handling**: Comprehensive error middleware and logging
- **Security**: Helmet, CORS, rate limiting built-in

### **Optional Extras**

- **🐳 Docker** - Complete containerization setup
- **🔍 ESLint & Prettier** - Code formatting and linting
- **🧪 Jest Testing** - Unit and integration test setup
- **🪝 Git Hooks** - Husky pre-commit hooks
- **📚 API Documentation** - Swagger/OpenAPI (NestJS)

## 📂 Generated Project Structures

### **Express.js Structure (Traditional MVC)**

```
my-app/
├── src/
│   ├── config/           # Database and app configuration
│   ├── controllers/      # Route controllers
│   ├── models/          # Database models
│   ├── routes/          # Express routes
│   ├── middlewares/     # Custom middlewares
│   ├── utils/           # Utilities (TypeScript)
│   ├── validators/      # Joi validators (JavaScript)
│   └── app.ts/js        # Express application
├── tests/ (optional)
├── .env.example
├── tsconfig.json (TypeScript only)
└── package.json
```

### **NestJS Structure (Module-based)**

```
my-app/
├── src/
│   ├── auth/            # Authentication module
│   │   ├── dto/         # Data transfer objects
│   │   ├── guards/      # Auth guards
│   │   ├── strategies/  # Passport strategies
│   │   ├── auth.controller.ts
│   │   ├── auth.service.ts
│   │   └── auth.module.ts
│   ├── users/           # Users module
│   │   ├── dto/         # User DTOs
│   │   ├── entities/    # User entities
│   │   ├── users.controller.ts
│   │   ├── users.service.ts
│   │   └── users.module.ts
│   ├── config/          # Configuration
│   ├── app.module.ts    # Root module
│   └── main.ts/js       # NestJS bootstrap
├── test/ (optional)
├── tsconfig.json (TypeScript only)
└── package.json
```

## 🚀 Quick Start Examples

### **Create a TypeScript Express API**

```bash
create-node-mvc my-api
# Select: TypeScript → Express → MongoDB → API Only
cd my-api
npm install
npm run dev
```

### **Create a NestJS Enterprise App**

```bash
create-node-mvc my-enterprise-app
# Select: TypeScript → NestJS → PostgreSQL → API Only → Docker + Testing
cd my-enterprise-app
npm install
npm run start:dev
```

### **Create a Simple JavaScript API**

```bash
create-node-mvc my-simple-api
# Select: JavaScript → Express → MongoDB → API Only
cd my-simple-api
npm install
npm start
```

## 📖 Available Scripts

After generating your project, you can use these commands:

### **Express.js Projects**

```bash
npm start          # Start production server
npm run dev        # Start development server with nodemon/ts-node
npm run build      # Compile TypeScript (TypeScript only)
npm test           # Run tests (if testing enabled)
npm run lint       # Run ESLint (if linting enabled)
```

### **NestJS Projects**

```bash
npm run start          # Start production server
npm run start:dev      # Start development server with watch
npm run start:debug    # Start with debugging
npm run build          # Build the application
npm run test           # Run unit tests
npm run test:e2e       # Run end-to-end tests
```

## 🎛️ Configuration

### **Environment Variables**

Your generated project includes a `.env.example` file. Copy it to `.env` and configure:

```env
# Database
DATABASE_URL=mongodb://localhost:27017/your-app
# or for SQL databases
DATABASE_URL=postgresql://user:password@localhost:5432/your-app

# JWT
JWT_SECRET=your-super-secret-jwt-key

# Server
PORT=3000
NODE_ENV=development

# CORS (optional)
CORS_ORIGIN=http://localhost:3000
```

### **Database Setup**

- **MongoDB**: Ensure MongoDB is running locally or provide a connection string
- **PostgreSQL/MySQL**: Create a database and provide connection details
- **SQLite**: Database file will be created automatically

## 🔧 Customization

### **Adding New Routes (Express)**

```typescript
// src/routes/example.ts
import { Router } from "express";
const router = Router();

router.get("/", (req, res) => {
  res.json({ message: "Hello World" });
});

export default router;
```

### **Adding New Modules (NestJS)**

```bash
# Generate new module
nest g module products
nest g controller products
nest g service products
```

## 🤝 Contributing

We welcome contributions! Please feel free to submit a Pull Request.

## 📄 Development

To work on this CLI tool:

```bash
git clone https://github.com/your-username/create-node-mvc.git
cd create-node-mvc
npm install
npm run dev
```

## 🆚 Comparison with Other Tools

| Feature             | create-node-mvc     | create-next-app | @nestjs/cli     |
| ------------------- | ------------------- | --------------- | --------------- |
| Multiple Languages  | ✅ TS & JS          | ❌ TS only      | ❌ TS only      |
| Multiple Frameworks | ✅ Express & NestJS | ❌ Next only    | ❌ NestJS only  |
| Database Support    | ✅ 4 databases      | ❌ None         | ❌ Manual setup |
| Authentication      | ✅ Built-in JWT     | ❌ Manual       | ❌ Manual       |
| Docker Setup        | ✅ Optional         | ❌ Manual       | ❌ Manual       |
| Testing Setup       | ✅ Pre-configured   | ❌ Manual       | ✅ Basic        |

## 📋 Roadmap

- [ ] **React/Vue frontend integration**
- [ ] **GraphQL support for Express**
- [ ] **Prisma ORM support**
- [ ] **WebSocket support**
- [ ] **Microservices templates**
- [ ] **CI/CD pipeline templates**

## 🏆 License

MIT © [Zebix]

---

**Made with ❤️ for the Node.js community**

_Like Laravel's Artisan for Node.js_ 🚀
