# open-source-kigali/osk-backend architecture

> Architecture diagram of the GitHub repository open-source-kigali/osk-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/open-source-kigali/osk-backend
- Repository: https://github.com/open-source-kigali/osk-backend

## Overview

#### Purpose and runtime
This is the TypeScript/Express backend for the Open Source Kigali website. It exposes a REST API for community content and operations: members, contributors, projects, events, partners, partner applications, reviews, and aggregate stats. Node.js runs the compiled service; `src/server.ts` starts it and `src/app.ts` assembles the Express application.

#### HTTP composition and API contract
Routes are centralized and mounted through `src/routes/index.ts`, with feature routers such as `src/routes/event.routes.ts`, `src/routes/partner.routes.ts`, and `src/routes/partner-application.routes.ts`. Controllers form the HTTP boundary: they parse requests, invoke services, and return the standard response envelope via `src/utils/response.ts`. The published contract is `docs/openapi.yaml`, served as Swagger UI at `/api/docs`.

#### Domain service layer
Feature services contain business logic and persistence orchestration behind controllers. Major domains are:
- Events: `src/controllers/event.controller.ts`, `src/services/event.service.ts`
- Members: `src/controllers/member.controller.ts`, `src/services/member.service.ts`
- Projects and GitHub refresh: `src/controllers/project.controller.ts`, `src/services/project.service.ts`, `src/services/github.service.ts`
- Partners and applications: `src/controllers/partner.controllers.ts`, `src/services/partner.service.ts`, `src/services/partner-application.service.ts`
- Reviews and stats: `src/controllers/review.controller.ts`, `src/services/review.service.ts`, `src/services/stats.service.ts`

The principal flow is request → route → controller → service → Prisma/external provider → response.

#### Persistence and schema evolution
PostgreSQL is the system of record, accessed through Prisma. `prisma/schema.prisma` defines entities and relations, while `src/config/prisma.ts` owns the application Prisma client. Versioned SQL migrations in `prisma/migrations/` evolve the database, including partner/member/user-role/event, image, review, and partner-application capabilities. Local PostgreSQL infrastructure is provided by `docker-compose.yml`.

#### Security, validation, and failure boundaries
Environment loading and required operational settings are centralized in `src/config/env.ts`. Admin-only API operations are protected by shared-key middleware in `src/middlewares/auth.middleware.ts` using the `x-api-key`/`ADMIN_API_KEY` boundary. Request validation is expressed by domain schemas such as `src/schemas/event.schema.ts`, `src/schemas/member.schema.ts`, and `src/schemas/partner.schema.ts`. Unhandled and unknown-route paths terminate in `src/middlewares/error.middleware.ts` and `src/middlewares/not-found.middleware.ts`.

#### Media and external integrations
Uploads cross a distinct multipart boundary through `src/middlewares/upload.middleware.ts`, then use `src/utils/cloudinary-upload.ts` and `src/config/cloudinary.ts` to persist images in Cloudinary; database records retain image metadata/public IDs. GitHub is an external read dependency for project refresh and contributor profile enrichment through `src/services/github.service.ts` and `src/services/contributor.service.ts`. Contributor source data is repository-managed in `CONTRIBUTORS.md`.

#### Operational interfaces
The service is configured through `.env.example`, including database, CORS, admin-key, Cloudinary, and GitHub-token settings. It builds to `dist/` and runs on port 3000 by default. CI is defined in `.github/workflows/ci.yml`; tests use Vitest and cover selected controllers, services, and response behavior.

