# ozymandiaz1876/learning-management-system-backend architecture

> Architecture diagram of the GitHub repository ozymandiaz1876/learning-management-system-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ozymandiaz1876/learning-management-system-backend
- Repository: https://github.com/ozymandiaz1876/learning-management-system-backend

## Overview

##### Main Components

a) Core Application Layer:
- Following modules as separate components within:
- Auth Module
- Users Module
- Questions Module
- Tests Module
- Results Module

b) Database Layer:
- MongoDB (indicated by Mongoose/Typegoose configuration)
- Collections for Users, Questions, Tests, and Results

c) Authentication Layer:
- JWT Authentication system
- Role-based access control

##### Component Relationships

- Client/External Requests → Auth Guard → Controllers
- Controllers → Services → Repositories → Database
- JWT flow from Auth Service to other protected modules

##### Detailed Module Breakdown

For each major module, create a sub-section showing:

a) Auth Module:
**┌─ Auth Module ─────────────┐**
- JWT Strategy           │
- Guards                 │
- Controllers           │
- Services              │
- ┘

b) Tests Module:
**┌─ Tests Module ────────────┐**
- Test Algorithm Config   │
- Test Controller        │
- Test Service          │
- Test Repository       │
- ┘

##### Key Elements to Highlight

a) Security Layer:
- JWT Authentication flow
- Role Guards (UserRoles enum implementation)
- Authorization decorators

b) Data Flow:
- Request handling path
- Database interactions
- Test algorithm flow

##### Technical Details

- NestJS framework as the foundation
- MongoDB database connection
- JWT token implementation
- Configuration management
- Repository pattern implementation

**┌─ Test Algorithm ────────────────┐**
- Initial Difficulty → 5         │
- Max Questions → 20             │
- Difficulty Range → 1-10        │
- Adaptive Difficulty System     │
- ┘

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        CL[Client Requests]
    end

    subgraph "NestJS Application"
        subgraph "Authentication Layer"
            JWT["JWT Strategy"]:::auth
            AG["Auth Guards"]:::auth
            AC["Auth Controller"]:::auth
            AS["Auth Service"]:::auth
        end

        subgraph "Core Modules"
            UM["Users Module"]:::module
            QM["Questions Module"]:::module
            TM["Tests Module"]:::module
            RM["Results Module"]:::module

            subgraph "Module Components"
                US["Users Service"]:::service
                UR["Users Repository"]:::repo
                QS["Questions Service"]:::service
                QR["Questions Repository"]:::repo
                TS["Tests Service"]:::service
                TR["Tests Repository"]:::repo
                RS["Results Service"]:::service
                RR["Results Repository"]:::repo
            end
        end

        subgraph "Test Algorithm"
            TAC["Test Algorithm Config"]:::config
            direction TB
            TAC --> |"Initial Difficulty: 5"| TS
            TAC --> |"Max Questions: 20"| TS
            TAC --> |"Difficulty Range: 1-10"| TS
        end

        subgraph "Access Control"
            RG["Role Guard"]:::security
            RD["Role Decorators"]:::security
            RE["User Roles Enum"]:::security
        end
    end

    subgraph "Database Layer"
        DB[(MongoDB)]:::database
        UM_COL[(Users Collection)]:::collection
        QM_COL[(Questions Collection)]:::collection
        TM_COL[(Tests Collection)]:::collection
        RM_COL[(Results Collection)]:::collection
    end

    %% Connections
    CL --> AG
    AG --> AC
    AC --> AS
    AS --> JWT

    %% Module Connections
    UM --> US --> UR --> UM_COL
    QM --> QS --> QR --> QM_COL
    TM --> TS --> TR --> TM_COL
    RM --> RS --> RR --> RM_COL

    %% Security Flow
    AG --> RG
    RG --> RD
    RD --> RE

    %% Styles
    classDef module fill:#2196F3,stroke:#1565C0,color:white
    classDef service fill:#4CAF50,stroke:#2E7D32,color:white
    classDef repo fill:#78909C,stroke:#546E7A,color:white
    classDef auth fill:#FFC107,stroke:#FFA000,color:black
    classDef security fill:#F44336,stroke:#C62828,color:white
    classDef database fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef collection fill:#7B1FA2,stroke:#4A148C,color:white
    classDef config fill:#00BCD4,stroke:#0097A7,color:white

    %% Click Events
    click JWT "https://github.com/Ozymandiaz1876/learning-management-system-backend/blob/main/src/auth/strategies/jwt.strategy.ts"
    click AG "https://github.com/Ozymandiaz1876/learning-management-system-backend/tree/main/src/auth/guards"
    click AC "https://github.com/Ozymandiaz1876/learning-management-system-backend/blob/main/src/auth/auth.controller.ts"
    click AS "https://github.com/Ozymandiaz1876/learning-management-system-backend/blob/main/src/auth/auth.service.ts"
    click UM "https://github.com/Ozymandiaz1876/learning-management-system-backend/blob/main/src/users/users.module.ts"
    click US "https://github.com/Ozymandiaz1876/learning-management-system-backend/blob/main/src/users/users.service.ts"
    click UR "https://github.com/Ozymandiaz1876/learning-management-system-backend/blob/main/src/users/users.repository.ts"
    click QM "https://github.com/Ozymandiaz1876/learning-management-system-backend/blob/main/src/questions/questions.module.ts"
    click QS "https://github.com/Ozymandiaz1876/learning-management-system-backend/blob/main/src/questions/questions.service.ts"
    click QR "https://github.com/Ozymandiaz1876/learning-management-system-backend/blob/main/src/questions/questions.repository.ts"
    click TM "https://github.com/Ozymandiaz1876/learning-management-system-backend/blob/main/src/tests/tests.module.ts"
    click TS "https://github.com/Ozymandiaz1876/learning-management-system-backend/blob/main/src/tests/tests.service.ts"
    click TR "https://github.com/Ozymandiaz1876/learning-management-system-backend/blob/main/src/tests/tests.repository.ts"
    click RM "https://github.com/Ozymandiaz1876/learning-management-system-backend/blob/main/src/results/results.module.ts"
    click RS "https://github.com/Ozymandiaz1876/learning-management-system-backend/blob/main/src/results/results.service.ts"
    click RR "https://github.com/Ozymandiaz1876/learning-management-system-backend/blob/main/src/results/results.repository.ts"
    click TAC "https://github.com/Ozymandiaz1876/learning-management-system-backend/blob/main/src/tests/config/testAlgorithm.config.ts"
    click RG "https://github.com/Ozymandiaz1876/learning-management-system-backend/blob/main/src/auth/guards/role.guard.ts"
    click RD "https://github.com/Ozymandiaz1876/learning-management-system-backend/blob/main/src/auth/decorators/roles.decorators.ts"
    click RE "https://github.com/Ozymandiaz1876/learning-management-system-backend/blob/main/src/constants/enums/UserRoles.enum.ts"
```
