How open-source-kigali/osk-backend works
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: event.routes.ts Feature routes · event.controller.ts Controllers · prisma.ts Prisma client · app.ts Express app
Components 21
Runtime
- Service bootstrap · Starts the compiled service on its configured port.
src/server.ts - Express app · Assembles middleware, routes, and terminal handlers.
src/app.ts - Environment settings · Loads required operational settings.
src/config/env.ts
HTTP API
- Route registry · Mounts feature routers under the API.
src/routes/index.ts - Feature routes · Declare resource endpoints and middleware chains.
src/routes/event.routes.ts - Controllers · Parse requests, invoke services, and return API responses.
src/controllers/event.controller.ts - Request schemas · Validate domain request payloads before controller handling.
src/schemas/event.schema.ts - Admin key guard · Protects admin operations using x-api-key and ADMIN_API_KEY.
src/middlewares/auth.middleware.ts - Multipart uploads · Crosses the multipart boundary for image-bearing requests.
src/middlewares/upload.middleware.ts - Error and not-found handlers · Terminates unknown routes and unhandled failures.
src/middlewares/error.middleware.ts - Response envelope · Produces the standard API response format.
src/utils/response.ts - OpenAPI and Swagger UI · Documents the API served at /api/docs.
docs/openapi.yaml
Domain services
- Community services · Own business logic and persistence orchestration.
src/services/event.service.ts - Project service · Manages projects and coordinates GitHub refresh.
src/services/project.service.ts - Contributor service · Enriches contributor profiles from GitHub data.
src/services/contributor.service.ts
Data and integrations
- GitHub integration · Reads project and contributor data from GitHub.
src/services/github.service.ts - Prisma client · Application-owned client for database access.
src/config/prisma.ts - Prisma schema and migrations · Defines PostgreSQL entities and versioned schema changes.
prisma/schema.prisma - PostgreSQL · Stores community content, operations, and image metadata.
docker-compose.yml - Cloudinary upload adapter · Persists uploaded images and returns media identifiers.
src/utils/cloudinary-upload.ts - Cloudinary
Connections 24
- 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