# nag763/tchatchers architecture

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

- Interactive diagram: https://gitdiagram.com/nag763/tchatchers
- Repository: https://github.com/nag763/tchatchers

## Overview

##### Main Components
- Client (Browser): The chat client running in the user’s browser. It loads a static WASM bundle (built with yew.rs) along with assets (HTML, CSS, Tailwind) that display the UI.
- Frontend Service (tchatchers_front): This Rust crate builds the frontend web-app using yew.rs and communicates with the backend via HTTP APIs and Websockets.
- Backend Service (tchatchers_back): This is the API layer built with Axum, handling authentication, chat room management, data persistence, and real-time communication with Websockets.
- Asynchronous Service (tchatchers_async): A dedicated crate that handles asynchronous operations such as queued message processing. It interacts with Redis to manage queues and processes messages asynchronously.
- Core Service (tchatchers_core): This shared library encapsulates common functionality (data models, API-response formats, configuration, authentication tokens, etc.) that is used by both the frontend and backend.
- Command-Line Tools (tchatchers_cli_tools & tct): These tools help in managing or maintaining the application (for example, possibly for environment setup, debugging, or maintenance operations).
- Data Layer: This includes the Postgres database which persists chat data, users, and any other core records, as well as Redis which is used for real-time caching and token storage.
- Proxy/Reverse Proxy: Although not part of the source code, the README describes an architecture layer maintained by nginx that handles HTTPS, security headers, and basic load balancing measures.

##### Relationships and Interactions
- The Client sends HTTP/Websocket requests to the Frontend Service (served as a static WASM application) which may then interact with the Backend Service.
- The Backend Service (API layer) handles authentication, message handling, and CRUD operations while also interacting with the Postgres database for persistent storage.
- The Asynchronous Service continuously processes messages from Redis queues to handle time-consuming tasks asynchronously.
- The Core library is used by both the frontend and backend layers, ensuring that common logic (such as API responses, configuration, and error management) remains consistent across the application.
- Nginx (reverse proxy) sits at the entry point of the system, routing requests to the appropriate services (frontend, API, and, if applicable, the asynchronous processing endpoints) while enforcing security constraints.
- The CLI Tools provide management operations that might interact with one or several of the above components (for example, updating the environment, migrations, or reporting).

##### Architectural Patterns and Design Principles
- Service Separation: The project distinguishes frontend, backend, and asynchronous services as separate Rust crates. This modular design encourages separation of concerns.
- Microservices Elements: Although it is a monorepository, the individual services (frontend, backend, async) behave as microservices within the architecture.
- Asynchronous Processing: The dedicated asynchronous layer design shows the use of queues and processors to handle tasks that should not block real-time responses.
- Shared Core: Using a common core crate ensures consistency and reusability across different services.
- Containerization and CI/CD: The existence of multiple Dockerfiles (one per service), docker-compose scripts, GitHub workflows, and Makefiles indicates containerized deployments and an integrated CI/CD process.

- Document interaction points (such as API calls, message queues, Websockets) and include annotations or legends to explain the purpose of each component.

## Diagram (Mermaid)