Main entry points: [`src/routes/event.routes.ts`](https://github.com/open-source-kigali/osk-backend/blob/dev/src/routes/event.routes.ts) (Feature routes), [`src/controllers/event.controller.ts`](https://github.com/open-source-kigali/osk-backend/blob/dev/src/controllers/event.controller.ts) (Controllers), [`src/config/prisma.ts`](https://github.com/open-source-kigali/osk-backend/blob/dev/src/config/prisma.ts) (Prisma client), [`src/app.ts`](https://github.com/open-source-kigali/osk-backend/blob/dev/src/app.ts) (Express app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_server["Service bootstrap<br/>Node/Express entry<br/>[server.ts]"]
  node_app["Express app<br/>application composition<br/>[app.ts]"]
  node_env["Environment settings<br/>configuration boundary<br/>[env.ts]"]
end

subgraph group_http["HTTP API"]
  node_routes["Route registry<br/>Express routers<br/>[index.ts]"]
  node_feature_routes["Feature routes<br/>event, partner, application routers<br/>[event.routes.ts]"]
  node_controllers["Controllers<br/>HTTP boundary"]
  node_validation["Request schemas<br/>validation<br/>[event.schema.ts]"]
  node_admin_auth["Admin key guard<br/>authentication middleware<br/>[auth.middleware.ts]"]
  node_upload["Multipart uploads<br/>upload middleware"]
  node_failure_handlers["Error and not-found handlers<br/>terminal middleware"]
  node_response["Response envelope<br/>response utility<br/>[response.ts]"]
  node_openapi["OpenAPI and Swagger UI<br/>published API contract<br/>[openapi.yaml]"]
end

subgraph group_domain["Domain services"]
  node_domain_services["Community services<br/>[event.service.ts]"]
  node_project_service["Project service<br/>project orchestration<br/>[project.service.ts]"]
  node_contributor_service["Contributor service<br/>contributor enrichment"]
end

subgraph group_data["Data and integrations"]
  node_github{{"GitHub integration<br/>external API client<br/>[github.service.ts]"}}
  node_prisma_client["Prisma client<br/>persistence adapter<br/>[prisma.ts]"]
  node_schema["Prisma schema and migrations<br/>data model evolution<br/>[schema.prisma]"]
  node_postgres[("PostgreSQL<br/>system of record<br/>[docker-compose.yml]")]
  node_cloudinary_upload["Cloudinary upload adapter<br/>media integration"]
  node_cloudinary{{"Cloudinary<br/>external media storage"}}
end

node_server -->|"starts"| node_app
node_env -.->|"configures"| node_server
node_app -->|"mounts"| node_routes
node_app -->|"terminates with"| node_failure_handlers
node_routes -->|"registers"| node_feature_routes
node_feature_routes -->|"validates with"| node_validation
node_feature_routes -->|"guards admin routes"| node_admin_auth
node_feature_routes -->|"accepts multipart through"| node_upload
node_feature_routes -->|"dispatches to"| node_controllers
node_controllers -->|"invokes"| node_domain_services
node_controllers -->|"invokes"| node_project_service
node_controllers -->|"invokes"| node_contributor_service
node_controllers -->|"formats via"| node_response
node_domain_services -->|"persists through"| node_prisma_client
node_project_service -->|"persists through"| node_prisma_client
node_contributor_service -->|"persists through"| node_prisma_client
node_project_service -->|"refreshes from"| node_github
node_contributor_service -->|"enriches from"| node_github
node_upload -->|"forwards files to"| node_cloudinary_upload
node_cloudinary_upload -->|"stores media in"| node_cloudinary
node_domain_services -.->|"records upload metadata"| node_cloudinary_upload
node_prisma_client -->|"queries"| node_postgres
node_schema -->|"defines and migrates"| node_postgres
node_openapi -.->|"documents"| node_routes

click node_server "https://github.com/open-source-kigali/osk-backend/blob/dev/src/server.ts"
click node_app "https://github.com/open-source-kigali/osk-backend/blob/dev/src/app.ts"
click node_env "https://github.com/open-source-kigali/osk-backend/blob/dev/src/config/env.ts"
click node_routes "https://github.com/open-source-kigali/osk-backend/blob/dev/src/routes/index.ts"
click node_feature_routes "https://github.com/open-source-kigali/osk-backend/blob/dev/src/routes/event.routes.ts"
click node_controllers "https://github.com/open-source-kigali/osk-backend/blob/dev/src/controllers/event.controller.ts"
click node_validation "https://github.com/open-source-kigali/osk-backend/blob/dev/src/schemas/event.schema.ts"
click node_admin_auth "https://github.com/open-source-kigali/osk-backend/blob/dev/src/middlewares/auth.middleware.ts"
click node_upload "https://github.com/open-source-kigali/osk-backend/blob/dev/src/middlewares/upload.middleware.ts"
click node_failure_handlers "https://github.com/open-source-kigali/osk-backend/blob/dev/src/middlewares/error.middleware.ts"
click node_response "https://github.com/open-source-kigali/osk-backend/blob/dev/src/utils/response.ts"
click node_domain_services "https://github.com/open-source-kigali/osk-backend/blob/dev/src/services/event.service.ts"
click node_project_service "https://github.com/open-source-kigali/osk-backend/blob/dev/src/services/project.service.ts"
click node_contributor_service "https://github.com/open-source-kigali/osk-backend/blob/dev/src/services/contributor.service.ts"
click node_github "https://github.com/open-source-kigali/osk-backend/blob/dev/src/services/github.service.ts"
click node_prisma_client "https://github.com/open-source-kigali/osk-backend/blob/dev/src/config/prisma.ts"
click node_schema "https://github.com/open-source-kigali/osk-backend/blob/dev/prisma/schema.prisma"
click node_postgres "https://github.com/open-source-kigali/osk-backend/blob/dev/docker-compose.yml"
click node_cloudinary_upload "https://github.com/open-source-kigali/osk-backend/blob/dev/src/utils/cloudinary-upload.ts"
click node_openapi "https://github.com/open-source-kigali/osk-backend/blob/dev/docs/openapi.yaml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_server,node_app,node_env toneBlue
class node_routes,node_feature_routes,node_controllers,node_validation,node_admin_auth,node_upload,node_failure_handlers,node_response,node_openapi toneAmber
class node_domain_services,node_project_service,node_contributor_service toneMint
class node_github,node_prisma_client,node_schema,node_postgres,node_cloudinary_upload,node_cloudinary toneRose
```

## Components

### Runtime

- [Service bootstrap](https://github.com/open-source-kigali/osk-backend/blob/dev/src/server.ts): Node/Express entry · Starts the compiled service on its configured port. · `src/server.ts`
- [Express app](https://github.com/open-source-kigali/osk-backend/blob/dev/src/app.ts): application composition · Assembles middleware, routes, and terminal handlers. · `src/app.ts`
- [Environment settings](https://github.com/open-source-kigali/osk-backend/blob/dev/src/config/env.ts): configuration boundary · Loads required operational settings. · `src/config/env.ts`

### HTTP API

- [Route registry](https://github.com/open-source-kigali/osk-backend/blob/dev/src/routes/index.ts): Express routers · Mounts feature routers under the API. · `src/routes/index.ts`
- [Feature routes](https://github.com/open-source-kigali/osk-backend/blob/dev/src/routes/event.routes.ts): event, partner, application routers · Declare resource endpoints and middleware chains. · `src/routes/event.routes.ts`
- [Controllers](https://github.com/open-source-kigali/osk-backend/blob/dev/src/controllers/event.controller.ts): HTTP boundary · Parse requests, invoke services, and return API responses. · `src/controllers/event.controller.ts`
- [Request schemas](https://github.com/open-source-kigali/osk-backend/blob/dev/src/schemas/event.schema.ts): validation · Validate domain request payloads before controller handling. · `src/schemas/event.schema.ts`
- [Admin key guard](https://github.com/open-source-kigali/osk-backend/blob/dev/src/middlewares/auth.middleware.ts): authentication middleware · Protects admin operations using x-api-key and ADMIN_API_KEY. · `src/middlewares/auth.middleware.ts`
- [Multipart uploads](https://github.com/open-source-kigali/osk-backend/blob/dev/src/middlewares/upload.middleware.ts): upload middleware · Crosses the multipart boundary for image-bearing requests. · `src/middlewares/upload.middleware.ts`
- [Error and not-found handlers](https://github.com/open-source-kigali/osk-backend/blob/dev/src/middlewares/error.middleware.ts): terminal middleware · Terminates unknown routes and unhandled failures. · `src/middlewares/error.middleware.ts`
- [Response envelope](https://github.com/open-source-kigali/osk-backend/blob/dev/src/utils/response.ts): response utility · Produces the standard API response format. · `src/utils/response.ts`
- [OpenAPI and Swagger UI](https://github.com/open-source-kigali/osk-backend/blob/dev/docs/openapi.yaml): published API contract · Documents the API served at /api/docs. · `docs/openapi.yaml`

### Domain services

- [Community services](https://github.com/open-source-kigali/osk-backend/blob/dev/src/services/event.service.ts): event, member, partner, review services · Own business logic and persistence orchestration. · `src/services/event.service.ts`
- [Project service](https://github.com/open-source-kigali/osk-backend/blob/dev/src/services/project.service.ts): project orchestration · Manages projects and coordinates GitHub refresh. · `src/services/project.service.ts`
- [Contributor service](https://github.com/open-source-kigali/osk-backend/blob/dev/src/services/contributor.service.ts): contributor enrichment · Enriches contributor profiles from GitHub data. · `src/services/contributor.service.ts`

### Data and integrations

- [GitHub integration](https://github.com/open-source-kigali/osk-backend/blob/dev/src/services/github.service.ts): external API client · Reads project and contributor data from GitHub. · `src/services/github.service.ts`
- [Prisma client](https://github.com/open-source-kigali/osk-backend/blob/dev/src/config/prisma.ts): persistence adapter · Application-owned client for database access. · `src/config/prisma.ts`
- [Prisma schema and migrations](https://github.com/open-source-kigali/osk-backend/blob/dev/prisma/schema.prisma): data model evolution · Defines PostgreSQL entities and versioned schema changes. · `prisma/schema.prisma`
- [PostgreSQL](https://github.com/open-source-kigali/osk-backend/blob/dev/docker-compose.yml): system of record · Stores community content, operations, and image metadata. · `docker-compose.yml`
- [Cloudinary upload adapter](https://github.com/open-source-kigali/osk-backend/blob/dev/src/utils/cloudinary-upload.ts): media integration · Persists uploaded images and returns media identifiers. · `src/utils/cloudinary-upload.ts`
- **Cloudinary**: external media storage

## Connections

- Service bootstrap → Express app: starts
- Environment settings → Service bootstrap: configures
- Express app → Route registry: mounts
- Express app → Error and not-found handlers: terminates with
- Route registry → Feature routes: registers
- Feature routes → Request schemas: validates with
- Feature routes → Admin key guard: guards admin routes
- Feature routes → Multipart uploads: accepts multipart through
- Feature routes → Controllers: dispatches to
- Controllers → Community services: invokes
- Controllers → Project service: invokes
- Controllers → Contributor service: invokes
- Controllers → Response envelope: formats via
- Community services → Prisma client: persists through
- Project service → Prisma client: persists through
- Contributor service → Prisma client: persists through
- Project service → GitHub integration: refreshes from
- Contributor service → GitHub integration: enriches from
- Multipart uploads → Cloudinary upload adapter: forwards files to
- Cloudinary upload adapter → Cloudinary: stores media in
- Community services → Cloudinary upload adapter: records upload metadata
- Prisma client → PostgreSQL: queries
- Prisma schema and migrations → PostgreSQL: defines and migrates
- OpenAPI and Swagger UI → Route registry: documents
