Skip to content

nodejs-boot/sample-microservices-monorepo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Sample Microservices Monorepo

A comprehensive Node-Boot microservices monorepo sample project demonstrating modern microservices architecture, inter-service communication, and monorepo management using Turborepo.

πŸ—οΈ Architecture Overview

This project showcases a microservices architecture with three interconnected services that demonstrate real-world patterns of service communication, data consistency, and event tracking.

                             β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                             β”‚   Account Service   β”‚
                             β”‚     Port: 40000     β”‚
                             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                       β”‚
                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                 β”‚                     β”‚                          β”‚
                 β–Ό                     β–Ό                          β–Ό
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚   User Service  β”‚        β”‚   Account DB    β”‚     β”‚ Statistics Service β”‚
    β”‚   Port: 42000   β”‚        β”‚   (MongoDB)     β”‚     β”‚    Port: 41000     β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚                                                  β”‚
              β–Ό                                                  β–Ό
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚   Users DB      β”‚                                 β”‚  Statistics DB   β”‚
    β”‚   (MongoDB)     β”‚                                 β”‚   (MongoDB)      β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Service Interactions

  • Account Service β†’ User Service: Validates user existence during account creation
  • Account Service β†’ Statistics Service: Records account events (creation, updates, deletions)
  • Each service maintains its own dedicated MongoDB database for data isolation
  • All services use HTTP-based communication with NodeBoot's built-in HTTP client framework

πŸš€ Services

  • Port: 40000
  • Purpose: Account management with CRUD operations
  • Features: Slug-based identification, user validation, score-based ranking
  • Dependencies: User Service (validation), Statistics Service (event recording)
  • Port: 42000
  • Purpose: User management and authentication
  • Features: Email validation, user status management, CRUD operations
  • Dependencies: None (foundational service)
  • Port: 41000
  • Purpose: Event tracking and analytics
  • Features: Event recording, aggregation, filtering by type and user
  • Dependencies: None (receives events from other services)

πŸ› οΈ Technology Stack

Core Framework

  • NodeBoot: Modern Node.js framework with dependency injection, decorators, and enterprise-grade features
  • Node.js: 18+ runtime environment
  • TypeScript: Type-safe development with full ES2022+ support

Monorepo Management

  • Turborepo: High-performance build system for JavaScript and TypeScript monorepos
  • pnpm: Fast, disk space efficient package manager with workspace support
  • Workspaces: Organized service isolation with shared dependencies

Database & Persistence

  • MongoDB: Document database with cloud Atlas integration
  • TypeORM: Object-relational mapping with MongoDB support

Development & Quality

  • Jest: Testing framework with SWC transpilation
  • ESLint: Code linting with TypeScript support
  • Prettier: Code formatting with import organization
  • Husky: Git hooks for pre-commit quality checks
  • Lint-staged: Run linters on staged files

API & Documentation

  • OpenAPI/Swagger: Auto-generated API documentation
  • class-validator: Request validation with decorators
  • CORS: Cross-origin resource sharing configuration

DevOps & Tooling

  • Docker: Containerization support for each service
  • GitHub Actions: CI-CD
  • Nodemon: Development server with hot reloading
  • Winston: Structured logging
  • Changesets: Version management and changelog generation

πŸ“ Project Structure

