# arquisoft/wichat_0 architecture

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

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

## Overview

##### Main Components Identification
- Frontend (Webapp): A React application that provides the user interface for login and user registration.
- API Gateway Service: Acts as the entry point exposed to public users. It proxies requests to internal services.
- Auth Service: An Express service responsible for handling user authentication.
- User Service: An Express service managing user data and registration, interacting with MongoDB.
- LLM Service: An Express service for handling communication with one or more external LLM providers, configured via API keys.
- Database: A Mongo database (or multiple instances) accessed by both the Auth and User services via mongoose.
- External Services: (Optional element) The LLM provider’s APIs, which are interacted with by the LLM service.
- CI/CD & Monitoring: GitHub Actions for continuous integration and delivery (the deployment pipeline, unit tests, e2e tests) and integrated monitoring (Prometheus and Grafana configurations under the gateway service).

##### Relationships and Interactions
- The Webapp communicates with the API Gateway Service to perform user operations.
- The API Gateway forwards specific requests to the Auth Service, User Service, or LLM Service.
- The Auth and User services both interface with the same MongoDB instance for data storage.
- The LLM Service communicates with external LLM providers (using provided API keys), facilitating features in the Webapp.
- CI/CD pipelines (defined in the .github/workflows directory) oversee building, testing, releasing, and deployment using SSH and docker-compose.

##### Architectural Patterns and Design Principles
- Microservices Architecture: Each service (gateway, auth, user, LLM) operates independently, enabling separate deployment and scalability.
- API Gateway Pattern: The gateway service serves as a façade for exposing internal services externally.
- Containerization and Orchestration: Docker containers for each service managed via docker-compose (with different profiles for dev/prod) and orchestrated through GitHub Actions.
- Continuous Integration/Continuous Delivery (CI/CD) workflow: Automated build, test, and deployment cycles using GitHub Actions.
- Monitoring: Integrated monitoring setup using Prometheus and Grafana (as seen in the gateway service directory).

##### Technologies and Frameworks
- Backend: Node.js with Express.js in all microservices.
- Frontend: React.js.
- Database: MongoDB (accessed via mongoose).
- Containerization: Docker (with individual Dockerfiles and .dockerignore files).
- CI/CD: GitHub Actions.
- Monitoring: Prometheus and Grafana.
- Communication: RESTful services with potential OpenAPI definitions (gatewayservice/openapi.yaml).

## Diagram (Mermaid)

```mermaid
graph TD
    %% CI/CD Pipeline
    subgraph "CI/CD Automation"
        CICD["CI/CD Pipeline (GitHub Actions)"]:::cicd
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        WEBAPP["Webapp (React)"]:::frontend
    end

    %% Backend Services
    subgraph "Backend Services"
        GATEWAY["API Gateway Service"]:::backend
        AUTH["Auth Service"]:::backend
        USER["User Service"]:::backend
        LLM["LLM Service"]:::backend
    end

    %% Data & External
    subgraph "Data & External"
        MONGO["MongoDB"]:::database
        EXTERNAL["External LLM Provider"]:::external
    end

    %% Monitoring
    subgraph "Monitoring"
        MONITOR["Monitoring (Prometheus & Grafana)"]:::monitoring
    end

    %% Relationships
    WEBAPP -->|"requests"| GATEWAY
    GATEWAY -->|"authRouting"| AUTH
    GATEWAY -->|"userRouting"| USER
    GATEWAY -->|"LLMRouting"| LLM
    AUTH -->|"dataPersistence"| MONGO
    USER -->|"dataPersistence"| MONGO
    LLM -->|"APIcalls"| EXTERNAL
    GATEWAY -->|"monitoredBy"| MONITOR

    %% CI/CD Pipeline deployments
    CICD -->|"deploys"| WEBAPP
    CICD -->|"deploys"| GATEWAY
    CICD -->|"deploys"| AUTH
    CICD -->|"deploys"| USER
    CICD -->|"deploys"| LLM

    %% Click Events
    click WEBAPP "https://github.com/arquisoft/wichat_0/tree/master/webapp/"
    click GATEWAY "https://github.com/arquisoft/wichat_0/tree/master/gatewayservice/"
    click AUTH "https://github.com/arquisoft/wichat_0/tree/master/users/authservice/"
    click USER "https://github.com/arquisoft/wichat_0/tree/master/users/userservice/"
    click LLM "https://github.com/arquisoft/wichat_0/tree/master/llmservice/"
    click CICD "https://github.com/arquisoft/wichat_0/tree/master/.github/workflows/"
    click MONITOR "https://github.com/arquisoft/wichat_0/tree/master/gatewayservice/monitoring/"

    %% Styles
    classDef frontend fill:#a2d5f2,stroke:#000,stroke-width:2px;
    classDef backend fill:#f2a2a2,stroke:#000,stroke-width:2px;
    classDef database fill:#f2f2a2,stroke:#000,stroke-width:2px;
    classDef external fill:#a2f2a2,stroke:#000,stroke-width:2px;
    classDef cicd fill:#d5a2f2,stroke:#000,stroke-width:2px;
    classDef monitoring fill:#f2d5a2,stroke:#000,stroke-width:2px;
```
