npm package: @ldpld/create-node-mvc
Description: Express.js MVC Scaffold Generator - Create production-ready Node.js projects with dual-route architecture
Author: pledovski
Latest version: 0.1.1

# create-node-mvc

Express.js MVC Scaffold Generator - Create production-ready Node.js projects with dual-route architecture.

## Installation

Install globally via npm:

```bash
npm install -g create-node-mvc
```

Or use with npx (no installation required):

```bash
npx create-node-mvc my-project
```

## Usage

```bash
create-node-mvc <project-name>
```

The CLI will guide you through an interactive setup with the following options:

- **API-only architecture**: Generate API routes only (no view rendering)
- **Include authentication**: Add JWT-based authentication system
- **Additional features**: Select from:
  - File uploads (express-fileupload)
  - Email service (nodemailer)
  - Testing setup (Jest + Supertest)
  - Tailwind CSS (with build pipeline)

### Command Options

```bash
create-node-mvc <project-name> [options]
```

**Options:**
- `--skip-install`: Skip automatic `npm install` after project generation

**Examples:**

```bash
# Create project with interactive prompts and auto-install
create-node-mvc my-api

# Create project and skip dependency installation
create-node-mvc my-api --skip-install
```

## Running Tests

### Run all tests:
```bash
npm test
```

### Run tests with coverage:
```bash
npm test -- --coverage
```

### Run specific test file:
```bash
npm test -- tests/project-structure.test.js
```

### Update snapshots (when intentional changes occur):
```bash
npm test -- -u
```

### Test execution time:
- Unit tests: ~5-10 seconds
- Integration tests: ~20-30 seconds (without server startup)
- Server startup tests: ~2-3 minutes (includes npm install)
- Full suite: ~3-4 minutes

### Test coverage goals:
- lib/ modules: >80% coverage
- Integration coverage: All configuration combinations
- Edge cases: Error handling scenarios

## Development

### Project Structure

```
cli/
├── bin/
│   └── create-node-mvc.js     # CLI entry point
├── lib/
│   ├── prompts.js             # Interactive questions
│   ├── fileOperations.js      # File copying/operations
│   ├── variableReplacer.js    # Template variable substitution
│   ├── featureIntegration.js  # Optional feature integration
│   └── dependencyInstaller.js # npm install automation
├── templates/
│   ├── base/                  # Core project template
│   └── optional/              # Feature-specific templates
└── tests/                     # Test suite
```

### Adding New Features

1. Add template files to `templates/optional/<feature-name>/`
2. Update `lib/featureIntegration.js` with merge logic
3. Add feature to prompts in `lib/prompts.js`
4. Write tests in `tests/feature-validation.test.js`

## Generated Project Structure

### Full MVC Project (Default)

```
your-project/
├── config/
│   ├── config.env              # Environment configuration
│   └── db.js                   # MongoDB connection setup
├── controllers/
│   ├── api/
│   │   └── user.controller.js  # API endpoint handlers
│   ├── view/
│   │   └── user.controller.js  # View rendering handlers
│   └── error.js                # 404 error handler
├── middleware/
│   ├── advancedResults.js      # Query filtering, pagination
│   ├── async.js                # Async error wrapper
│   ├── auth.js                 # JWT authentication
│   └── error.js                # Global error handler
├── models/
│   └── User.js                 # Mongoose User model
├── routes/
│   ├── api/
│   │   └── user.routes.js      # API routes (/api/v1/users)
│   └── view/
│       └── user.routes.js      # View routes (/users)
├── utils/
│   ├── errorResponse.js        # Custom error class
│   ├── geocoder.js             # Geocoding utilities
│   ├── path.js                 # Path helpers
│   └── saveToDisk.js           # File upload utilities
├── views/
│   ├── users/
│   │   ├── list.ejs            # User list view
│   │   ├── show.ejs            # User detail view
│   │   ├── new.ejs             # Create user form
│   │   └── edit.ejs            # Edit user form
│   ├── partials/
│   │   ├── header.ejs          # Reusable header
│   │   └── footer.ejs          # Reusable footer
│   └── 404.ejs                 # Error page
├── public/
│   ├── css/
│   │   └── main.css            # Stylesheet
│   ├── src/imgs/
│   │   └── ava-img-blue.svg    # Example image
│   └── index.html              # Static homepage
├── .env.example                # Environment template
├── .gitignore                  # Git ignore rules
├── app.js                      # Express app entry point
├── package.json                # Dependencies
└── README.md                   # Project documentation
```

### Dual-Route Architecture

Generated projects support both API and view routes:

- **API Routes** (`/api/v1/*`): JSON responses for REST clients
  - Controllers: `controllers/api/`
  - Routes: `routes/api/`
  - Example: `GET /api/v1/users` → Returns JSON

- **View Routes** (`/*`): Server-rendered EJS templates
  - Controllers: `controllers/view/`
  - Routes: `routes/view/`
  - Views: `views/`
  - Example: `GET /users` → Renders HTML page

### API-Only Mode

When "API-only architecture" is selected, the structure excludes:

```
your-project/
├── config/
├── controllers/
│   ├── api/                    # ✓ API controllers only
│   └── error.js
├── middleware/
├── models/
├── routes/
│   └── api/                    # ✓ API routes only
├── utils/
├── .env.example
├── .gitignore
├── app.js
├── package.json
└── README.md

# Excluded in API-only mode:
# ✗ views/
# ✗ public/
# ✗ controllers/view/
# ✗ routes/view/
```

### Optional Features

When selected, additional files are added:

**Authentication** (`--auth`):
- `controllers/api/protected.controller.js`
- `routes/api/protected.routes.js`
- Enhanced `middleware/auth.js`
- JWT environment variables in `.env`

**File Upload** (`--fileupload`):
- `controllers/api/upload.controller.js`
- `routes/api/upload.routes.js`
- `utils/fileUpload.js`
- Upload directory configuration

**Email Service** (`--email`):
- `controllers/api/email.controller.js`
- `utils/sendEmail.js`
- SMTP environment variables

**Testing** (`--testing`):
- `tests/api/user.test.js`
- `tests/setup.js`
- `jest.config.js`
- Test scripts in `package.json`

**Tailwind CSS** (`--tailwind`):
- `tailwind.config.js`
- `postcss.config.js`
- `public/css/input.css`
- Enhanced view templates with Tailwind classes
- Build scripts in `package.json`

## License

MIT