# arquisoft/wichat_es3b architecture

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

## Overview

##### Main Components
- Frontend (Webapp):
- Represented as the React-based web application.
- This component handles user interaction (login, user registration, gameplay features) and communicates with the backend via HTTP APIs.
- Gateway Service:
- Acts as the public-facing proxy.
- Routes client requests from the webapp to the appropriate backend services.
- Backend Microservices:
- LLM Service: An Express service that manages communication with a Language Model (LLM) and requires an API key.
- User-related Services (contained in the users directory):
◦ Auth Service: Handles user authentication.
◦ User Service: Manages user data insertion.
◦ Stats Service: Manages game or usage statistics.
- Wiki Question Service:
◦ A specialized service for question generation and management.
- Database:
- A shared MongoDB database used by at least the auth and user services (accessed via Mongoose).
- Infrastructure and CI/CD:
- Docker and Docker Compose configuration for containerized deployment.
- GitHub Actions workflows for build, testing, and deployment over SSH.
- Environment configuration (.env files) for sensitive data like the LLM API key.

##### Relationships and Interactions
- The Webapp sends RESTful API calls to the Gateway Service.
- The Gateway Service functions as a reverse proxy, forwarding requests to:
- The LLM Service (for language model communication).
- The respective User services (auth, user, and stats) for authentication and user management.
- The Auth and User services connect to a shared MongoDB database.
- Optionally, if the Wiki Question Service is actively used in the system’s flow, it should be connected (or interact) with the other services that may need to retrieve or generate query-based content.
- CI/CD pipelines are used to build, test, and deploy all these components by:
- Running individual tests (unit and end-to-end tests).
- Building Docker images for each service.
- Deploying via SSH using docker-compose (utilizing profiles such as “prod” and “dev”).

##### Architectural Patterns and Design Principles
- Microservices Architecture:
- Each business domain is modularized in its own service (e.g., auth, users, stats, LLM, and wiki questions), which improves separation of concerns and scalability.
- Containerization:
- Dockerfiles for each service and the overall docker-compose configuration indicate a containerized deployment approach.
- CI/CD Integration:
- Automated test, build, and deployment pipelines from GitHub Actions ensure a robust development process.
- Clear API Gateway Pattern:
- The gateway service simplifies the communication between the client (webapp) and multiple backend services.
- Shared Data Store:
- MongoDB serves as the central data storage for user-related information, denoting a common dependency.

##### Detailed Process
- Then, drill down with sub-components or annotations about:
- Which services are containerized,
- How the CI/CD workflow orchestrates deployment,
- How sensitive configuration (API keys via .env) is managed.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client/Presentation Layer
    subgraph "Client/Presentation Layer"
        A["Webapp (React)"]:::frontend
    end

    %% Backend/API Layer
    subgraph "Backend/API Layer"
        B["Gateway Service (Express)"]:::backend
        C["LLM Service (Express)"]:::backend
        subgraph "User Microservices"
            D["Auth Service (Express)"]:::backend
            E["User Service (Express)"]:::backend
            F["Stats Service (Express)"]:::backend
        end
        G["Wiki Question Service (Express)"]:::backend
    end

    %% Shared Database
    DB["MongoDB Database"]:::database

    %% Infrastructure & CI/CD
    subgraph "Infrastructure & CI/CD"
        DC["Docker Compose"]:::infrastructure
        GA["GitHub Actions Workflows"]:::infrastructure
        ENV[".env Configuration"]:::infrastructure
    end

    %% API Request Flows
    A -->|"RESTCall"| B
    B -->|"RoutesRequest"| C
    B -->|"RoutesRequest"| D
    B -->|"RoutesRequest"| E
    B -->|"RoutesRequest"| F
    B -->|"RoutesRequest"| G

    %% Database Connections
    D -->|"DBQuery"| DB
    E -->|"DBQuery"| DB
    F -->|"DBQuery"| DB

    %% Infrastructure Deployment Flows (Dotted)
    GA -->|"TriggersBuild"| DC
    DC -.->|"Deploys"| A
    DC -.->|"Deploys"| B
    DC -.->|"Deploys"| C
    DC -.->|"Deploys"| D
    DC -.->|"Deploys"| E
    DC -.->|"Deploys"| F
    DC -.->|"Deploys"| G
    ENV -.->|"Configures"| B
    ENV -.->|"Configures"| C
    ENV -.->|"Configures"| D
    ENV -.->|"Configures"| E
    ENV -.->|"Configures"| F
    ENV -.->|"Configures"| G

    %% Click Events
    click A "https://github.com/arquisoft/wichat_es3b/tree/master/webapp/"
    click B "https://github.com/arquisoft/wichat_es3b/blob/master/gatewayservice/gateway-service.js"
    click C "https://github.com/arquisoft/wichat_es3b/blob/master/llmservice/llm-service.js"
    click D "https://github.com/arquisoft/wichat_es3b/blob/master/users/authservice/auth-service.js"
    click E "https://github.com/arquisoft/wichat_es3b/blob/master/users/userservice/user-service.js"
    click F "https://github.com/arquisoft/wichat_es3b/blob/master/users/statsservice/stats-service.js"
    click G "https://github.com/arquisoft/wichat_es3b/blob/master/wikiquestionservice/wikiQuestion-service.js"
    click DC "https://github.com/arquisoft/wichat_es3b/blob/master/docker-compose.yml"
    click GA "https://github.com/arquisoft/wichat_es3b/tree/master/.github/workflows/"
    click ENV "https://github.com/arquisoft/wichat_es3b/blob/master/.env Configuration"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#0000FF,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#008000,stroke-width:2px,stroke-dasharray: 5,5;
    classDef database fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef infrastructure fill:#D3D3D3,stroke:#A9A9A9,stroke-width:2px;
```
