# vishnuvinay89/all-saas-learner-ai-services architecture

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

## Overview

##### Project type and purpose
- This is a NestJS-based, server-side TypeScript application acting as a REST API backend.
- It’s structured as a modular monolith: two domain modules (MongoDB and MySQL), both exposing “scores” endpoints plus shared configuration and caching.
- The project is containerized via Docker/Docker-Compose and tested with Jest (unit and e2e).

##### File structure
- Top-level:
- Dockerfile & docker-compose.yml – container definitions and multi-container orchestration (app, MongoDB, MySQL).
- nest-cli.json, tsconfig*.json – Nest/TypeScript build configs.
- .github/workflows – CI pipelines for dev/prod.
- src/:
- app.module.ts, main.ts – Nest entry point and root module.
- config/ – abstraction of environment-driven DB connection configs.
- mongodb/ – module for MongoDB: schemas (Mongoose), DTOs, controller, service, plus caching submodule.
- mysql/ – module for MySQL: entities (TypeORM), DTOs, controller, service.
- test/ – end-to-end tests and Jest config.

##### README for additional insights
- Technology stack: Node.js, NestJS, Mongoose, TypeORM, Docker.

a. Main components
- Client / API consumer (e.g., frontend or Postman)
- NestJS Application
– HTTP Server (Express under the hood)
– AppModule (root)
- ConfigModule (env config for MongoDB + MySQL)
- MongoModule
– Mongoose schemas (assessmentInput, scores, logs, mapping)
– CacheService (in-Mongo caching)
– ScoresController & ScoresService
- MySQLModule
– TypeORM entities (score)
– ScoresController & ScoresService
- External resources
– MongoDB instance (container)
– MySQL instance (container)
b. Relationships & interactions
- Client → HTTP Server → Controllers
- Controllers → Services → Database adapters (Mongoose or TypeORM)
- Services use ConfigModule for connection settings
- CacheService used by Mongo services for temporary storage
- Docker-Compose glues Nest app, MongoDB, MySQL in one network
c. Architectural patterns & design principles
- Modularization (Nest Modules) separating domain concerns (Mongo vs. MySQL)
- Dependency Injection (services injected into controllers, config injected into modules)
- Repository pattern via Mongoose models & TypeORM repositories
- 12-factor principles: config via env, containerization
d. Key technologies & libraries
- NestJS (modules, controllers, providers)
- Mongoose (MongoModule, schemas, DTOs)
- TypeORM (entities, repositories)
- Docker & Docker-Compose
- Jest for unit/e2e testing
- GitHub Actions (.github/workflows) for CI

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    Client["API Client (Postman/Frontend)"]:::external

    %% Docker Compose orchestration
    subgraph "Docker Compose" 
        direction TB
        ComposeApp["Nest App Container"]:::infra
        ComposeMongo["MongoDB Container"]:::db
        ComposeMySQL["MySQL Container"]:::db
    end

    %% NestJS Application
    subgraph "NestJS Application" 
        direction TB
        HTTP["HTTP Server (Express)"]:::code
        HTTP --> AppModule
        AppModule["AppModule"]:::code
        AppModule --> ConfigModule
        AppModule --> MongoModule
        AppModule --> MySQLModule

        ConfigModule["ConfigModule"]:::code

        subgraph "MongoModule" 
            direction TB
            MCtrl["ScoresController"]:::code
            MServ["ScoresService"]:::code
            MServ --> MongoDB
            MCtrl --> MServ
            DTO1["AssessmentInput DTO"]:::code
            DTO2["CreateLearnerProfile DTO"]:::code
            Schemas["Mongoose Schemas"]:::code
            Schemas -->|uses| DTO1
            Schemas -->|uses| DTO2
            Cache["CacheService"]:::code
            MServ -->|caching| Cache
        end

        subgraph "MySQLModule" 
            direction TB
            SCtrl["ScoresController"]:::code
            SServ["ScoresService"]:::code
            SServ --> MySQL
            SCtrl --> SServ
            DTO3["CreateScore DTO"]:::code
            DTO4["UpdateScore DTO"]:::code
            Entity["Score Entity"]:::code
            SServ -->|queries| Entity
        end
    end

    %% External Databases
    MongoDB[("MongoDB")]:::db
    MySQL[("MySQL")]:::db

    %% Testing
    subgraph "E2E Testing" 
        direction TB
        E2E["Jest E2E Runner"]:::test
        E2E --> ComposeApp
    end

    %% CI/CD
    subgraph "CI/CD (GitHub Actions)" 
        direction TB
        DevWF["Dev Workflow"]:::infra
        ProdWF["Prod Workflow"]:::infra
    end

    %% Flows
    Client -->|POST /scores| HTTP
    ConfigModule -->|env vars| MongoModule
    ConfigModule -->|env vars| MySQLModule
    ComposeApp -->|connects| ComposeMongo
    ComposeApp -->|connects| ComposeMySQL

    %% Click Events
    click Dockerfile "https://github.com/vishnuvinay89/all-saas-learner-ai-services/tree/main/Dockerfile"
    click Compose "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/docker-compose.yml"
    click DevWF "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/.github/workflows/dev.yml"
    click ProdWF "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/.github/workflows/prod.yml"
    click Main "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/main.ts"
    click AppModule "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/app.module.ts"
    click AppCtrl "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/app.controller.ts"
    click AppCtrlSpec "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/app.controller.spec.ts"
    click AppService "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/app.service.ts"
    click AppClusterService "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/app-cluster.service.ts"
    click MongoConfig "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/config/mongodb.config.ts"
    click MySQLConfig "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/config/mysql.config.ts"
    click MongoModule "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mongodb/mongodb.module.ts"
    click MCtrl "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mongodb/scores.controller.ts"
    click MCtrlSpec "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mongodb/scores.controller.spec.ts"
    click MServ "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mongodb/scores.service.ts"
    click MServSpec "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mongodb/scores.service.spec.ts"
    click DTO1 "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mongodb/dto/AssessmentInput.dto.ts"
    click DTO2 "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mongodb/dto/CreateLearnerProfile.dto.ts"
    click Schemas "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mongodb/schemas/assessmentInput.schema.ts"
    click Schemas "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mongodb/schemas/denoiserOutputLogs.schema.ts"
    click Schemas "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mongodb/schemas/hexcodeMapping.schema.ts"
    click Schemas "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mongodb/schemas/scores.schema.ts"
    click Cache "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mongodb/cache/cache.service.ts"
    click MySQLModule "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mysql/mysql.module.ts"
    click SCtrl "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mysql/scores.controller.ts"
    click SCtrlSpec "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mysql/scores.controller.spec.ts"
    click SServ "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mysql/scores.service.ts"
    click SServSpec "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mysql/scores.service.spec.ts"
    click DTO3 "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mysql/dto/create-score.dto.ts"
    click DTO4 "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mysql/dto/update-score.dto.ts"
    click Entity "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/src/mysql/entities/score.entity.ts"
    click E2E "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/test/app.e2e-spec.ts"
    click JestE2E "https://github.com/vishnuvinay89/all-saas-learner-ai-services/blob/main/test/jest-e2e.json"

    %% Styles
    classDef code fill:#BBE1FA,stroke:#333,stroke-width:1px
    classDef db fill:#8BF1A4,stroke:#333,stroke-width:1px
    classDef infra fill:#FFD9A5,stroke:#333,stroke-width:1px
    classDef external fill:#F2E394,stroke:#333,stroke-width:1px
    classDef test fill:#FBD1A2,stroke:#333,stroke-width:1px
```