```mermaid
graph TD
    Client_Browser["Client (Browser)"]:::client
    Nginx_Proxy["Nginx Proxy"]:::proxy
    Frontend_Service["Frontend (Yew.rs/WASM)"]:::frontend
    Backend_API["Backend API (Axum)"]:::backend
    Core_Service["Core Service (Shared Library)"]:::core
    Postgres_DB["Postgres Database"]:::datalayer
    Redis_Cache["Redis Cache/Queue"]:::datalayer
    Async_Processor["Async Processor (Async Service)"]:::async
    CLI_Tools["CLI Tools"]:::cli

    Client_Browser -->|"HTTP/Websocket"| Nginx_Proxy
    Nginx_Proxy -->|"Routes_to"| Frontend_Service
    Nginx_Proxy -->|"Routes_to"| Backend_API
    Frontend_Service -->|"Uses_shared"| Core_Service
    Backend_API -->|"Uses_shared"| Core_Service
    Backend_API -->|"CRUD_operations"| Postgres_DB
    Backend_API -->|"TokenQueue_ops"| Redis_Cache
    Redis_Cache -->|"Queued_messages"| Async_Processor
    Backend_API -->|"Triggers_async"| Async_Processor
    CLI_Tools -->|"Manages"| Frontend_Service
    CLI_Tools -->|"Manages"| Backend_API
    CLI_Tools -->|"Manages"| Async_Processor

    %% Click Events for Client (Browser)
    click Client_Browser "https://github.com/nag763/tchatchers/tree/main/tchatchers_front/assets"
    click Client_Browser "https://github.com/nag763/tchatchers/blob/main/tchatchers_front/index.html"
    click Client_Browser "https://github.com/nag763/tchatchers/blob/main/tchatchers_front/main.css"

    %% Click Events for Frontend Service (WASM, yew.rs)
    click Frontend_Service "https://github.com/nag763/tchatchers/tree/main/tchatchers_front"
    click Frontend_Service "https://github.com/nag763/tchatchers/tree/main/tchatchers_front/src"
    click Frontend_Service "https://github.com/nag763/tchatchers/blob/main/tchatchers_front/Trunk.toml"

    %% Click Events for Backend Service (Axum API)
    click Backend_API "https://github.com/nag763/tchatchers/tree/main/tchatchers_back"
    click Backend_API "https://github.com/nag763/tchatchers/tree/main/tchatchers_back/src"
    click Backend_API "https://github.com/nag763/tchatchers/tree/main/tchatchers_back/api"

    %% Click Events for Asynchronous Service (Async message processing)
    click Async_Processor "https://github.com/nag763/tchatchers/tree/main/tchatchers_async"
    click Async_Processor "https://github.com/nag763/tchatchers/tree/main/tchatchers_async/src"

    %% Click Events for Core Service (Shared functionality)
    click Core_Service "https://github.com/nag763/tchatchers/tree/main/tchatchers_core"
    click Core_Service "https://github.com/nag763/tchatchers/tree/main/tchatchers_core/src"
    click Core_Service "https://github.com/nag763/tchatchers/blob/main/tchatchers_core/src/api_response.rs"

    %% Click Events for Command-Line Tools
    click CLI_Tools "https://github.com/nag763/tchatchers/tree/main/tchatchers_cli_tools"
    click CLI_Tools "https://github.com/nag763/tchatchers/tree/main/tchatchers_cli_tools/src"
    click CLI_Tools "https://github.com/nag763/tchatchers/tree/main/tchatchers_cli_tools/templates"

    %% Click Events for Proxy/Reverse Proxy
    click Nginx_Proxy "https://github.com/nag763/tchatchers/blob/main/tchatchers_cli_tools/templates/nginx.conf"
    click Nginx_Proxy "https://github.com/nag763/tchatchers/blob/main/tchatchers_cli_tools/templates/nginx.proxy.conf"

    %% Styles
    classDef client fill:#AED6F1,stroke:#2E86C1,color:#154360,stroke-width:2px;
    classDef frontend fill:#ABEBC6,stroke:#28B463,color:#1D8348,stroke-width:2px;
    classDef backend fill:#F9E79F,stroke:#F4D03F,color:#B7950B,stroke-width:2px;
    classDef async fill:#D2B4DE,stroke:#AF7AC5,color:#6C3483,stroke-width:2px;
    classDef core fill:#FAD7A0,stroke:#F5B041,color:#B9770E,stroke-width:2px;
    classDef datalayer fill:#F5CBA7,stroke:#E59866,color:#BF360C,stroke-width:2px;
    classDef cli fill:#F5B7B1,stroke:#EC7063,color:#C0392B,stroke-width:2px;
    classDef proxy fill:#D6EAF8,stroke:#5DADE2,color:#2874A6,stroke-width:2px;
```
