A modular and scalable Node.js framework for building efficient, enterprise-ready backend architectures with NestJS.
A modular, scalable, and enterprise-ready backend architecture built with NestJS.
This project is designed to accelerate backend development, especially for rapid Proof-of-Concept (PoC) efforts, new system bootstrapping, or as a clean foundation for evolving from a monolith to microservices. It embraces the modular monolith patternβintentionally excluding Clean Architecture and Domain-Driven Design (DDD) to reduce complexity and promote faster iteration.
Ideal for enterprises and startups, this template helps teams progress from PoC to Product-Market Fit (PMC) by offering:
- A structured yet flexible modular architecture
- Integrated logger mechanism for operational insight
- A database factory pattern supporting multiple databases (MySQL, PostgreSQL, SQLite)
If you're looking for a reliable and pragmatic backend starterβwhether for demos, PoC trials, or real-world product foundationsβthis project can help you move fast with confidence.
This project follows a modular monolith architecture, emphasizing clear separation of concerns while maintaining the simplicity of a monolithic deployment. The folder layout encourages scalable, testable, and maintainable codebases.
modular-monolith-architecture
βββ Dockerfile
βββ docker-compose.*.yml # Support PostgreSQL & SQLite
βββ logs/ # Daily log files
βββ src/
β βββ main.ts # Entry point
β βββ app.module.ts # Root module
β βββ common/ # Shared logic (e.g., logger, interceptors)
β βββ config/ # Multi-database configuration (MySQL, PostgreSQL, SQLite)
β βββ modules/
β βββ product/ # Product feature module
β βββ user/ # User feature module
βββ test/ # e2e testing
βββ sample.env # Environment config template
βββ README.md
-
common/: Cross-cutting concerns such as custom exception filters, response interceptors, and centralized logging.
-
config/: Modular database configuration with support for SQLite, PostgreSQL, and MySQL, using a database factory pattern.
-
modules/: Business logic split into independently maintainable feature modules (e.g., user, product), each with:
- controllers/: Handle HTTP requests
- services/: Core business logic
- repositories/: Database access logic
- dto/, entities/, facades/: Well-structured data handling
- β Modular Monolith Structure β Clear, maintainable boundaries between features while remaining deployable as a single unit.
- π§ͺ Built-in e2e Testing β Includes Jest test setup to validate end-to-end functionality.
- π¦ Multi-Database Support β Easily switch between SQLite, PostgreSQL, and MySQL via plug-and-play configuration.
- πͺ΅ Advanced Logging β Centralized file-based logging system with daily rotation (e.g., logs/application-YYYY-MM-DD.log).
- π Feature-Based Modular Design β Each domain (e.g., user/product) is fully encapsulated with its own logic.
- βοΈ Docker & Compose Ready β Start instantly with docker-compose setups for PostgreSQL and SQLite.
Avoids over-engineering by not enforcing Clean Architecture or full DDD. Ideal for fast-moving projects, PoCs, or early-stage product validation.
All domain modules are logically isolated, enabling easier future migration to microservices when scale demands itβwithout premature complexity.
Whether you're a lean startup or an enterprise team, this template provides a solid base to:
- Quickly prototype ideas with real APIs
- Gradually scale into a production-grade product
- Demo to stakeholders using different DB engines
Designed to support the lifecycle from Proof-of-Concept (PoC) to Product-Market Fit (PMC), offering balance between agility and structure.
Follow these steps to get your modular monolith project up and running in minutes.
- Clone the Template
git clone https://github.com/your-username/modular-monolith-architecture.git
cd modular-monolith-architecture
- Install Dependencies
npm install
- Set Up Environment Variables
Copy the sample environment file and customize it if needed:
cp sample.env .env
- Run the Application (Development Mode)
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
By default, the API will be available at: π http://localhost:3000
- Run tests
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
- Use Docker (Optional)
- Run with SQLite (default)
docker-compose -f docker-compose.sqlite.yml up
- Run with PostgreSQL
docker-compose -f docker-compose.postgresql.yml up
Application logs are automatically saved to the logs/ directory with daily log rotation (e.g., application-2025-04-27.log).
When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the deployment documentation for more information.
If you are looking for a cloud-based platform to deploy your NestJS application, check out Mau, our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:
$ npm install -g mau
$ mau deploy
With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.
Check out a few resources that may come in handy when working with NestJS:
- Visit the NestJS Documentation to learn more about the framework.
- For questions and support, please visit our Discord channel.
- To dive deeper and get more hands-on experience, check out our official video courses.
- Deploy your application to AWS with the help of NestJS Mau in just a few clicks.
- Visualize your application graph and interact with the NestJS application in real-time using NestJS Devtools.
- Need help with your project (part-time to full-time)? Check out our official enterprise support.
- To stay in the loop and get updates, follow us on X and LinkedIn.
- Looking for a job, or have a job to offer? Check out our official Jobs board.
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
- Author - Da-Wei Lin
- Website - David Weblog
- Twitter - @nestframework
Nest is MIT licensed.