Welcome to the NestJS Microservices project. This project is a collection of microservices that are designed to work together to provide a complete solution for a specific business domain. The microservices are designed to be independent of each other and can be deployed and scaled independently.
By @nikosanif
-
Install Node.js v20.15 (npm v10.7.0)
-
Install Docker and Docker Compose
-
For protobuf, you need to have
protocinstalled. You can install it using the following command:# macOS brew install protobuf # Ubuntu sudo apt install protobuf-compiler
-
Clone the repository and navigate to the project directory:
git clone <repo-url> cd nestjs-microservices
-
Install the dependencies:
npm install
-
Build protobuf files:
# Build the protobuf files nx run microservices:build-protobuf -
Start microservices:
# Start required services with docker (database, etc.) docker compose -f ./docker/docker-compose.yml up -d # In one shell, start the cyclops microservice # Users microservice (HTTP + gRPC API) npx nx run cyclops:serve # In another shell, start the wolverine microservice # Auth microservice (HTTP API) npx nx run wolverine:serve
The project is structured as a monorepo. Each microservice is a separate package within the monorepo. The monorepo is managed using nx.
The monorepo is structured as follows:
.
├── apps
│ ├── cyclops # Agnostic microservice
│ └── wolverine # Agnostic microservice
│
├── libs
│ ├── microservices
│ │ └── grpc # gRPC services/models
│ │
│ ├── modules
│ │ ├── auth # Auth module
│ │ ├── files # File management module
│ │ └── users # User management module
│ │
│ ├── sdk
│ │ ├── api # API utilities for microservices
│ │ ├── common # Common utilities for microservices
│ │ └── ... # Other SDKs
│ │
│ └── shared
│ ├── config # Configuration management
│ └── utils # Miscellaneous utilities
│
├── tools
│ ├── eslint # ESLint configuration of monorepo
│ └── scripts # Helper scripts for development
│
└── ... other filesThe following graph shows the dependencies between the packages in the monorepo.
- Formatting with Prettier
- Testing with Jest
- Linting with ESLint
- Boundaries between layers
- No circular dependencies
- Git hooks with Husky
- Publishable npm package
- Local npm registry with Verdaccio (for development)
- HTTP + gRPC communication
- Protobuf for gRPC
- Automatic generation of TypeScript types
- Automatic generation of gRPC services and decorators (directly to NestJS)
- Validation of DTOs
- Configuration management
- API utilities
- Swagger documentation
- Solid architecture
npx nx run <app>:serve- Start the specified microservicenpx nx run <app/lib>:build- Build the specified app or libnpx nx run <app/lib>:test- Run tests for the specified app or libnpx nx run microservices:build-protobuf- Generate TypeScript types and gRPC services from protobuf filesnpx nx graph- Generate a dependency graph of the monoreponpm run format:check- Check if the code is formatted correctlynpm run format:write- Format the codenpm run lint- Lint the codenpm run lint:affected- Lint the affected code
Who is for this? I would love for you to contribute to NestJS Microservices! You can contribute in many ways, such as creating new features, fixing bugs, improving documentation, or suggesting new ideas.
If you have found any bug in the source code or want to request a new feature, you can help by submitting an issue at GitHub. Even better, you can fork this repository and submit a PR with the fix or the new feature description.
- Star this repository 👆⭐️
- Also, if you are an Angular developer, check out my other repository: Angular Authentication 🛡️
- Fullstack Software Engineer - I’m currently working on Angular & Node.js application development.
- I write stuff at dev.to/nikosanif and nikosanif.medium.com
- How to reach me:
or
Feel free to use this repository, but please star and put a reference to this repository. 🙏 ❤️
