# arquisoft/wichat_es6a architecture

> Architecture diagram of the GitHub repository arquisoft/wichat_es6a, 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/arquisoft/wichat_es6a
- Repository: https://github.com/arquisoft/wichat_es6a

## Overview

##### Main Components
- Web Application: A React frontend located in the webapp folder. It provides the user interface and makes API calls to the backend.
- Gateway Service: An Express service (gatewayservice) that acts as a public façade or API gateway. It channels requests to the relevant backend services.
- Backend Microservices:
- Auth Service: (users/authservice) handles user authentication.
- User Service: (users/userservice) manages user data and registration.
- LLM Service: (llmservice) communicates with a Language Learning Model (LLM). It uses an API key-based integration and provides advanced processing.
- History Service: (historyservice) manages history or stats, likely related to chat interactions.
- Wikidata Service: (wikidataservice) provides integration with external wikidata sources.
- Shared Database: As noted in the README, the Auth and User services share a MongoDB instance (accessed via mongoose). Though not explicitly in the file tree, it should be represented as a common datastore.
- Monitoring and CI/CD Components: Notice the monitoring directories inside the gateway service (using Grafana and Prometheus which is a hint for real-time metrics monitoring) as well as the GitHub Actions workflows (in the .github directory). This indicates continuous testing, building, and deployment integration.

##### Relationships and Interactions
- The WebApp sends HTTP requests (via APIs) to the Gateway Service.
- The Gateway Service forwards or proxies requests to the appropriate microservices (Auth, User, LLM, etc.).
- Auth and User services interact with the shared Mongo database.
- Monitoring tools (Prometheus and Grafana) collect metrics from the services (at least from the gateway service) and display dashboards.
- The CI/CD pipeline (configured in GitHub Actions) automates unit, integration, and end-to-end tests, followed by Docker image builds and deployment (using docker-compose.yml and SSH deployment commands).

##### Architectural Patterns & Design Principles
- Microservices Architecture: Each backend component is isolated in its own folder with its own Dockerfile and package.json, suggesting independent deployment and scaling.
- API Gateway Pattern: The gatewayservice acts as a proxy for client requests, centralizing external communication.
- Containerization & Orchestration: Dockerfiles in each component coupled with a central docker-compose.yml show container-based deployment.
- Continuous Integration/Deployment: GitHub Actions for automated testing and deployment, ensuring graceful integration.
- Separation of Concerns: Frontend and multiple backend services are clearly segregated.

##### Technologies & Frameworks
- React for building the web frontend.
- Express (Node.js) for the backend services.
- MongoDB (with mongoose) for persistent storage in the auth and user services.
- Docker & docker-compose for containerization.
- GitHub Actions for CI/CD.
- Monitoring tools (Prometheus and Grafana) for real-time service metrics.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend
    subgraph "Frontend"
        A["WebApp (React)"]:::frontend
    end

    %% Backend Services
    subgraph "Backend Services"
        B["Gateway Service (Express)"]:::backend
        C["Auth Service (Express)"]:::backend
        D["User Service (Express)"]:::backend
        E["LLM Service (Express)"]:::backend
        F["History Service (Express)"]:::backend
        G["Wikidata Service (Express)"]:::backend
    end

    %% Infrastructure Components
    subgraph "Infrastructure"
        H["MongoDB (Shared Database)"]:::database
        I["Monitoring (Prometheus & Grafana)"]:::monitoring
        J["CI/CD Pipeline (GitHub Actions)"]:::cicd
        K["Docker Compose Deployment"]:::infrastructure
    end

    %% Data Flow: Frontend to Gateway
    A -->|"API_calls"| B

    %% Gateway forwarding to Backend Services
    B -->|"forwards_to"| C
    B -->|"forwards_to"| D
    B -->|"forwards_to"| E
    B -->|"forwards_to"| F
    B -->|"forwards_to"| G

    %% Database interactions from Auth and User services
    C -->|"db_ops"| H
    D -->|"db_ops"| H

    %% Monitoring Metrics from Services
    B -->|"metrics"| I
    C -->|"metrics"| I
    D -->|"metrics"| I
    E -->|"metrics"| I
    F -->|"metrics"| I
    G -->|"metrics"| I

    %% CI/CD Pipeline triggers Docker Compose deployment
    J -->|"deploys"| K
    K -->|"deploys_to"| A
    K -->|"deploys_to"| B
    K -->|"deploys_to"| C
    K -->|"deploys_to"| D
    K -->|"deploys_to"| E
    K -->|"deploys_to"| F
    K -->|"deploys_to"| G

    %% Click Events
    click A "https://github.com/arquisoft/wichat_es6a/tree/master/webapp/"
    click B "https://github.com/arquisoft/wichat_es6a/tree/master/gatewayservice/"
    click C "https://github.com/arquisoft/wichat_es6a/tree/master/users/authservice/"
    click D "https://github.com/arquisoft/wichat_es6a/tree/master/users/userservice/"
    click E "https://github.com/arquisoft/wichat_es6a/tree/master/llmservice/"
    click F "https://github.com/arquisoft/wichat_es6a/tree/master/historyservice/"
    click G "https://github.com/arquisoft/wichat_es6a/tree/master/wikidataservice/"
    click I "https://github.com/arquisoft/wichat_es6a/tree/master/gatewayservice/monitoring/"
    click J "https://github.com/arquisoft/wichat_es6a/tree/master/.github/workflows/"

    %% Styles
    classDef frontend fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef backend fill:#C5E1A5,stroke:#333,stroke-width:2px;
    classDef database fill:#F4B400,stroke:#333,stroke-width:2px,shape: cylinder;
    classDef monitoring fill:#FFCDD2,stroke:#333,stroke-width:2px;
    classDef cicd fill:#FFECB3,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#D1C4E9,stroke:#333,stroke-width:2px;
```