sample-microservices-monorepo/
β”œβ”€β”€ services/                    # Microservices directory
β”‚   β”œβ”€β”€ account-service/         # Account management service
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ api/            # Controllers and models
β”‚   β”‚   β”‚   β”œβ”€β”€ client/         # HTTP clients for other services
β”‚   β”‚   β”‚   β”œβ”€β”€ config/         # Service configuration
β”‚   β”‚   β”‚   β”œβ”€β”€ middlewares/    # Custom middleware
β”‚   β”‚   β”‚   β”œβ”€β”€ persistence/    # Database entities and repositories
β”‚   β”‚   β”‚   └── services/       # Business logic
β”‚   β”‚   β”œβ”€β”€ app-config.yaml     # Service configuration
β”‚   β”‚   └── Dockerfile          # Container configuration
β”‚   β”œβ”€β”€ user-service/           # User management service
β”‚   └── statistics-service/     # Event tracking service
β”œβ”€β”€ shared/                     # Shared libraries (future)
β”œβ”€β”€ package.json               # Root package configuration
β”œβ”€β”€ pnpm-workspace.yaml        # Workspace configuration
β”œβ”€β”€ turbo.json                 # Turborepo configuration
β”œβ”€β”€ tsconfig.base.json         # Base TypeScript configuration
└── README.md                  # This file

🚦 Getting Started

Prerequisites

  • Node.js 18+
  • pnpm 7.5.1+
  • MongoDB Atlas account or local MongoDB instance

Installation

  1. Clone the repository

    git clone https://github.com/nodejs-boot/sample-microservices-monorepo.git
    cd sample-microservices-monorepo
  2. Install dependencies

    pnpm install
  3. Build all services

    pnpm build
  4. Start development servers

    pnpm dev

Service URLs

πŸ“‹ Available Scripts

Development

  • pnpm dev - Start all services in development mode
  • pnpm build - Build all services
  • pnpm test - Run tests across all services
  • pnpm tsc - Type check all services

Code Quality

  • pnpm lint - Lint all code
  • pnpm lint:fix - Fix linting issues
  • pnpm format:check - Check code formatting
  • pnpm format:fix - Fix formatting issues

Utilities

  • pnpm nodeboot:update - Update NodeBoot dependencies
  • pnpm nodeboot:check:type-deps - Verify type dependencies
  • pnpm changeset:create - Create a new changeset

🎯 NodeBoot Framework Features Demonstrated

This monorepo showcases key NodeBoot capabilities:

Dependency Injection

  • Service dependency injection
  • HTTP client injection with configuration
  • Repository pattern with automatic injection

Configuration Management

  • YAML-based configuration with environment variable interpolation
  • Service-specific configuration with shared patterns
  • Integration configuration for service communication

HTTP Client Framework

  • Declarative HTTP clients with @HttpClient decorator
  • Automatic service discovery and configuration
  • Built-in timeout and logging support

Data Persistence

  • MongoDB integration with TypeORM
  • Repository pattern with pagination support
  • Entity validation and transformation

API Development

  • Controller-based routing with decorators
  • Automatic OpenAPI documentation generation
  • Request validation with class-validator
  • Structured error handling

Middleware Support

  • Custom error handling middleware
  • Logging middleware with Winston integration
  • CORS configuration

πŸ”„ Inter-Service Communication Flow

  1. Account Creation Flow:

    Client β†’ Account Service β†’ User Service (validation) β†’ Statistics Service (event recording)
    
  2. User Validation: Account Service validates users exist before account creation

  3. Event Tracking: All account operations are recorded in Statistics Service

  4. Error Propagation: Service errors are properly handled and propagated

πŸ§ͺ Testing Strategy

  • Unit Tests: Jest with SWC for fast transpilation
  • Integration Tests: Service-to-service communication testing
  • Type Safety: Full TypeScript coverage with strict configuration
  • Mocking: HTTP client stubbing for isolated testing

πŸ“– Documentation

Each service includes comprehensive documentation:

  • API endpoints and request/response models
  • Configuration options
  • Development setup instructions
  • Docker containerization

🀝 Contributing

  1. Follow the established code style (ESLint + Prettier)
  2. Add tests for new functionality
  3. Update documentation as needed
  4. Use changesets for version management

πŸ“„ License

This project is licensed under the MIT License - see individual service LICENSE files for details.


This sample demonstrates production-ready microservices architecture using NodeBoot framework, showcasing modern development practices, proper service separation, and effective monorepo management.

About

Node-Boot micro-services monorepo sample project

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published