# boboiboy181/uitwiki-be architecture

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

- Interactive diagram: https://gitdiagram.com/boboiboy181/uitwiki-be
- Repository: https://github.com/boboiboy181/uitwiki-be

## Overview

##### Main Components
- Microservices – There are several services under the “apps” directory:
- Authentication Service (apps/auth): Manages user authentication, JWT strategies, and guards.
- Chatbot Service (apps/chatbot): Handles natural language processing queries and responses.
- Document Service (apps/document): Manages PDF document uploads and storage; likely used to update the knowledge base.
- Session Service (apps/session): Manages session data, probably storing conversation histories.
- Main Backend or Gateway (apps/uit-wiki-be): Seems to integrate the above services into a unified API endpoint interface.
- Shared Library – The “libs/common” folder provides common utilities, DTOs, decorators, shared database modules, logging, and integration with third-party tools (e.g., Redis, Pinecone). This module is used by multiple microservices.
- Infrastructure & Deployment – The Docker files for each app, docker-compose.yml, and Kubernetes manifests under the “k8s” directory (with Helm charts) represent how services are containerized and orchestrated.
- External Dependencies – MongoDB for persistent storage, Redis for caching or session storage, and possibly external API consumers via Swagger-documented endpoints.

##### Relationships and Interactions
- Clients (UIT students and admin/lecturers) access the system via web or mobile interfaces.
- Requests hit a Kubernetes Ingress or load balancer (if depicted) and then get routed to the “uit-wiki-be” gateway.
- The Gateway/Backend then directs requests internally or via API calls to the appropriate microservice:
– Authentication for login and token management.
– Chatbot for retrieving answers.
– Document Service for file upload and document querying.
– Session Service for maintaining conversation histories.
- Shared modules in “libs/common” are consumed by individual microservices for consistent business logic and common functionality.
- Data flows are bidirectional:
– HTTP requests from the client to a service.
– Internal service-to-service calls or shared database calls.
– Interactions with databases like MongoDB and caches like Redis.

##### Architectural Patterns and Design Principles
- Microservice Architecture: Each major function (auth, chatbot, document, session) is isolated as its own service.
- API Gateway/Backend Integration: The “uit-wiki-be” service appears to act as a centralized backend that integrates these microservices.
- Containerization and Orchestration: Docker is used for image build/deployment and Kubernetes manifests manage production deployments.
- Common Utility / Shared Libraries: “libs/common” encapsulates patterns (e.g., repository pattern, decorators, DTOs) that promote code reuse and consistency.

##### Relevant Technologies and Frameworks
- Nest.js framework across services.
- Docker for containerization (each service has its Dockerfile).
- Kubernetes with Helm charts (see k8s/uit-wiki-be) for deployments.
- MongoDB and Redis for storage and caching.
- Swagger for API documentation (from libs/common).
- Testing frameworks and e2e configurations (present under each app’s test directory).

##### Final Assembly
- Expand each microservice with internal details if needed (important files like controllers, services, and repositories can be abstracted as sub-components).
- That each component is clearly labeled with its role (for example, “Auth – handles user and JWT management”).
- Container and orchestration layers below or as an adjacent context, showing how Docker images feed into Kubernetes deployments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients and Ingress
    Clients["Clients (UIT Students/Admins)"]:::client
    Ingress["Kubernetes Ingress/Load Balancer"]:::ingress
    Clients -->|"HTTP-request"| Ingress

    %% API Gateway
    APIGateway["API Gateway: uit-wiki-be"]:::api
    Ingress -->|"routes"| APIGateway
    APIGateway -->|"delegates"| MSGroup

    %% Microservices Subgraph
    subgraph "Microservices"
        AuthService["Authentication Service (Nest.js)"]:::microservice
        ChatbotService["Chatbot Service (Nest.js)"]:::microservice
        DocumentService["Document Service (Nest.js)"]:::microservice
        SessionService["Session Service (Nest.js)"]:::microservice
    end
    %% API Gateway delegates to each microservice
    APIGateway -->|"calls"| AuthService
    APIGateway -->|"calls"| ChatbotService
    APIGateway -->|"calls"| DocumentService
    APIGateway -->|"calls"| SessionService

    %% Shared Utilities
    SharedUtilities["Shared Utilities (libs/common)"]:::shared
    AuthService -->|"uses"| SharedUtilities
    ChatbotService -->|"uses"| SharedUtilities
    DocumentService -->|"uses"| SharedUtilities
    SessionService -->|"uses"| SharedUtilities

    %% External Databases & Cache
    MongoDB["MongoDB (Persistent Storage)"]:::external
    Redis["Redis (Caching/Session Storage)"]:::external
    AuthService -->|"stores"| MongoDB
    DocumentService -->|"stores"| MongoDB
    SessionService -->|"stores"| Redis
    ChatbotService -->|"caches"| Redis

    %% Infrastructure Subgraph
    subgraph "Infrastructure"
        Containerization["Containerization (Docker & docker-compose)"]:::infra
        Orchestration["Orchestration (Kubernetes & Helm)"]:::infra
    end
    %% Deployment flow
    APIGateway -->|"containerized"| Containerization
    AuthService -->|"containerized"| Containerization
    ChatbotService -->|"containerized"| Containerization
    DocumentService -->|"containerized"| Containerization
    SessionService -->|"containerized"| Containerization
    SharedUtilities -->|"packaged"| Containerization
    Containerization -->|"deployed via"| Orchestration

    %% Click Events for Component Mapping
    click APIGateway "https://github.com/boboiboy181/uitwiki-be/tree/main/apps/uit-wiki-be"
    click AuthService "https://github.com/boboiboy181/uitwiki-be/tree/main/apps/auth"
    click ChatbotService "https://github.com/boboiboy181/uitwiki-be/tree/main/apps/chatbot"
    click DocumentService "https://github.com/boboiboy181/uitwiki-be/tree/main/apps/document"
    click SessionService "https://github.com/boboiboy181/uitwiki-be/tree/main/apps/session"
    click SharedUtilities "https://github.com/boboiboy181/uitwiki-be/tree/main/libs/common"
    click Containerization "https://github.com/boboiboy181/uitwiki-be/blob/main/docker-compose.yml"
    click Orchestration "https://github.com/boboiboy181/uitwiki-be/tree/main/k8s/uit-wiki-be"

    %% Styles
    classDef client fill:#FFEBCC,stroke:#D2691E,stroke-width:2px
    classDef ingress fill:#FFFACD,stroke:#DAA520,stroke-width:2px
    classDef api fill:#F08080,stroke:#DC143C,stroke-width:2px
    classDef microservice fill:#ADD8E6,stroke:#00008B,stroke-width:2px
    classDef shared fill:#FFE4E1,stroke:#B22222,stroke-width:2px
    classDef external fill:#90EE90,stroke:#008000,stroke-width:2px
    classDef infra fill:#D3D3D3,stroke:#696969,stroke-width:2px

    %% Grouping Microservices for clean vertical layout
    MSGroup["Microservices Group"]:::microservice
    APIGateway --- MSGroup
    MSGroup --- AuthService
    MSGroup --- ChatbotService
    MSGroup --- DocumentService
    MSGroup --- SessionService
```
