Skip to content

GoddeyUwamari/production-api-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

31 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Production API Framework

A production-ready Node.js/TypeScript API demonstrating enterprise-level backend development with comprehensive DevOps practices from code to cloud deployment.

Node.js TypeScript Express License

πŸ“‹ Table of Contents

🎯 Overview

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)

✨ Features

Phase 1: Complete Project Foundation βœ…

  • βœ… 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

Phase 2: Database & Caching βœ… COMPLETE

  • βœ… 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

Phase 3: Containerization (Coming Soon)

  • Multi-stage Dockerfile
  • Docker Compose for local development
  • Kubernetes manifests (Deployments, Services, ConfigMaps)
  • Helm charts for orchestration

Phase 4: CI/CD & Automation (Coming Soon)

  • GitHub Actions workflows
  • Automated testing and linting
  • Docker image building and pushing
  • Automated deployments

Phase 5: Monitoring & Observability (Coming Soon)

  • Prometheus metrics
  • Grafana dashboards
  • Logging with ELK stack
  • Distributed tracing

πŸ›  Tech Stack

Core Technologies

  • Runtime: Node.js 20 LTS
  • Language: TypeScript 5.x
  • Framework: Express.js 4.x
  • Database: PostgreSQL 15 (Phase 2)
  • Caching: Redis 7 (Phase 2)

Security & Middleware

  • Helmet - Security headers
  • CORS - Cross-origin resource sharing
  • Compression - Response compression
  • Morgan - HTTP request logger
  • Express Validator - Input validation

Development Tools

  • TypeScript - Type safety and modern JavaScript features
  • ESLint - Code linting
  • Prettier - Code formatting
  • ts-node-dev - Development server with hot reload
  • Nodemon - Process manager

DevOps (Future Phases)

  • Docker & Docker Compose
  • Kubernetes & Helm
  • GitHub Actions
  • Prometheus & Grafana

πŸ“¦ Prerequisites

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)

πŸš€ Quick Start

1. Clone the repository

git clone https://github.com/yourusername/production-api-framework.git
cd production-api-framework

2. Install dependencies

npm install

3. Set up environment variables

cp .env.example .env

Edit .env file with your configuration (defaults work for development).

4. Start development server

npm run dev

The server will start at http://localhost:3000

5. Set up databases (Phase 2)

Using Docker Compose (Recommended):

# Start PostgreSQL and Redis
docker-compose up -d

# Run database migrations
npm run migration:run

# Seed development data
npm run seed

Manual Setup:

# Install PostgreSQL 15 and Redis 7
# Update .env with your database credentials

# Run migrations
npm run migration:run

# Seed development data
npm run seed

6. Verify the server is running

Open 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!

πŸ“ Project Structure

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

πŸ“œ Available Scripts

# 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)

🌐 API Endpoints

Health & Monitoring

Method Endpoint Description
GET /health Health check endpoint for monitoring
GET /ready Readiness probe with database/Redis status

API Information

Method Endpoint Description
GET / API information and available endpoints
GET /api/v1 API v1 information

Users (Phase 2)

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

Tasks (Phase 2)

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

Example Responses

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"
}

βš™οΈ Environment Variables

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=true

See .env.example for complete configuration options.

πŸ—“ Development Phases

βœ… Phase 1: Complete Project Foundation

  • Project initialization and structure
  • TypeScript configuration
  • Express server with middleware
  • Health check endpoints
  • Error handling
  • Code quality tools

βœ… Phase 2: Database & Caching (COMPLETE)

  • 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

πŸ”„ Phase 3: Containerization

  • Docker multi-stage builds
  • Docker Compose setup
  • Kubernetes manifests
  • Helm charts

πŸ”„ Phase 4: CI/CD Pipeline

  • GitHub Actions workflows
  • Automated testing
  • Docker image building
  • Deployment automation

πŸ”„ Phase 5: Monitoring & Testing

  • Unit and integration tests
  • Prometheus metrics
  • Grafana dashboards
  • Logging infrastructure

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a 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

πŸ“„ License

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

πŸ‘€ Author

Your Name

πŸ™ Acknowledgments

  • 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

πŸŽ‰ Live Deployment

Application is automatically deployed to AWS EC2 on every push to main.

Testing deployment - Sun Dec 7 04:29:27 EST 2025

Ready for deployment

About

Production-grade Node.js/TypeScript API framework with complete DevOps infrastructure. Docker, Kubernetes, CI/CD, monitoring, and security best practices.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors