# sunbird-all/all-content-service architecture

> Architecture diagram of the GitHub repository sunbird-all/all-content-service, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sunbird-all/all-content-service
- Repository: https://github.com/sunbird-all/all-content-service

## Overview

##### Project type and purpose
- This is a monolithic backend REST‐API service built with NestJS (a Node.js/TypeScript framework).
- It exposes “collections” and “content” endpoints, uses schema definitions (likely Mongoose) to persist data, supports clustering for CPU scaling, and contains static language content assets.
- The presence of Dockerfile, docker-compose.yml, deploy.sh, and multiple GitHub Actions workflows indicates containerized deployment and CI/CD pipelines.

##### File structure
- Top-level:
- Dockerfile, docker-compose.yml, deploy.sh → container build & local orchestration
- .github/workflows/*.yml → CI/CD definitions
- src/ → application code
- Language content/ → static data assets (Excel, text files)
- src/ structure follows Nest conventions:
- main.ts → application entry point
- app-cluster.service.ts → spawns Node.js worker processes
- controllers/ → HTTP handlers (collection.controller.ts, content.controller.ts)
- services/ → business logic (collection.service.ts, content.service.ts)
- schemas/ → data models (collection.schema.ts, content.schema.ts)
- config/ → configuration modules (commonConfig, language files by locale)

##### README
- Confirms NestJS starter repo, outlines install/run/test commands.

a. Main components
- External clients (e.g., UI, mobile apps, API consumers)
- HTTP Load Balancer / Cluster Manager (Node’s cluster service)
- NestJS Application Process(es)
- Module: AppModule
- Submodules: CollectionModule, ContentModule, ConfigModule
- Controllers → Services → Schemas
- Database (e.g., MongoDB)
- Static File Store (Language content directory)
- CI/CD Pipeline & Container Registry
- Deployment Environment (e.g., Docker Swarm, Kubernetes, or plain Docker Compose)
b. Relationships and interactions
- Clients → HTTP Load Balancer → NestJS Worker Process
- Worker Process:
– Controllers receive requests
– Controllers call Services
– Services access Database via Schemas
– Services read static files from Language content on disk
- Cluster Manager evenly distributes requests across worker processes
- CI/CD pipelines build Docker image → push to registry → deploy via docker-compose or cloud
c. Architectural patterns / design principles
- Layered architecture (Controller → Service → Data Model)
- Dependency Injection (Nest’s providers and modules)
- High availability & horizontal scaling via Node.js clustering
- Configuration managed via environment‐aware modules (commonConfig + locale files)
- Containerization and infrastructure as code (Dockerfile & docker-compose.yml)
d. Key technologies / frameworks / libraries
- NestJS / Node.js / TypeScript
- Mongoose (implied by *.schema.ts)
- Docker / Docker Compose
- GitHub Actions (CI/CD)
- Optional: Nginx or cloud load balancer in front of containers

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients Layer
    Clients["External Clients\n(UI/Mobile/API)"]:::external

    %% Load Balancing & Clustering
    Clients -->|HTTP Request| LoadBalancer["HTTP Load Balancer"]:::infra
    LoadBalancer --> ClusterManager["Cluster Manager\n(AppClusterService)"]:::app
    click ClusterManager "https://github.com/sunbird-all/all-content-service/blob/main/src/app-cluster.service.ts"

    %% Application Layer
    subgraph Application Processes
        direction TB
        Worker["NestJS Worker Process"]:::app
        Worker --> AppModule["AppModule"]:::app
        click AppModule "https://github.com/sunbird-all/all-content-service/blob/main/src/app.module.ts"

        AppModule --> AppController["AppController"]:::app
        click AppController "https://github.com/sunbird-all/all-content-service/blob/main/src/app.controller.ts"
        AppModule --> AppService["AppService"]:::app
        click AppService "https://github.com/sunbird-all/all-content-service/blob/main/src/app.service.ts"

        %% Collection Module
        AppModule --> CollectionModule["CollectionModule"]:::app
        subgraph "CollectionModule"
            direction TB
            CollectionController["CollectionController"]:::app
            click CollectionController "https://github.com/sunbird-all/all-content-service/blob/main/src/controllers/collection.controller.ts"
            CollectionService["CollectionService"]:::app
            click CollectionService "https://github.com/sunbird-all/all-content-service/blob/main/src/services/collection.service.ts"
            CollectionSchema["CollectionSchema"]:::datastore
            click CollectionSchema "https://github.com/sunbird-all/all-content-service/blob/main/src/schemas/collection.schema.ts"
            CollectionController --> CollectionService
            CollectionService --> CollectionSchema
            CollectionService --> MongoDB
        end

        %% Content Module
        AppModule --> ContentModule["ContentModule"]:::app
        subgraph "ContentModule"
            direction TB
            ContentController["ContentController"]:::app
            click ContentController "https://github.com/sunbird-all/all-content-service/blob/main/src/controllers/content.controller.ts"
            ContentService["ContentService"]:::app
            click ContentService "https://github.com/sunbird-all/all-content-service/blob/main/src/services/content.service.ts"
            ContentSchema["ContentSchema"]:::datastore
            click ContentSchema "https://github.com/sunbird-all/all-content-service/blob/main/src/schemas/content.schema.ts"
            ContentController --> ContentService
            ContentService --> ContentSchema
            ContentService --> MongoDB
            ContentService --> FileStore
        end

        %% Configuration Module
        AppModule --> ConfigModule["ConfigModule"]:::app
        subgraph "ConfigModule"
            direction TB
            CommonConfig["commonConfig"]:::app
            click CommonConfig "https://github.com/sunbird-all/all-content-service/blob/main/src/config/commonConfig.ts"
            Lang_en["en.ts"]:::app
            click Lang_en "https://github.com/sunbird-all/all-content-service/blob/main/src/config/language/en.ts"
            Lang_hi["hi.ts"]:::app
            click Lang_hi "https://github.com/sunbird-all/all-content-service/blob/main/src/config/language/hi.ts"
            Lang_kn["kn.ts"]:::app
            click Lang_kn "https://github.com/sunbird-all/all-content-service/blob/main/src/config/language/kn.ts"
            Lang_ta["ta.ts"]:::app
            click Lang_ta "https://github.com/sunbird-all/all-content-service/blob/main/src/config/language/ta.ts"
            Lang_te["te.ts"]:::app
            click Lang_te "https://github.com/sunbird-all/all-content-service/blob/main/src/config/language/te.ts"
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        MongoDB["MongoDB"]:::datastore
        FileStore["Static Language Assets\n(Language content/)"]:::datastore
        click FileStore "https://github.com/sunbird-all/all-content-service/tree/main/Language content/"
    end

    %% CI/CD & Deployment
    subgraph "CI/CD & Deployment"
        direction TB
        Repo["Code Repository"]:::infra
        Actions["GitHub Actions\n(.github/workflows)"]:::infra
        click Actions "https://github.com/sunbird-all/all-content-service/tree/main/.github/workflows/"
        DockerBuild["Docker Build\n(Dockerfile)"]:::infra
        click DockerBuild "https://github.com/sunbird-all/all-content-service/tree/main/Dockerfile"
        Compose["Docker Compose\n(docker-compose.yml)"]:::infra
        click Compose "https://github.com/sunbird-all/all-content-service/blob/main/docker-compose.yml"
        DeployScript["Deployment Script\n(deploy.sh)"]:::infra
        click DeployScript "https://github.com/sunbird-all/all-content-service/blob/main/deploy.sh"
        Repo --> Actions --> DockerBuild --> Compose --> DeployScript
    end

    %% End-to-End Tests & Config
    subgraph "Testing & Config"
        direction TB
        E2E["E2E Tests\n(test/app.e2e-spec.ts)"]:::infra
        click E2E "https://github.com/sunbird-all/all-content-service/blob/main/test/app.e2e-spec.ts"
        JestConfig["Jest Config\n(test/jest-e2e.json)"]:::infra
        click JestConfig "https://github.com/sunbird-all/all-content-service/blob/main/test/jest-e2e.json"
        NestCLI["Nest CLI Config\n(nest-cli.json)"]:::infra
        click NestCLI "https://github.com/sunbird-all/all-content-service/blob/main/nest-cli.json"
        TSConfig["tsconfig.json"]:::infra
        click TSConfig "https://github.com/sunbird-all/all-content-service/blob/main/tsconfig.json"
        TSBuild["tsconfig.build.json"]:::infra
        click TSBuild "https://github.com/sunbird-all/all-content-service/blob/main/tsconfig.build.json"
        PackageJSON["package.json"]:::infra
        click PackageJSON "https://github.com/sunbird-all/all-content-service/blob/main/package.json"
        PackageLock["package-lock.json"]:::infra
        click PackageLock "https://github.com/sunbird-all/all-content-service/blob/main/package-lock.json"
    end

    %% Flows
    LoadBalancer --> Worker
    AppController --> AppService
    AppService --> MongoDB
    AppService --> FileStore

    %% Styles
    classDef app fill:#D6EAF8,stroke:#1B4F72,color:#1B2631
    classDef datastore fill:#D5F5E3,stroke:#145A32,color:#0B5345
    classDef infra fill:#FCF3CF,stroke:#7D6608,color:#784212
    classDef external fill:#FADBD8,stroke:#922B21,color:#641E16
```
