# sunbird-all/all-learner-ai-services architecture

> Architecture diagram of the GitHub repository sunbird-all/all-learner-ai-services, 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-learner-ai-services
- Repository: https://github.com/sunbird-all/all-learner-ai-services

## Overview

##### Project type and purpose
- This is a full-stack backend service built on NestJS (a Node.js/TypeScript framework) that exposes RESTful endpoints for managing “scores” and related data.
- It orchestrates data flows between API clients and three data stores (MongoDB, MySQL, Redis) and includes authentication, configuration, and caching layers.

##### File structure
- Top-level artifacts:
- Dockerfile & docker-compose.yml (defines containers for the app, MongoDB, MySQL, Redis)
- nest-cli.json, tsconfig.json/build (build configuration)
- .github/workflows/* (CI/CD pipelines)
- src/ modules:
- app.module.ts, app.controller.ts/service.ts (entry point & heartbeat)
- auth/ (AuthGuard, AuthModule for JWT/OAuth)
- config/ (environment-specific DB configs for MongoDB & MySQL)
- mongodb/ (cache service, language config, DTOs, Mongoose schemas, controllers/services for scores & logs)
- mysql/ (TypeORM Entities, DTOs, controllers/services for scores)
- redis/ (RedisModule for cache)
- test/ (unit & e2e tests)

##### README for insights
- Standard NestJS starter README: confirms use of NestJS CLI, modules, and standard commands.

##### Detail
- Sequence of a typical request (annotate steps 1–5).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Layer
    subgraph "API Layer"
        NG["NestJS App"]:::app
        AuthMod["AuthModule"]:::auth
        AuthGuard["AuthGuard"]:::auth
    end

    %% Business Layer
    subgraph "Business Layer"
        subgraph "MySQL Module"
            MyMod["mysql.module.ts"]:::mysql
            MYScoresCtl["scores.controller.ts"]:::mysql
            MYScoresSvc["scores.service.ts"]:::mysql
            ScoreEntity["score.entity.ts"]:::mysql
            CreateScoreDTO["create-score.dto.ts"]:::mysql
            UpdateScoreDTO["update-score.dto.ts"]:::mysql
        end
        subgraph "MongoDB Module"
            MongoMod["mongodb.module.ts"]:::mongo
            MongoScoresCtl["scores.controller.ts"]:::mongo
            MongoScoresSvc["scores.service.ts"]:::mongo
            Schemas["*.schema.ts"]:::mongo
            AssessmentDTO["AssessmentInput.dto.ts"]:::mongo
            LearnerDTO["CreateLearnerProfile.dto.ts"]:::mongo
            LangConfig["config/language/*.ts"]:::mongo
            MongoCache["cache.service.ts"]:::mongo
        end
        CacheMod["redis.module.ts"]:::redis
    end

    %% Config Module
    subgraph "Config Module"
        MongoCfg["mongodb.config.ts"]:::config
        MyCfg["mysql.config.ts"]:::config
    end

    %% Data Stores
    subgraph "Data Stores"
        MySQLDB["MySQL"]:::db
        MongoDB["MongoDB"]:::db
        RedisDB["Redis"]:::cachedb
    end

    %% CI/CD & Deployment
    subgraph "CI/CD & Deployment"
        GHDev["dev.yml"]:::ci
        GHStg["staging.yml"]:::ci
        GHProd["prod.yml"]:::ci
        GHProdRig["prod-test-rig.yml"]:::ci
        GH2Dev["2.0-dev.yml"]:::ci
        DockerFile["Dockerfile"]:::deploy
        DockerCompose["docker-compose.yml"]:::deploy
    end

    %% Relationships
    Client["External Client"]:::external -->|"HTTP/REST"| NG
    NG -->|"uses"| AuthMod
    NG -->|"applies"| AuthGuard
    AuthGuard -->|"guards"| MYScoresCtl
    AuthGuard -->|"guards"| MongoScoresCtl

    MYScoresCtl -->|"invoke"| MYScoresSvc
    MYScoresSvc -->|"TypeORM"| MyMod
    MyMod -->|"entity"| ScoreEntity
    MYScoresSvc -->|"cache-aside"| RedisDB
    RedisDB -->|"cache hits"| MYScoresSvc
    MYScoresSvc -->|"write/read"| MySQLDB

    MongoScoresCtl -->|"invoke"| MongoScoresSvc
    MongoScoresSvc -->|"Mongoose"| MongoMod
    MongoMod -->|"schema"| Schemas
    MongoMod -->|"uses DTOs"| AssessmentDTO
    MongoMod -->|"uses DTOs"| LearnerDTO
    MongoMod -->|"language config"| LangConfig
    MongoScoresSvc -->|"cache-aside"| MongoCache
    MongoCache -->|"cache hits"| MongoScoresSvc
    MongoScoresSvc -->|"write/read"| MongoDB

    CacheMod -->|"provides"| RedisDB

    MongoCfg -->|"injects"| MongoMod
    MyCfg -->|"injects"| MyMod

    DockerCompose -->|"orchestrates"| NG
    DockerCompose -->|"orchestrates"| MySQLDB
    DockerCompose -->|"orchestrates"| MongoDB
    DockerCompose -->|"orchestrates"| RedisDB
    DockerFile -->|"builds image"| DockerCompose

    GHDev -->|"pipeline"| DockerFile
    GHStg -->|"pipeline"| DockerFile
    GHProd -->|"pipeline"| DockerFile
    GHProdRig -->|"pipeline"| DockerFile
    GH2Dev -->|"pipeline"| DockerFile

    %% Click Events
    click NG "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/app.module.ts"
    click NG "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/main.ts"
    click NG "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/app.controller.ts"
    click NG "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/app.service.ts"

    click AuthMod "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/auth/auth.module.ts"
    click AuthGuard "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/auth/auth.guard.ts"

    click MongoCfg "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/config/mongodb.config.ts"
    click MyCfg "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/config/mysql.config.ts"

    click MyMod "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/mysql/mysql.module.ts"
    click MYScoresCtl "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/mysql/scores.controller.ts"
    click MYScoresSvc "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/mysql/scores.service.ts"
    click ScoreEntity "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/mysql/entities/score.entity.ts"
    click CreateScoreDTO "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/mysql/dto/create-score.dto.ts"
    click UpdateScoreDTO "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/mysql/dto/update-score.dto.ts"

    click MongoMod "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/mongodb/mongodb.module.ts"
    click MongoScoresCtl "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/mongodb/scores.controller.ts"
    click MongoScoresSvc "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/mongodb/scores.service.ts"
    click Schemas "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/mongodb/schemas/*.schema.ts"
    click AssessmentDTO "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/mongodb/dto/AssessmentInput.dto.ts"
    click LearnerDTO "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/mongodb/dto/CreateLearnerProfile.dto.ts"
    click LangConfig "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/mongodb/config/language/*.ts"
    click MongoCache "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/mongodb/cache/cache.service.ts"

    click CacheMod "https://github.com/sunbird-all/all-learner-ai-services/blob/main/src/redis/redis.module.ts"

    click GHDev "https://github.com/sunbird-all/all-learner-ai-services/blob/main/.github/workflows/dev.yml"
    click GHStg "https://github.com/sunbird-all/all-learner-ai-services/blob/main/.github/workflows/staging.yml"
    click GHProd "https://github.com/sunbird-all/all-learner-ai-services/blob/main/.github/workflows/prod.yml"
    click GHProdRig "https://github.com/sunbird-all/all-learner-ai-services/blob/main/.github/workflows/prod-test-rig.yml"
    click GH2Dev "https://github.com/sunbird-all/all-learner-ai-services/blob/main/.github/workflows/2.0-dev.yml"

    click DockerFile "https://github.com/sunbird-all/all-learner-ai-services/tree/main/Dockerfile"
    click DockerCompose "https://github.com/sunbird-all/all-learner-ai-services/blob/main/docker-compose.yml"

    %% Styles
    classDef app fill:#D0E8FF,stroke:#0366d6,stroke-width:2px
    classDef auth fill:#E8F0FE,stroke:#4A90E2,stroke-width:1.5px
    classDef mysql fill:#E2F5E9,stroke:#34A853,stroke-width:1.5px
    classDef mongo fill:#F0F4C3,stroke:#C0CA33,stroke-width:1.5px
    classDef redis fill:#FFF3E0,stroke:#FB8C00,stroke-width:1.5px
    classDef config fill:#ECEFF1,stroke:#607D8B,stroke-width:1px
    classDef db fill:#C8E6C9,stroke:#388E3C,stroke-width:2px
    classDef cachedb fill:#FFE0B2,stroke:#F57C00,stroke-width:2px
    classDef ci fill:#F5F5F5,stroke:#9E9E9E,stroke-width:1px
    classDef deploy fill:#FAFAFA,stroke:#BDBDBD,stroke-width:1px
    classDef external fill:#FFFFFF,stroke:#000000,stroke-width:1px
```
