Skip to content

Backend

Programming languages and frameworks used

The backend is written in TypeScript with the Node.js runtime environment.

It articulates around the Express web framework. Controllers are built using the tsoa tool to produce a fully OpenAPI-compliant API. Dependency injection uses tsyringe. Authentication is managed using Passport.

INFO

If there is a need to add other types of authentication methods, such as Single-Sign-On (SSO), refer to strategies defined in backend/src/config/passport.ts.

Tests are written using the Vitest framework, which has a one-to-one API compatible with Jest.

File structure

src/server.ts: backend entry point.

src/app.ts: Express app setup (middlewares, routes, error handling).

src/authentication.ts: authentication helpers and guards used by controllers.

src/controllers: API controllers (tsoa endpoints).

src/services: business logic used by controllers.

src/models: database entities and ORM models.

src/dtos: request/response DTOs used by the API.

src/migrations: database migration files.

src/config: technical configuration (CORS, data source, Passport, etc.).

src/constants: shared constants.

src/types and src/types.d.ts: shared custom TypeScript types.

src/tests: backend test helpers and fixtures.

Usage

It is prefered during development that you do not launch the backend using Docker but rather directly using Node. The Docker image is not automatically updated after each modification and will not reflect your change unless you explicitly tell Docker to build the image again.

Go inside the backend folder

bash
cd backend

Install the right dependencies

bash
npm install

Launch the app in development mode

bash
npm run dev

Lint

The linter finds variable that haven't been declared, unused imports, any usage of "any" (bad practice) etc.

bash
npm run lint

If the previous command yields error that it can easily fix without breaking changes, you can fix them

bash
npm run lint:fix

Format

The formatter (Prettier) changes the disposition of the code in the file (spacing, etc)

bash
npm run format

Build

Building transpiles your code into JavaScript code. It's good practice to test you haven't break the build from time to time.

bash
npm run build

Test

bash
npm run test