MonoloDoc

Simplified file structure

- apps/ // Where all apps are located, you MUST NOT create new apps by yourself, it is a decision for the whole team to make
- libs/ // Where all the code of the apps is located
	- *.controller // The controllers are the place where routes are exposed. Controllers MUST NEVER import other controllers
	- *.service // The services contains all the effective code of the app, they are imported by controllers and can be imported in other services IF it is required and doesn't create a circular dependency
	- prisma/
		- client/ // The prisma clients allows communications with the databases
		- schema/ // The prisma schemas define how the databases are shaped
- secrets/ // The folder used for secrets that cannot be contained in the .env file (such as cert files)
- .env // All secrets that can be contained in the environment variabled of the production machine

It is highly discouraged to edit any other file since this repository is managed by NX and editing any of these files might break our NX Cloud configurations

Creating a new Service

  1. Run npx nx g @nx/nest:library
  2. When asked, type the library-name.service (ex: demo.service)
  3. Then, NX will ask you where it should place the service, choose the one where the root starts with libs/ (here in our example: Root: libs/demo.service)
  4. Open the newly created demo.service folder inside libs/
  5. Open src/lib/
  6. Create a new file named demo.service.ts demo.service.spec.ts
  7. Inside these files create your new Nest service (see Demo service example)
  8. On the demo.service.module.ts that have been generated by the previous command, export your newly created service. Note: on this file you can also import other services, but you need to be careful of not creating circular dependencies

Creating a new Controller

  1. Run npx nx g @nx/nest:library
  2. When asked, type the library-name.service (ex: demo.controller)
  3. Then, NX will ask you where it should place the service, choose the one where the root starts with libs/ (here in our example: Root: libs/demo.controller)
  4. Open the newly created demo.controller folder inside libs/
  5. Open src/lib/
  6. Create new files named demo.controller.ts and demo.controller.spec.ts
  7. Inside these files create your new Nest controller (see Demo controller example)
  8. On the demo.controller.module.ts that have been generated by the previous command, add to the controllers your newly created controller and import the services you need. Note: Controllers MUST NEVER import other controllers
  9. Open the apps/app where this new controller must be added (ex: apps/api)
  10. Open src/app
  11. Inside app.module.ts, import your new controller’s module (ex: DemoModule for the demo controller)
  12. Restart the apps and your new controller should be exported