# cylab-africa/rri_backend architecture

> Architecture diagram of the GitHub repository cylab-africa/rri_backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cylab-africa/rri_backend
- Repository: https://github.com/cylab-africa/rri_backend

## Overview

##### Main Components of the System
- Backend Application:
- Entry point (index.js) that initializes the Node.js server.
- Controllers (located under src/controllers) that handle various request routes (e.g., authController.js, evaluationControllers.js, testController.js).
- Middleware (under src/middleware) to manage pre-processing of requests, such as authorization.
- Utility functions (under src/utilities), e.g., for generating tokens, adding questions, or calculating scores.
- An “auth” module (the separate auth directory) that likely provides additional authentication logic.
- Database:
- Postgres database as described in the README (with a database named “test”).
- Prisma configuration (located under src/db/configs/prisma), providing schema definitions and migrations that set up your database structure.
- Testing Infrastructure:
- Jest configuration and test files (e.g., src/jest.config.js, src/jest.setup.js, and tests in src/utilities/tests).
- Deployment & DevOps:
- Dockerfile and .dockerignore indicate containerization.
- Kubernetes-deployment.yml and files under .github/workflows suggest automated CI/CD and orchestration.

##### Relationships and Interactions
- The Node.js server (index.js) receives HTTP requests which are routed to the appropriate controllers.
- Controllers call middleware functions (such as authorization) before proceeding to process requests.
- After processing, the controllers interact with the database through Prisma (using the schema defined under src/db/configs/prisma).
- Utility functions support all these layers with shared functionality (e.g., token generation for auth or question initialization for database seeding).
- External setup scripts like init.sql and addQuestions.js indicate methods to initialize the database.
- On the deployment side, Docker and Kubernetes components ensure the service can be containerized and orchestrated in production.

##### Architectural Patterns & Key Technologies
- The project reflects a modular Node.js backend (likely using an MVC-like structure, where controllers, middleware, and utilities are separated).
- Use of Prisma ORM bridges the interaction with the PostgreSQL database.
- Testing and configuration files denote adherence to modern development practices (Jest for testing; CI/CD with GitHub Actions).
- Containerization (Docker) and orchestration (Kubernetes) are used to manage deployment and scalability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Component
    F("RRI_frontend (Client)"):::frontend

    %% Backend Service Subgraph
    subgraph "Backend Service (Node.js)"
        EP("index.js (Entry point)"):::backend
        Ctrl("Controllers (authController, evaluationControllers, testController)"):::controllers
        MW("authorization.js (Middleware)"):::middleware
        Util("Utilities (token, questions, etc.)"):::utilities
        Auth("auth.js (Authentication Module)"):::module
        %% Database Integration inside Backend
        Prisma("Prisma ORM & Migrations"):::database
        DB("PostgreSQL Database"):::database

        EP --> Ctrl
        Ctrl --> MW
        Ctrl --> Util
        Ctrl --> Auth
        Ctrl -->|"prisma"| Prisma
        Prisma --> DB
    end

    %% Frontend to Backend flow
    F --> EP

    %% Testing Infrastructure Subgraph
    subgraph "Testing Infrastructure"
        JestC("Jest Config"):::testing
        JestS("Jest Setup"):::testing
        JestTests("Utility Tests"):::testing
    end
    %% Indicate that controllers are validated by tests
    Ctrl ---|"tested_with"| JestTests

    %% Deployment & DevOps Subgraph
    subgraph "Deployment & DevOps"
        GH("GitHub Actions"):::devops
        Docker("Docker Container"):::devops
        K8s("Kubernetes Orchestrator"):::devops
    end
    GH --> Docker
    Docker --> K8s

    %% Click Events
    click EP "https://github.com/cylab-africa/rri_backend/blob/main/index.js"
    click Ctrl "https://github.com/cylab-africa/rri_backend/tree/main/src/controllers"
    click MW "https://github.com/cylab-africa/rri_backend/blob/main/src/middleware/authorization.js"
    click Util "https://github.com/cylab-africa/rri_backend/tree/main/src/utilities"
    click Auth "https://github.com/cylab-africa/rri_backend/blob/main/auth/auth.js"
    click Prisma "https://github.com/cylab-africa/rri_backend/tree/main/src/db/configs/prisma"
    click JestC "https://github.com/cylab-africa/rri_backend/blob/main/src/jest.config.js"
    click JestS "https://github.com/cylab-africa/rri_backend/blob/main/src/jest.setup.js"
    click JestTests "https://github.com/cylab-africa/rri_backend/tree/main/src/utilities/tests"
    click Docker "https://github.com/cylab-africa/rri_backend/tree/main/Dockerfile"
    click K8s "https://github.com/cylab-africa/rri_backend/blob/main/Kubernetes-deployment.yml"
    click GH "https://github.com/cylab-africa/rri_backend/blob/main/.github/workflows/main.yaml"

    %% Styling Classes
    classDef frontend fill:#F4A460,stroke:#000,stroke-width:1px;
    classDef backend fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef controllers fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef middleware fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef utilities fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef module fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef database fill:#F08080,stroke:#000,stroke-width:1px;
    classDef testing fill:#DDA0DD,stroke:#000,stroke-width:1px;
    classDef devops fill:#87CEFA,stroke:#000,stroke-width:1px;
```
