๐ Welcome to my Monorepo Boilerplate repository.
This project is structured as a monorepo and is managed with Nx, a powerful tool for monorepo development, which helps orchestrate and optimize the build process among other tasks.
The backend is built with NestJS, featuring many standard implementations ready to go out of the box. Read below for more details.
To get the backend up and running in a development environment, follow these steps:
-
Clone the repository: Use the following command to clone the repository to your local machine:
git clone https://github.com/DeanRTaylor1/monorepo-example
-
Install dependencies: Navigate to the project directory and use Yarn to install the necessary dependencies:
cd <repository-directory> yarn
-
Run the Application: You can now start the application with the following command (utilizes Docker):
yarn dev:docker
This command (
dev:be
) is shorthand fordocker-compose up
, as defined in thescripts
section ofpackage.json
, which sets up the database and server containers. More applications can be added to the docker-compose.yml
The backend is structured with an emphasis on modular organization aligned with my personal preference for NestJs. The root of the project contains the app
directory, which holds global logic and forms the base of our Nest project.
Utility decorators such as @BodyToCamel and @SnakeInterceptor are integrated for handling case conversion of DTOs between snake case and camelCase. Types are shared in the common
Case Utils directory to minimize repetition across backend and frontend.
Sensitive information is safeguarded by the responses
interceptor, which automatically excludes specified fields from client exposure. These sanitized types are also declared in the common
Sanitize Types package for frontend usage.
Configurations, including environment variables, are managed through an env object, which is set up to read from .env.NODE_ENV.local
files. Sequelize is the chosen ORM, but you can swap it out for TypeORM if preferred.
Role-based authentication with JWT is implemented, with route-level control using decorators and guards, by default all routes have basic auth and you need to disable auth with the @Public() decorator, to set up role authentication you can apply the @Roles and @UseGuard decorators which is explained on the nestjs docs. Refer to the UsersController for an example of setup.
Further project details and instructions on extending functionality with Nx are available in the Nx documentation.
Below is the directory structure of the backend, illustrating the organization and location of important files:
.
โโโ databases
โ โโโ config
โ โ โโโ config.js
โ โโโ migrations
โ โ โโโ 20231031032120-create-users.ts
โ โโโ models
โ โโโ index.js
โโโ jest.config.ts
โโโ project.json
โโโ sequelize.js
โโโ src
โ โโโ app
โ โ โโโ app.controller.spec.ts
โ โ โโโ app.controller.ts
โ โ โโโ app.module.ts
โ โ โโโ app.service.spec.ts
โ โ โโโ app.service.ts
โ โ โโโ decorators
โ โ โ โโโ body-to-camel.decorator.ts
โ โ โ โโโ pagination.decorator.ts
โ โ โ โโโ public-route.decorator.ts
โ โ โ โโโ roles.decorator.ts
โ โ โโโ filters
โ โ โ โโโ all-exceptions.filter.spec.ts
โ โ โ โโโ all-exceptions.filter.ts
โ โ โโโ guards
โ โ โ โโโ auth.guard.ts
โ โ โ โโโ roles.guard.ts
โ โ โโโ interceptors
โ โ โ โโโ responses.interceptor.spec.ts
โ โ โ โโโ responses.interceptor.ts
โ โ โ โโโ route-logger.interceptor.spec.ts
โ โ โ โโโ route-logger.interceptor.ts
โ โ โ โโโ snakecase.interceptor.spec.ts
โ โ โ โโโ snakecase.interceptor.ts
โ โ โโโ modules
โ โ โ โโโ [auth](apps/backend/src/app/modules/auth)
โ โ โ โโโ [base](apps/backend/src/app/modules/base)
โ โ โ โโโ [config](apps/backend/src/app/modules/config)
โ โ โ โโโ [users](apps/backend/src/app/modules/users)
โ โ โโโ pipes
โ โ โโโ compare-password.pipe.ts
โ โ โโโ hash-password.pipe.ts
โ โโโ assets
โ โโโ main.ts
โ โโโ utils
โ โโโ encryption.ts
โ โโโ format.utils.ts
โโโ tsconfig.app.json
โโโ tsconfig.json
โโโ tsconfig.spec.json
โโโ webpack.config.js