# arquisoft/wichat_es6b architecture

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

- Interactive diagram: https://gitdiagram.com/arquisoft/wichat_es6b
- Repository: https://github.com/arquisoft/wichat_es6b

## Overview

##### Main Components
- Frontend – Webapp (React): Represents the client side where users log in, register, and interact with the application.
- API Gateway – Gateway Service (Express): Exposed publicly and acts as a reverse proxy, forwarding requests to the appropriate back-end services.
- Back-end Services (Express-based):
- Auth Service: Handles user authentication.
- User Service: Manages user registration and profile data (sharing the MongoDB database).
- LLM Service: Acts as an intermediary with the Large Language Model API using the configured API key.
- (Optional) Question Service: Manages question generation and related functionalities (it includes routines for interacting with Wikidata and performing database operations).
- Additional “users” sub-services: Under the “users” directory, there are also a history service and a userservice which add to the modular design.
- Database – MongoDB: Used by both the auth and user services (and possibly the question service depending on design), accessed via mongoose.
- CI/CD & Deployment: GitHub Actions (with workflows under .github/workflows) automate testing, building, and deploying via SSH and Docker Compose.
- Monitoring & Logging: Integrated monitoring for the gateway service through Prometheus and Grafana, as seen in the gatewayservice/monitoring directory.

##### Component Relationships and Interactions
- Data Flow:
- The Webapp sends requests (e.g., login, registration, or LLM queries) to the Gateway Service.
- The Gateway Service acts as a proxy, routing requests to the respective microservices (Auth, User, LLM, and optionally Question Services).
- The Auth and User services interact with the shared MongoDB database to manage user information.
- External Integrations:
- The LLM Service communicates with external LLM providers, secured by API keys (provided via .env files).
- Monitoring components (Prometheus and Grafana) connect with the Gateway Service for observability.
- Deployment Pipeline:
- The CI/CD system builds and tests individual services using GitHub Actions. On release, images are pushed and updated using a docker-compose file executed on a remote virtual machine via SSH.

##### Architectural Patterns and Technologies
- Microservices Architecture: Separate Express-based services each handling a distinct set of responsibilities.
- API Gateway Pattern: Encapsulating the microservices behind a single entry point.
- Containerization: Each service is containerized with Docker (see respective Dockerfiles, .dockerignore files, and docker-compose.yml).
- Continuous Integration/Continuous Deployment: Automated pipelines ensure only validated builds are deployed.
- Monitoring: Use of Prometheus and Grafana – this is an additional architectural concern for production-readiness.
- Communication: Likely RESTful APIs among the services with JSON payloads.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        Webapp["React Webapp"]:::web
    end

    %% Gateway Layer
    subgraph "Gateway Layer"
        Gateway["API Gateway Service"]:::backend
    end

    %% Microservices Layer
    subgraph "Microservices Layer"
        AuthService["Auth Service\n(Handles authentication)"]:::backend
        UserService["User Service\n(Manages registration & profiles)"]:::backend
        HistoryService["History Service\n(Sub‑service)"]:::backend
        LLMService["LLM Service\n(Interacts with LLM API)"]:::backend
        QuestionService["Question Service\n(Manages questions)"]:::backend
    end

    %% Data Layer
    subgraph "Data Layer"
        MongoDB["MongoDB Database"]:::database
        ExternalLLMProvider["External LLM Provider"]:::backend
    end

    %% Ops & Deployment Layer
    subgraph "Ops & Deployment"
        CICD["CI/CD Pipeline\n(GitHub Actions)"]:::ops
        DeploymentEnvironment["Deployment Environment"]:::ops
        Monitoring["Monitoring\n(Prometheus & Grafana)"]:::ops
    end

    %% Connections
    Webapp -->|"sends_requests"| Gateway

    Gateway -->|"routes_to_auth"| AuthService
    Gateway -->|"routes_to_user"| UserService
    Gateway -->|"routes_to_history"| HistoryService
    Gateway -->|"routes_to_llm"| LLMService
    Gateway -->|"routes_to_question"| QuestionService

    AuthService -->|"db_access"| MongoDB
    UserService -->|"db_access"| MongoDB

    LLMService -->|"external_call"| ExternalLLMProvider

    Gateway -->|"monitored_by"| Monitoring

    CICD -->|"deploys_to"| DeploymentEnvironment

    %% Styles
    classDef web fill:#a2d2ff,stroke:#000,stroke-width:2px;
    classDef backend fill:#f9d6a5,stroke:#000,stroke-width:2px;
    classDef database fill:#f5b7b1,stroke:#000,stroke-width:2px;
    classDef ops fill:#d5f5e3,stroke:#000,stroke-width:2px;

    %% Click Events
    click Webapp "https://github.com/arquisoft/wichat_es6b/tree/master/webapp"
    click Gateway "https://github.com/arquisoft/wichat_es6b/tree/master/gatewayservice"
    click AuthService "https://github.com/arquisoft/wichat_es6b/tree/master/users/authservice"
    click UserService "https://github.com/arquisoft/wichat_es6b/tree/master/users/userservice"
    click HistoryService "https://github.com/arquisoft/wichat_es6b/tree/master/users/historyservice"
    click LLMService "https://github.com/arquisoft/wichat_es6b/tree/master/llmservice"
    click QuestionService "https://github.com/arquisoft/wichat_es6b/tree/master/questionservice"
    click MongoDB "https://github.com/arquisoft/wichat_es6b/blob/master/config/db.js"
    click CICD "https://github.com/arquisoft/wichat_es6b/tree/master/.github/workflows"
    click Monitoring "https://github.com/arquisoft/wichat_es6b/tree/master/gatewayservice/monitoring"
```
