Contribubting to the Server
The server is the core of the project, it’s the one that handles all the logic and the data, it’s the one that communicates with the database and the one that serves the data to the client.
We are using TS-Rest to handle the API, it’s a very simple and easy to use library that allows us to create a REST API with TypeScript, while maintaing the typesafety across projects. That definition is done in @tms/api package. In the server we implement all the logic to fullfil the API definition.
We use the following structure:
- Auth: All the logic related to authentication and authorization.
- Commands: All logic related to actions bein run in the process, like processing a certain entity, creating entities, validating processes or making changes in the database.
- Controller: These are the handlers of the request, here we try to keep the logic as simple as possible, and we try to keep the logic in the commands, we mostly should validate or transform the inputs as needed for the commands to be run and handle the heavy lifting.
- DB: Here we define and handle our database connection, we use Drizzle ORM to handle the database connection and the models, these are defined in @tms/db package.
- Respositories: Here we define the repositories that are used to interact with the database, we keep all queries and related database actions to try and keep the code as reusable as possible, these way we can take advantage of Drizzle’s prepared statements for complex queries.
- Services: Here we define all logic related to external services, like S3 integrations, Google Maps’ Geoencoding or any other service that we might need to interact with.
- Validators: TBD if needed
Last updated on