Table of Contents
Table of Contents
Here is the core API that powers c3pm. It contains a GraphQL API meant to be used by the web application, and a few REST endpoints meant to be used by the CLI. It is built with Node.js using the TypeScript language.
To deploy the application locally, you will need to have installed Node.js, Docker, and Direnv
First, setup your environment. If some variables are missing, ask your manager.
cp .envrc.example .envrc
direnv allow
Start the PostgreSQL container:
docker run \
--name c3pm-db \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_USER=postgres \
-p 5432:5432 \
-d \
postgres
Install the dependencies:
npm install
Apply the migrations to the database and start the dev server:
npx prisma migrate up --experimental
You should now have the GraphQL Playground available at http://localhost:4000/graphql/
To interact with the database directly you can start the Prisma Studio:
npx prisma studio --experimental
Make sure the environment variables are correctly set, then build and start the application:
npm ci
npm run build
npm start
The application will not start until all the environment variables are set.
To improve readability and maintainability, there is a clear separation between the data access, the core business logic, and the transport layer.
The data access is generated by Prisma. You can edit the
prisma/schema.prisma
file to modify the database.
⚠️ : every modification in theschema.prisma
must be followed by the creation of a new migration step:npx prisma migrate save --experimental
The business logic lives in the services. A service is a class
which extends the Service
class. It has access to the db
and
the session
.
The transport layer is responsible for the transfer of the response
of a service to the end user. For example, the src/graphql
directory contains all the code relative to the GraphQL API. To
create a new GraphQL type, add a file in src/graphql/types
and
export it in src/graphql/index.ts
. To add a new query or
mutation, add a field
in the Query
or Mutation
module.