Skip to content

Jobinjose01/NodeTS-Starter-Kit

Repository files navigation

Node.js Starter Kit πŸš€

A production-ready Node.js starter kit with Express, TypeScript, Prisma, MySQL, comprehensive testing, and automated code generation.

TypeScript Express Prisma Jest License

✨ Features

Core Stack

  • TypeScript 5.9 - Type-safe development with latest features
  • Express 5.2 - Fast, minimalist web framework
  • Prisma 7 - Next-generation ORM with type safety
  • MySQL - Reliable relational database
  • JWT - Secure token-based authentication
  • RBAC - Role-based access control with permissions

Developer Experience

  • 🎯 Code Generator - Auto-generate CRUD modules with tests in seconds
  • πŸ“š RESTful APIs - Standard REST conventions (POST /, GET /, GET /:id, PUT /:id, DELETE /:id)
  • πŸ“– Swagger UI - Interactive API documentation at /api-docs
  • βœ… ESLint 9 - Modern flat config with strict rules
  • πŸ’… Prettier - Consistent code formatting
  • 🌍 i18n - Multi-language support (English, Spanish)

Testing & Performance

  • Jest 30 - Modern testing framework with great DX
  • Unit Tests - Isolated tests with mocked dependencies
  • Integration Tests - Full API endpoint testing with real database
  • Performance Tracking - Color-coded benchmarking (🟒 Fast, 🟑 Acceptable, 🟠 Slow, πŸ”΄ Very Slow)
  • Coverage Reports - Detailed HTML reports with >80% coverage

πŸ“‹ Quick Start

Prerequisites

  • Node.js 20+
  • MySQL 8+ (or Docker)
  • npm or yarn

Installation

# Clone repository
git clone <repository-url>
cd node-starter-kit

# Install dependencies
npm install

# Setup environment
cp .env.example .env

# Start MySQL (Docker)
docker-compose up -d

# Run migrations
npm run prisma:migrate

# Seed database
npm run seed

Development

# Start development server
npm run dev

# Server runs on http://localhost:5000
# Swagger UI: http://localhost:5000/api-docs

πŸ§ͺ Testing

# Run all tests with coverage
npm test

# Run unit tests only (fast, isolated)
npm run test:unit

# Run integration tests only (with database)
npm run test:integration

# Run all tests sequentially
npm run test:all

# Run tests for specific module (unit + integration)
npm run test:module user

# Run only unit tests for specific module
npm run test:unit:module user

# Watch mode
npm run test:watch

πŸ’‘ Pro Tips:

  • Use test:module to test a specific feature (e.g., user, role)
  • Use test:unit:module for fast unit tests of a single module
  • Pattern matching works: npm run test:module role runs all role-related tests

πŸ”¨ Code Generation

Generate complete CRUD modules with one command:

npm run generate

What it generates:

  • βœ… Model class with TypeScript interfaces
  • βœ… Service with CRUD operations + pagination
  • βœ… Controller with RESTful endpoints
  • βœ… Routes with authentication & validation
  • βœ… Validators with i18n error messages
  • βœ… Swagger documentation (schemas + paths)
  • βœ… Unit tests (controller + service)
  • βœ… Integration tests with performance tracking

Example: Generate a Product module in < 5 seconds with full test coverage!

πŸ“– Detailed guide: docs/CODE_GENERATION.md

πŸ“ Project Structure

β”œβ”€β”€ prisma/                      # Database schema & migrations
β”‚   β”œβ”€β”€ schema.prisma           # Prisma schema
β”‚   β”œβ”€β”€ migrations/             # Database migrations
β”‚   └── seeders/                # Seed data
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ config/                 # Configuration files
β”‚   β”‚   β”œβ”€β”€ swagger/           # API documentation
β”‚   β”‚   β”œβ”€β”€ locales/           # i18n translations
β”‚   β”‚   └── templates/         # Code generation templates
β”‚   β”œβ”€β”€ controllers/            # Request handlers
β”‚   β”œβ”€β”€ services/               # Business logic
β”‚   β”œβ”€β”€ routes/                 # API routes
β”‚   β”œβ”€β”€ middlewares/            # Express middlewares
β”‚   β”œβ”€β”€ validators/             # Request validation
β”‚   β”œβ”€β”€ models/                 # Data models
β”‚   β”œβ”€β”€ utils/                  # Utility functions
β”‚   └── tests/                  # Test files
β”‚       β”œβ”€β”€ unit/              # Unit tests
β”‚       β”œβ”€β”€ integration/       # Integration tests
β”‚       └── helpers/           # Test utilities
β”œβ”€β”€ docs/                       # Documentation
β”‚   β”œβ”€β”€ TESTING.md             # Testing guide
β”‚   β”œβ”€β”€ BENCHMARKING.md        # Performance guide
β”‚   └── CODE_GENERATION.md     # Generator guide
└── logs/                       # Application logs
    └── benchmark/             # Performance logs

