A comprehensive Node-Boot microservices monorepo sample project demonstrating modern microservices architecture, inter-service communication, and monorepo management using Turborepo.
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) β
βββββββββββββββββββ ββββββββββββββββββββ
- 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
- 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)
- 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
- 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
- MongoDB: Document database with cloud Atlas integration
- TypeORM: Object-relational mapping with MongoDB support
- 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
- OpenAPI/Swagger: Auto-generated API documentation
- class-validator: Request validation with decorators
- CORS: Cross-origin resource sharing configuration
- 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
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
- Node.js 18+
- pnpm 7.5.1+
- MongoDB Atlas account or local MongoDB instance
-
Clone the repository
git clone https://github.com/nodejs-boot/sample-microservices-monorepo.git cd sample-microservices-monorepo -
Install dependencies
pnpm install
-
Build all services
pnpm build
-
Start development servers
pnpm dev
- Account Service: http://localhost:40000/v1
- User Service: http://localhost:42000/v1
- Statistics Service: http://localhost:41000/v1
pnpm dev- Start all services in development modepnpm build- Build all servicespnpm test- Run tests across all servicespnpm tsc- Type check all services
pnpm lint- Lint all codepnpm lint:fix- Fix linting issuespnpm format:check- Check code formattingpnpm format:fix- Fix formatting issues
pnpm nodeboot:update- Update NodeBoot dependenciespnpm nodeboot:check:type-deps- Verify type dependenciespnpm changeset:create- Create a new changeset
This monorepo showcases key NodeBoot capabilities:
- Service dependency injection
- HTTP client injection with configuration
- Repository pattern with automatic injection
- YAML-based configuration with environment variable interpolation
- Service-specific configuration with shared patterns
- Integration configuration for service communication
- Declarative HTTP clients with
@HttpClientdecorator - Automatic service discovery and configuration
- Built-in timeout and logging support
- MongoDB integration with TypeORM
- Repository pattern with pagination support
- Entity validation and transformation
- Controller-based routing with decorators
- Automatic OpenAPI documentation generation
- Request validation with class-validator
- Structured error handling
- Custom error handling middleware
- Logging middleware with Winston integration
- CORS configuration
-
Account Creation Flow:
Client β Account Service β User Service (validation) β Statistics Service (event recording) -
User Validation: Account Service validates users exist before account creation
-
Event Tracking: All account operations are recorded in Statistics Service
-
Error Propagation: Service errors are properly handled and propagated
- 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
Each service includes comprehensive documentation:
- API endpoints and request/response models
- Configuration options
- Development setup instructions
- Docker containerization
- Follow the established code style (ESLint + Prettier)
- Add tests for new functionality
- Update documentation as needed
- Use changesets for version management
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.