# holedev/vnoi-microservice architecture

> Architecture diagram of the GitHub repository holedev/vnoi-microservice, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/holedev/vnoi-microservice
- Repository: https://github.com/holedev/vnoi-microservice

## Overview

##### Main Components
- Frontend (Client): This lives in the “client” directory. It is a React 18 application using Vite, Material UI, CodeMirror for a modern, interactive UI, with additional tools like Cypress for E2E testing and K6 for load testing.
- API Gateway: Found under the “server/gateway” directory, this component acts as the central entry point for all client requests, handling routing, security (JWT, rate limiting), and orchestrating calls to internal services.
- Backend Microservices: These include the User Service, Exercise Service, Learning Service, Media Service, Statistics Service, and Common Service. Each service is maintained as a separate module within the “server” directory (with dedicated folders like server/user, server/exercise, etc.). They provide discrete functionalities (e.g., user management, exercise submission and evaluation, course learning, media handling, and analytics).
- Infrastructure Components:
– Messaging Queue: RabbitMQ (configuration found across several service directories) is used to manage asynchronous communication.
– Database: MongoDB is the primary data store for these services.
– Monitoring: Prometheus and Grafana are integrated for real-time performance metrics and logging dashboards.
– Containerization & Orchestration: Docker is extensively used (Dockerfiles and docker-compose configurations are present) to manage environments for development and production.

##### Relationships and Interactions
- The Client (frontend) communicates directly with the API Gateway.
- The API Gateway then routes requests to the appropriate backend service (User, Exercise, Learning, Media, or Statistics).
- Each microservice interacts with:
– A common service, which provides shared utilities and business logic.
– MongoDB for persistent storage.
– RabbitMQ for inter-service messaging.
- Monitoring services such as Prometheus and Grafana pull metrics from the backend services.
- There are also external dependencies (such as Firebase) and configuration tools integrated into selected services.

##### Important Architectural Patterns & Principles
- Microservices Architecture: Each service is isolated to manage specific business domains. This improves scalability, maintainability, and fault isolation.
- API Gateway Pattern: Centralizes request routing, security, and possibly load balancing.
- Containerization: Docker is used to standardize and deploy multiple services reliably in various environments.
- Testing First: A comprehensive testing strategy is in place (unit tests, integration tests, E2E tests) ensuring service reliability.
- Observability: Incorporation of Prometheus and Grafana demonstrates an adherence to modern devops practices.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["React Frontend"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        API["API Gateway"]:::gateway
        US["User Service"]:::microservice
        ES["Exercise Service"]:::microservice
        LS["Learning Service"]:::microservice
        MS["Media Service"]:::microservice
        SS["Statistics Service"]:::microservice
        CS["Common Service"]:::microservice
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        MQ["RabbitMQ"]:::infrastructure
        DB["MongoDB"]:::database
        PM["Prometheus"]:::monitoring
        GF["Grafana"]:::monitoring
        DC["Docker & Docker-Compose"]:::infrastructure
    end

    %% Connections: Frontend to API Gateway
    FE -->|"HTTP"| API

    %% Connections: API Gateway to Backend Microservices
    API -->|"Route"| US
    API -->|"Route"| ES
    API -->|"Route"| LS
    API -->|"Route"| MS
    API -->|"Route"| SS

    %% Connections: Microservices share common service
    US -->|"Shared"| CS
    ES -->|"Shared"| CS
    LS -->|"Shared"| CS
    MS -->|"Shared"| CS
    SS -->|"Shared"| CS

    %% Connections: Microservices accessing Database and Messaging
    US -->|"DB"| DB
    ES -->|"DB"| DB
    LS -->|"DB"| DB
    MS -->|"DB"| DB
    SS -->|"DB"| DB
    CS -->|"DB"| DB

    US -->|"MQ"| MQ
    ES -->|"MQ"| MQ
    LS -->|"MQ"| MQ
    MS -->|"MQ"| MQ
    SS -->|"MQ"| MQ
    CS -->|"MQ"| MQ

    %% Connections: Microservices sending metrics to Prometheus and then Grafana
    US -->|"Monitored"| PM
    ES -->|"Monitored"| PM
    LS -->|"Monitored"| PM
    MS -->|"Monitored"| PM
    SS -->|"Monitored"| PM
    CS -->|"Monitored"| PM
    PM -->|"Dashboard"| GF

    %% Click Events for Component Mapping
    click FE "https://github.com/holedev/vnoi-microservice/tree/main/client"
    click API "https://github.com/holedev/vnoi-microservice/tree/main/server/gateway"
    click US "https://github.com/holedev/vnoi-microservice/tree/main/server/user"
    click ES "https://github.com/holedev/vnoi-microservice/tree/main/server/exercise"
    click LS "https://github.com/holedev/vnoi-microservice/tree/main/server/learning"
    click MS "https://github.com/holedev/vnoi-microservice/tree/main/server/media"
    click SS "https://github.com/holedev/vnoi-microservice/tree/main/server/statistics"
    click CS "https://github.com/holedev/vnoi-microservice/tree/main/server/common"

    %% Classes & Styles
    classDef frontend fill:#f9f,stroke:#333,stroke-width:2px;
    classDef gateway fill:#ccf,stroke:#333,stroke-width:2px;
    classDef microservice fill:#cfc,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#ffc,stroke:#333,stroke-width:2px;
    classDef database fill:#fcf,stroke:#333,stroke-width:2px;
    classDef monitoring fill:#cff,stroke:#333,stroke-width:2px;
```
