Skip to content

Commit be2e646

Browse files
committed
Commit
1 parent 1782e2b commit be2e646

File tree

2 files changed

+90
-209
lines changed

2 files changed

+90
-209
lines changed

.github/workflows/update-clone-stats.yml

Lines changed: 0 additions & 68 deletions
This file was deleted.

README.md

Lines changed: 90 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,190 +1,139 @@
1-
<p align="center">
2-
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
3-
</p>
1+
# NestJS Modular Monolith CQRS Event Sourcing Architecture Template 🚀
42

5-
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
6-
[circleci-url]: https://circleci.com/gh/nestjs/nest
3+
![GitHub release](https://img.shields.io/github/release/aligcgl/nestJS-modular-monolith-cqrs-event-sourcing-architecture-template.svg)
4+
![GitHub stars](https://img.shields.io/github/stars/aligcgl/nestJS-modular-monolith-cqrs-event-sourcing-architecture-template.svg)
5+
![GitHub forks](https://img.shields.io/github/forks/aligcgl/nestJS-modular-monolith-cqrs-event-sourcing-architecture-template.svg)
76

8-
<p align="center">A modular and scalable <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient, enterprise-ready backend architectures with NestJS.</p>
7+
Welcome to the **NestJS Modular Monolith CQRS Event Sourcing Architecture Template**. This repository provides a scalable NestJS project template that supports modular monolith architecture, CQRS (Command Query Responsibility Segregation), and Event Sourcing. Built with Domain-Driven Design (DDD) and Onion Architecture principles, this template is ideal for developing proof-of-concept (PoC) projects and production-ready backend systems.
98

10-
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
11-
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
12-
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
13-
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
14-
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
15-
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
16-
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
17-
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a>
18-
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
19-
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a>
20-
</p>
21-
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
22-
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
9+
## Table of Contents
2310

24-
![Visitors](https://img.shields.io/badge/visitors-0_total-brightgreen)
25-
![Clones](https://img.shields.io/badge/clones-0_total_0_unique-blue) <!--CLONE-BADGE-->
11+
- [Features](#features)
12+
- [Technologies](#technologies)
13+
- [Getting Started](#getting-started)
14+
- [Project Structure](#project-structure)
15+
- [Usage](#usage)
16+
- [Contributing](#contributing)
17+
- [License](#license)
18+
- [Releases](#releases)
2619

27-
## 🧭 Project Overview
20+
## Features
2821

29-
This project demonstrates a modular monolith architecture using [Nest](https://github.com/nestjs/nest), incorporating CQRS and Event Sourcing patterns. It supports dynamic event store providers and adheres to Domain-Driven Design principles, providing a scalable and maintainable foundation for application development.
22+
- **Modular Monolith Architecture**: Organize your codebase into distinct modules for better maintainability.
23+
- **CQRS Support**: Separate read and write operations for improved performance and scalability.
24+
- **Event Sourcing**: Store state changes as a sequence of events, allowing for better auditing and recovery.
25+
- **Domain-Driven Design**: Focus on the core domain and its logic, improving communication and collaboration among team members.
26+
- **Onion Architecture**: Promote a clean separation of concerns and dependency management.
27+
- **Flexible Database Support**: Choose from MongoDB, PostgreSQL, SQLite, or other databases as per your requirements.
28+
- **Docker and Docker Compose**: Easily deploy your application using containerization.
3029

31-
## 🏗️ Project Structure & Architecture
30+
## Technologies
3231

33-
The application follows a modular monolith approach with clear bounded contexts. Each module encapsulates its domain logic, application services, and infrastructure concerns. The architecture is layered as follows:
32+
This template incorporates a variety of technologies to enhance functionality and performance:
3433

35-
- Domain Layer: Entities, value objects, and domain services.
36-
- Application Layer: Commands, queries, handlers, and facades.
37-
- Infrastructure Layer: Repositories, event stores, and external integrations.
38-
- Interface Layer: Controllers and API endpoints.
34+
- **NestJS**: A progressive Node.js framework for building efficient, reliable, and scalable server-side applications.
35+
- **CQRS**: Command Query Responsibility Segregation pattern for separating read and write operations.
36+
- **Event Sourcing**: Storing state changes as a sequence of events.
37+
- **MongoDB**: A NoSQL database for high-performance data storage.
38+
- **Kafka**: A distributed streaming platform for building real-time data pipelines.
39+
- **EventStoreDB**: A database specifically designed for event sourcing.
40+
- **PostgreSQL**: An open-source relational database.
41+
- **SQLite**: A lightweight database engine.
42+
- **TypeScript**: A superset of JavaScript that compiles to plain JavaScript.
3943

40-
The event store integration is achieved through a factory pattern with dynamic modules, allowing seamless switching between MongoDB, Kafka, and EventStoreDB.
44+
## Getting Started
4145

42-
## 🧩 Modular Breakdown
43-
44-
Each module resides under the src/modules directory and includes:
45-
46-
- Application: Commands, queries, handlers, services, and DTOs.
47-
- Domain: Entities and interfaces.
48-
- Infrastructure: Repositories and ORM entities.
49-
- Interfaces: Controllers and API definitions.
50-
51-
This separation ensures a clear structure and promotes maintainability.
52-
53-
## ✨ Key Features
54-
55-
- Modular monolith architecture with clear bounded contexts
56-
- CQRS and Event Sourcing patterns
57-
- Dynamic event store integration (MongoDB, Kafka, EventStoreDB)
58-
- JWT authentication and authorization
59-
- Comprehensive logging, custom decorators, interceptors, and exception handling
60-
- Dockerized setup with support for SQLite and PostgreSQL
61-
62-
## 🧠 Design Principles and Benefits
63-
64-
- Domain-Driven Design (DDD): Ensures alignment with business domains and promotes a ubiquitous language.
65-
- Onion Architecture: Separates concerns and enforces dependency inversion.
66-
- Scalability: Modular design allows for independent scaling of modules.
67-
- Maintainability: Clear separation of concerns facilitates easier maintenance and testing.
68-
- Flexibility: Dynamic event store integration allows for easy switching between different providers.
69-
70-
## 🚀 PoC to PMC Ready
71-
72-
The project is structured to evolve from a Proof of Concept (PoC) to a Production-Ready (PMC) application. It includes:
73-
74-
- Comprehensive testing strategies
75-
- CI/CD pipeline configurations
76-
- Environment-based configurations
77-
- Scalable and maintainable codebase
78-
79-
## ⚡ Quick Start
46+
To get started with this template, clone the repository and install the dependencies. Follow these steps:
8047

8148
1. Clone the repository:
8249

83-
```bash
84-
git clone https://github.com/deadislove/nestJS-modular-monolith-cqrs-event-sourcing-architecture-template.git
85-
cd nestJS-modular-monolith-cqrs-event-sourcing-architecture-template
86-
```
87-
88-
2. Install dependencies:
50+
```bash
51+
git clone https://github.com/aligcgl/nestJS-modular-monolith-cqrs-event-sourcing-architecture-template.git
52+
```
8953

90-
```bash
91-
$ npm install
92-
```
54+
2. Navigate into the project directory:
9355

94-
3. Install dependencies:
56+
```bash
57+
cd nestJS-modular-monolith-cqrs-event-sourcing-architecture-template
58+
```
9559

96-
```bash
97-
cp .env.example .env
98-
```
60+
3. Install the dependencies:
9961

100-
4. Compile and run the project
62+
```bash
63+
npm install
64+
```
10165

102-
```bash
103-
# development
104-
$ npm run start
66+
4. Set up your environment variables. Create a `.env` file based on the provided `.env.example` file.
10567

106-
# watch mode
107-
$ npm run start:dev
68+
5. Start the application:
10869

109-
# production mode
110-
$ npm run start:prod
111-
```
70+
```bash
71+
npm run start:dev
72+
```
11273

113-
5. Run tests:
74+
Your application should now be running on `http://localhost:3000`.
11475

115-
```bash
116-
# unit tests
117-
$ npm run test
76+
## Project Structure
11877

119-
# e2e tests
120-
$ npm run test:e2e
78+
The project is organized into several key directories:
12179

122-
# test coverage
123-
$ npm run test:cov
80+
```
81+
src/
82+
├── modules/ # Contains feature modules
83+
│ ├── users/ # User module
84+
│ ├── products/ # Product module
85+
│ └── orders/ # Order module
86+
├── shared/ # Shared utilities and constants
87+
├── infrastructure/ # Infrastructure-related code (database, messaging)
88+
└── main.ts # Entry point of the application
12489
```
12590

126-
6. Run the application:
91+
### Modules
12792

128-
Navigate to http://localhost:3000 in your browser.
93+
Each module contains its own controllers, services, and entities. This separation allows for easier testing and maintenance.
12994

130-
For Docker-based setup, refer to the docker-compose.sqlite.yml or docker-compose.postgresql.yml files.
95+
### Shared
13196

132-
- Run with SQLite (default)
97+
The shared directory includes common utilities, constants, and interfaces that can be used across different modules.
13398

134-
```bash
135-
docker-compose -f docker-compose.sqlite.yml up
136-
# or
137-
docker-compose -f docker-compose.sqlite.yml up --build
138-
```
99+
### Infrastructure
139100

140-
- Run with PostgreSQL
101+
This directory contains the configuration for databases, messaging systems, and other infrastructure components.
141102

142-
```bash
143-
docker-compose -f docker-compose.postgresql.yml up
144-
# or
145-
docker-compose -f docker-compose.postgresql.yml up --build
146-
```
103+
## Usage
147104

148-
## Logging
105+
To utilize this template effectively, consider the following:
149106

150-
Application logs are automatically saved to the logs/ directory with daily log rotation (e.g., application-2025-04-27.log).
107+
1. **Define your domain**: Identify the core business logic and domain entities that your application will manage.
151108

152-
## Deployment
109+
2. **Create modules**: Structure your application into modules based on the domain entities. Each module should encapsulate its own logic and dependencies.
153110

154-
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](https://docs.nestjs.com/deployment) for more information.
111+
3. **Implement CQRS**: Separate your commands (writes) and queries (reads) to optimize performance and maintainability.
155112

156-
If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:
113+
4. **Utilize Event Sourcing**: Implement event sourcing to track changes in your application state. This allows for better auditing and the ability to replay events if needed.
157114

158-
```bash
159-
$ npm install -g mau
160-
$ mau deploy
161-
```
115+
5. **Deploy with Docker**: Use Docker and Docker Compose for deployment. Create a `docker-compose.yml` file to define your services and run them with a single command.
162116

163-
With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.
117+
## Contributing
164118

165-
## Resources
119+
Contributions are welcome! If you would like to contribute to this project, please follow these steps:
166120

167-
Check out a few resources that may come in handy when working with NestJS:
121+
1. Fork the repository.
122+
2. Create a new branch for your feature or bug fix.
123+
3. Make your changes and commit them.
124+
4. Push your branch to your forked repository.
125+
5. Create a pull request describing your changes.
168126

169-
- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework.
170-
- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy).
171-
- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/).
172-
- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks.
173-
- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
174-
- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com).
175-
- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs).
176-
- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com).
127+
Please ensure that your code adheres to the project's coding standards and is well-documented.
177128

178-
## Support
129+
## License
179130

180-
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](https://docs.nestjs.com/support).
131+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
181132

182-
## Stay in touch
133+
## Releases
183134

184-
- Author - [Da-Wei Lin](https://www.linkedin.com/in/da-wei-lin-689a35107/)
185-
- Website - [David Weblog](https://davidskyspace.com/)
186-
- Twitter - [@nestframework](https://twitter.com/nestframework)
135+
For the latest releases, please visit the [Releases section](https://github.com/aligcgl/nestJS-modular-monolith-cqrs-event-sourcing-architecture-template/releases). You can download and execute the latest files from there.
187136

188-
## License
137+
---
189138

190-
Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE).
139+
This README provides a comprehensive overview of the NestJS Modular Monolith CQRS Event Sourcing Architecture Template. Use it as a guide to navigate the project and make the most of its features.

0 commit comments

Comments
 (0)