A production-ready Node.js/TypeScript API demonstrating enterprise-level backend development with comprehensive DevOps practices from code to cloud deployment.
- Overview
- Features
- Tech Stack
- Prerequisites
- Quick Start
- Project Structure
- Available Scripts
- API Endpoints
- Environment Variables
- Development Phases
- Contributing
- License
This project showcases a production-grade backend API built with modern best practices, including:
- Clean Architecture with separation of concerns
- Type Safety with TypeScript strict mode
- Security Best Practices (Helmet, CORS, input validation)
- Comprehensive Error Handling with custom error classes
- Request Logging and monitoring
- Graceful Shutdown for zero-downtime deployments
- Environment-based Configuration management
- Code Quality Tools (ESLint, Prettier, EditorConfig)
- Docker & Kubernetes ready (Phase 3)
- CI/CD Pipeline with GitHub Actions (Phase 4)
- β Professional project structure with TypeScript
- β Express.js server with security middleware
- β Health check and readiness probe endpoints
- β Comprehensive error handling
- β Request logging with Morgan
- β Environment configuration management
- β Code quality tools (ESLint, Prettier)
- β Development and production build scripts
- β PostgreSQL 15 integration with TypeORM
- β Redis 7 for caching and sessions
- β Database migrations and seeders
- β Repository pattern implementation
- β User and Task entities with relationships
- β Service layer with business logic
- β RESTful API endpoints for Users and Tasks
- β Input validation with express-validator
- β Password hashing with bcryptjs
- β Caching strategy implementation
- β Health checks with database/Redis status
π View Phase 2 Documentation
- Multi-stage Dockerfile
- Docker Compose for local development
- Kubernetes manifests (Deployments, Services, ConfigMaps)
- Helm charts for orchestration
- GitHub Actions workflows
- Automated testing and linting
- Docker image building and pushing
- Automated deployments
- Prometheus metrics
- Grafana dashboards
- Logging with ELK stack
- Distributed tracing
- Runtime: Node.js 20 LTS
- Language: TypeScript 5.x
- Framework: Express.js 4.x
- Database: PostgreSQL 15 (Phase 2)
- Caching: Redis 7 (Phase 2)
- Helmet - Security headers
- CORS - Cross-origin resource sharing
- Compression - Response compression
- Morgan - HTTP request logger
- Express Validator - Input validation
- TypeScript - Type safety and modern JavaScript features
- ESLint - Code linting
- Prettier - Code formatting
- ts-node-dev - Development server with hot reload
- Nodemon - Process manager
- Docker & Docker Compose
- Kubernetes & Helm
- GitHub Actions
- Prometheus & Grafana
Before you begin, ensure you have the following installed:
Optional (for future phases):
- Docker >= 24.0.0
- Docker Compose >= 2.20.0
- kubectl (Kubernetes CLI)
git clone https://github.com/yourusername/production-api-framework.git
cd production-api-frameworknpm installcp .env.example .envEdit .env file with your configuration (defaults work for development).
npm run devThe server will start at http://localhost:3000
Using Docker Compose (Recommended):
# Start PostgreSQL and Redis
docker-compose up -d
# Run database migrations
npm run migration:run
# Seed development data
npm run seedManual Setup:
# Install PostgreSQL 15 and Redis 7
# Update .env with your database credentials
# Run migrations
npm run migration:run
# Seed development data
npm run seedOpen your browser or use curl:
# Health check
curl http://localhost:3000/health
# Readiness check (includes database/Redis status)
curl http://localhost:3000/ready
# API info
curl http://localhost:3000/api/v1
# Create a test user (Phase 2)
curl -X POST http://localhost:3000/api/v1/users \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "SecurePass123!",
"firstName": "Test",
"lastName": "User"
}'Default Credentials (after seeding):
- Email:
admin@example.com - Password:
Password123!
production-api-framework/
βββ src/
β βββ api/ # API endpoints (Phase 2)
β β βββ v1/
β β βββ users/ # User endpoints
β β β βββ user.controller.ts
β β β βββ user.routes.ts
β β β βββ user.validator.ts
β β βββ tasks/ # Task endpoints
β β βββ task.controller.ts
β β βββ task.routes.ts
β β βββ task.validator.ts
β βββ config/ # Configuration files
β β βββ environment.ts # Environment variables configuration
β βββ controllers/ # Route controllers
β β βββ apiController.ts # API info endpoints
β β βββ healthController.ts # Health check endpoints
β βββ core/ # Core infrastructure (Phase 2)
β β βββ cache/
β β β βββ redis.config.ts # Redis configuration
β β βββ database/
β β βββ base.repository.ts # Base repository pattern
β β βββ data-source.ts # TypeORM data source
β βββ middlewares/ # Custom middleware
β β βββ errorHandler.ts # Error handling middleware
β β βββ validation.middleware.ts # Input validation
β βββ migrations/ # Database migrations (Phase 2)
β β βββ 1702000000000-CreateUsersTable.ts
β β βββ 1702000000001-CreateTasksTable.ts
β βββ models/ # Data models (Phase 2)
β β βββ user.entity.ts # User entity
β β βββ task.entity.ts # Task entity
β β βββ index.ts # Export all entities
β βββ repositories/ # Data access layer (Phase 2)
β β βββ user.repository.ts # User repository
β β βββ task.repository.ts # Task repository
β β βββ index.ts # Export all repositories
β βββ routes/ # API routes
β β βββ apiRoutes.ts # API v1 routes
β β βββ healthRoutes.ts # Health routes
β β βββ index.ts # Main router
β βββ scripts/ # Utility scripts (Phase 2)
β β βββ seed-data.ts # Database seeding
β βββ services/ # Business logic (Phase 2)
β β βββ cache.service.ts # Caching service
β β βββ user.service.ts # User business logic
β β βββ task.service.ts # Task business logic
β βββ types/ # TypeScript type definitions
β β βββ express.d.ts # Express type extensions
β βββ utils/ # Utility functions
β βββ app.ts # Express app setup
β βββ server.ts # Server entry point
βββ docs/ # Documentation
β βββ PHASE_2_COMPLETE.md # Phase 2 documentation
βββ dist/ # Compiled JavaScript (generated)
βββ node_modules/ # Dependencies (generated)
βββ .env # Environment variables (create from .env.example)
βββ .env.example # Environment variables template
βββ .eslintrc.json # ESLint configuration
βββ .prettierrc # Prettier configuration
βββ .editorconfig # Editor configuration
βββ .gitignore # Git ignore rules
βββ .dockerignore # Docker ignore rules
βββ docker-compose.yml # Docker Compose configuration (Phase 2)
βββ tsconfig.json # TypeScript configuration
βββ package.json # Project dependencies and scripts
βββ LICENSE # MIT License
βββ README.md # This file
# Development
npm run dev # Start development server with hot reload
npm run type-check # Run TypeScript type checking
# Building
npm run build # Compile TypeScript to JavaScript
npm run clean # Remove dist folder
# Production
npm start # Start production server (builds first)
# Database (Phase 2)
npm run migration:run # Run pending migrations
npm run migration:revert # Revert last migration
npm run migration:show # Show migration status
npm run migration:generate # Generate migration from entities
npm run seed # Seed development data
npm run db:setup # Run migrations + seed (one command)
# Code Quality
npm run lint # Run ESLint
npm run lint:fix # Fix ESLint errors automatically
npm run format # Format code with Prettier
npm run format:check # Check code formatting
# Testing (Phase 5)
npm test # Run tests (not yet implemented)| Method | Endpoint | Description |
|---|---|---|
| GET | /health |
Health check endpoint for monitoring |
| GET | /ready |
Readiness probe with database/Redis status |
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
API information and available endpoints |
| GET | /api/v1 |
API v1 information |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/users |
Create new user |
| GET | /api/v1/users |
List all users (paginated, filterable) |
| GET | /api/v1/users/:id |
Get user by ID |
| PUT | /api/v1/users/:id |
Update user |
| DELETE | /api/v1/users/:id |
Delete user (soft delete) |
| GET | /api/v1/users/:id/tasks |
Get user's assigned and created tasks |
| POST | /api/v1/users/:id/change-password |
Change user password |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/tasks |
Create new task |
| GET | /api/v1/tasks |
List all tasks (paginated, filterable) |
| GET | /api/v1/tasks/:id |
Get task by ID |
| PUT | /api/v1/tasks/:id |
Update task |
| DELETE | /api/v1/tasks/:id |
Delete task (soft delete) |
| PATCH | /api/v1/tasks/:id/assign |
Assign task to user |
| PATCH | /api/v1/tasks/:id/status |
Update task status |
GET /health
{
"success": true,
"message": "API is running",
"timestamp": "2024-01-15T10:30:00.000Z",
"uptime": 123.456,
"environment": "development",
"version": "v1"
}GET /ready
{
"success": true,
"message": "API is ready",
"timestamp": "2024-01-15T10:30:00.000Z",
"uptime": 123.456,
"environment": "development",
"version": "v1",
"services": {
"database": {
"status": "healthy",
"healthy": true,
"details": {
"database": "api_db",
"host": "localhost",
"port": 5432,
"isConnected": true
}
},
"redis": {
"status": "healthy",
"healthy": true,
"details": {
"host": "localhost",
"port": 6379,
"db": 0,
"status": "ready"
}
}
}
}POST /api/v1/users (Create User)
{
"success": true,
"data": {
"id": "123e4567-e89b-12d3-a456-426614174000",
"email": "john.doe@example.com",
"firstName": "John",
"lastName": "Doe",
"role": "USER",
"status": "ACTIVE",
"createdAt": "2024-01-15T10:30:00.000Z",
"updatedAt": "2024-01-15T10:30:00.000Z"
},
"message": "User created successfully",
"timestamp": "2024-01-15T10:30:00.000Z"
}GET /api/v1/users (List Users)
{
"success": true,
"data": [
{
"id": "123e4567-e89b-12d3-a456-426614174000",
"email": "john.doe@example.com",
"firstName": "John",
"lastName": "Doe",
"role": "USER",
"status": "ACTIVE"
}
],
"pagination": {
"page": 1,
"limit": 10,
"total": 3,
"totalPages": 1,
"hasNext": false,
"hasPrevious": false
},
"timestamp": "2024-01-15T10:30:00.000Z"
}Create a .env file from .env.example:
# Application
NODE_ENV=development
PORT=3000
API_VERSION=v1
APP_NAME=production-api-framework
# Server
HOST=localhost
ALLOWED_ORIGINS=http://localhost:3000,http://localhost:3001
# Database (Phase 2)
DB_HOST=localhost
DB_PORT=5432
DB_NAME=api_db
DB_USER=postgres
DB_PASSWORD=your_db_password_here
DB_SSL=false
DB_POOL_MIN=2
DB_POOL_MAX=10
# Redis (Phase 2)
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DB=0
REDIS_TTL=3600
# JWT (Phase 2)
JWT_SECRET=your_super_secret_jwt_key_change_this_in_production
JWT_EXPIRES_IN=7d
# Security
HELMET_ENABLED=true
COMPRESSION_ENABLED=true
CORS_ENABLED=true
CORS_CREDENTIALS=true
# Logging
LOG_LEVEL=info
LOG_FORMAT=combined
ENABLE_REQUEST_LOGGING=trueSee .env.example for complete configuration options.
- Project initialization and structure
- TypeScript configuration
- Express server with middleware
- Health check endpoints
- Error handling
- Code quality tools
- PostgreSQL integration with TypeORM
- Redis for caching
- User and Task entities
- Repository pattern
- Service layer with business logic
- RESTful API endpoints
- Input validation
- Password hashing
- Database migrations and seeders
- Health checks with database/Redis status
π View Complete Phase 2 Documentation
- Docker multi-stage builds
- Docker Compose setup
- Kubernetes manifests
- Helm charts
- GitHub Actions workflows
- Automated testing
- Docker image building
- Deployment automation
- Unit and integration tests
- Prometheus metrics
- Grafana dashboards
- Logging infrastructure
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Your Name
- GitHub: @yourusername
- Email: your.email@example.com
- Express.js team for the excellent framework
- TypeScript team for making JavaScript safer
- The Node.js community for amazing tools and libraries
Built with β€οΈ for production-ready backend development
Application is automatically deployed to AWS EC2 on every push to main.