This is a NestJS monorepo project boilerplate that provides a solid foundation for building scalable and maintainable applications. The monorepo structure allows for easy code sharing and reusability across multiple projects. The structure focuses on the use case of a Bookstore where we want to keep NestJS two separate APIs: one for a bookstore and another for employees of the bookstore. The purpose of this boilerplate is to keep the two APIs separate, while also providing a NestJS library to share common modules such as authentication and user management.
To get started with this project, follow these steps:
- Clone the repository to your local machine
- Install the necessary dependencies by running
pnpm install
in the root directory of the project (notice that the seput is usingpnpm
instead ofnpm
oryarn
This project is structured as a monorepo, with the following directories:
- apps/bookstore-api: This directory contains the code for the API that serves the bookstore.
- apps/employee-api: This directory contains the code for the API that serves the employees of the bookstore.
- libs/authentication: This directory contains the code for the NestJS library that should provide common modules for authentication
- libs/users: This directory contains the code for the NestJS library that should provide common modules for users
Refer to the following visual organisation for clarity. Also, consider that this architectural approach is based on the official NestJS documentation.
nestjs-monorepo/
├─ node_modules/
├─ apps/
│ ├─ bookstore-api/
│ │ ├─ src
│ │ ├─ test
│ ├─ employees-api/
│ │ ├─ src
│ │ ├─ test
├─ libs/
│ ├─ auth/
│ ├─ users/
├─ .gitignore
├─ package.json
├─ nest-cli.json
├─ README.md
To run the APIs, follow these steps:
- Navigate to the apps/bookstore-api directory
- Start the server by running npm run start:dev
- Navigate to the apps/employee-api directory
- Start the server by running npm run start:dev
To use the common library in either of the APIs, follow these steps:
- Import the necessary modules from the @app/* package
- Use the imported modules in your code For example, to use the authentication module in the apps/bookstore-api API, you would do the following:
import { AuthModule } from '@bookstore/common';
@Module({
imports: [AuthModule],
controllers: [BookstoreController],
providers: [BookstoreService],
})
export class BookstoreModule {}
If you would like to contribute to this project, please follow these steps:
- Fork the repository
- Create a new branch for your changes
- Make your changes and commit them to your branch
- Push your changes to your forked repository
- Create a pull request to merge your changes into the main repository
This project is licensed under the MIT License. See the LICENSE file for more details.