πŸ”— Full API docs: http://localhost:5000/api-docs

🧰 Available Scripts

Development

npm run dev              # Start development server
npm run build            # Build for production
npm start                # Start production server

Code Quality

npm run lint:check       # Check for linting errors
npm run lint:fix         # Fix linting errors
npm run format:check     # Check code formatting
npm run format:fix       # Format code with Prettier

Database

npm run prisma:generate  # Generate Prisma Client
npm run prisma:migrate   # Run migrations
npm run prisma:deploy    # Deploy migrations (production)
npm run prisma:format    # Format schema.prisma
npm run seed             # Seed database

Code Generation

npm run generate         # Generate CRUD module with tests

Testing

npm test                      # Run all tests with coverage
npm run test:unit             # Run all unit tests
npm run test:integration      # Run all integration tests
npm run test:all              # Run unit then integration (sequential)
npm run test:module <name>    # Run all tests for specific module
npm run test:unit:module <name>  # Run unit tests for specific module
npm run test:watch            # Watch mode for development

Examples:

npm run test:module user           # All user tests (unit + integration)
npm run test:unit:module role      # Only role unit tests (fast)
npm run test:module Controller     # All controller tests

πŸ“š Documentation

Detailed guides available in the docs/ folder:

Guide Description
TESTING.md Complete testing guide (unit, integration, performance)
TESTING_CHEATSHEET.md Quick reference for all test commands ⚑
BENCHMARKING.md Performance tracking and optimization tips
CODE_GENERATION.md Code generator usage and customization

πŸš€ Deployment

Docker

# Build image
docker build -t node-starter-kit .

# Run container
docker-compose up -d

# Check logs
docker-compose logs -f app

Production

# Build
npm run build

# Set environment
export NODE_ENV=production

# Run migrations
npm run prisma:deploy

# Start server
npm start

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Guidelines:

  • Write tests for new features
  • Follow TypeScript/ESLint conventions
  • Update documentation as needed
  • Maintain >80% code coverage

πŸ“Š Performance

The starter kit includes built-in performance tracking:

  • Color-coded benchmarks in test output
  • Automatic logging to logs/benchmark/
  • Performance thresholds: Fast (<100ms), Acceptable (<500ms), Slow (<1000ms)
  • Summary reports after test runs npm run analyze-benchmark

Example output:

========================================
  Performance Test Summary
========================================

API Call: Get All Users
  ⏱️  Time: 89ms
  Status: 🟒 Fast (Expected: 500ms)

API Call: Create User
  ⏱️  Time: 245ms
  Status: 🟑 Acceptable (Expected: 500ms)

πŸ› Troubleshooting

Database Connection Issues

# Check Docker containers
docker-compose ps

# Restart database
docker-compose restart db

# Check logs
docker-compose logs db

Migration Errors

# Reset database (⚠️ Development only)
npx prisma migrate reset

# Re-run migrations
npm run prisma:migrate

# Regenerate client
npm run prisma:generate

# Run only one seeder
npm run seed -- --name=Permissions

Port Already in Use

# Find process using port 3000
lsof -ti:5000

# Kill process
lsof -ti:5000 | xargs kill -9

πŸ“„ License

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

πŸ™ Acknowledgments

πŸ“ž Support

For questions or issues:


Upstream

git remote add upstream git@github.com:Jobinjose01/NodeTS-Starter-Kit.git

Built with ❀️ using TypeScript, Express, and Prisma

About

Node Type Script Starter Kit with Code Generation for CRUDS

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors