# Backend Infra Introduction ## CI/CD flow ```mermaid flowchart TD; GitLab(GitLab)-->|1. Webhook Trigger|Build(Cloud Build) GitLab-->|2. Clone|Build subgraph Build [Cloud Build] Build-Clone(1. Clone the target branch)-->Build-Checkout(2. Checkout to the target commit) Build-Checkout-->Build-Build(3. Build docker image) Build-Build-->Build-Push(4. Push to Artifact Registry) Build-Push-->|Is develop branch|Build-DeployDevDB Build-Push-->|Is master branch|Build-DeployProdDB Build-DeployDevDB(5. Migrate dev DB with Prisma)-->Build-DeployDevServ(6. Deploy dev service) Build-DeployProdDB(5. Migrate prod DB with Prisma)-->Build-DeployProdServ(6. Deploy prod service) end Build-->|3. Push docker image|Artifact(Artifact Registry) Build-->|4. Deploy|Run Artifact-->|5. Pull latest image|Run(Cloud Run) ``` > GitLab Webhook Setting > https://gitlab.com/elkroom/backend/oxo_game_service/-/hooks > Cloud Build Setting Page > https://console.cloud.google.com/cloud-build/triggers?project=oxo-backend ## Project ## Tech Stack - TypeScript - Fastify - Prisma - PostgreSQL ### Project Structure ```mermaid flowchart LR; Router(Router)-->Controller(Controller)-->Service(Service) ``` - src - api - ***.schema.ts:** API schemas. It will be used by Swagger to generate API docs, and [Ajv](https://ajv.js.org/) to validate all request and response - ***.type.ts**: [TypeBox](https://github.com/sinclairzx81/typebox) declaration, for declaring schema's type - ***.request.ts:** interface which extend `FastifyRequest` - **firebase:** code that related to Firebase - plugin - **auth.ts:** fastify plugin that declare the auth functions - **jwt.ts:** plugin for JWT verifying - **env.ts:** plugin for setting environment variables - **helmet.ts:** plugin for auto-add important security headers - **swagger.ts:** plugin for setup Swagger by the schemas - util - **error:** place to declare HTTP exception, such as 404 not found. ### Tools - pnpm - Fast, disk space efficient package manager - ESLint - A linter for JS/TS, and it could be fully customized with its configuration file(`.eslintrc`).