# gabrielbarros36/gchat architecture

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

- Interactive diagram: https://gitdiagram.com/gabrielbarros36/gchat
- Repository: https://github.com/gabrielbarros36/gchat

## Overview

##### Project Overview
- The project, “gchat”, is a toy chat application designed to help the author learn Rust, asynchronous programming, and websockets.
- It is a full-stack application with a Next.js (React) client and a Rust-based backend that manages the routing, state, and websocket connections.

##### Identifying Main Components
a. Frontend (Client):
- Located in the "client" directory, using Next.js with React.
- Contains a well-organized directory structure including pages, components (various modals and utility components), CSS (globals.css), and configuration files (tailwind.config.ts, eslint, etc.).
- Implements UI elements such as chat forms, authentication modals, and settings using custom components and UI modules.

b. Backend (Server):
- Located in the "src" directory with main files like server.rs and client.rs.
- Consists of the "routes" subdirectory (with auth.rs, friend.rs, group.rs, and mod.rs) which hosts endpoint definitions for handling chat functions such as user authentication, friend management, and group management.
- Includes state management (src/state.rs) likely used to manage realtime data or websocket sessions.
- Uses templates (in the "templates" directory) for rendering static HTML pages for login, registration, and success feedback, which might indicate server-side rendering for certain flows.

c. Communication/Real-time Layer:
- The README’s emphasis on “async programming and websockets” indicates that the Rust server handles real-time communication.

##### Relationships and Interactions
- How client-side modules (e.g., components for auth, chat, group settings) trigger asynchronous calls to corresponding backend routes (auth, friend, group routes).
- That the backend parses requests, manages application state, and maintains continuous websocket connections for live chat functionality.

##### Architectural Patterns and Technologies
- Next.js MVC-like structure for the client (pages, components, CSS) that separates UI from data fetching logic.
- Rust’s asynchronous programming model using async/await (possibly via an async framework) to manage concurrent websocket connections and HTTP requests.
- Modular architecture in the backend – different routes handling separate aspects (authentication, friendship, group management).
- Use of templating for server-rendered pages in HTML (login, register, success).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend (Next.js Client)"
        F1["Next.js Client"]:::frontend
        F2["UI Components"]:::frontend
    end

    subgraph "Backend (Rust Server)"
        B1["Server Logic"]:::backend
        B2["Routing Modules"]:::backend
        B3["State Management"]:::backend
        B4["Template Rendering"]:::backend
    end

    WS["WebSocket/Async Communication"]:::communication

    F1 -->|"HTTP/APIcalls"| B1
    F2 -->|"TriggersRoutes"| B2
    F1 -->|"InitiatesWSconnection"| WS
    WS -->|"Real-timeUpdates"| F1
    B1 -->|"HandlesAsyncWS"| WS
    B2 -->|"UpdatesState"| B3
    B1 -->|"RendersPages"| B4

    click F1 "https://github.com/gabrielbarros36/gchat/tree/main/client"
    click F2 "https://github.com/gabrielbarros36/gchat/tree/main/client/src/app/_components"
    click B1 "https://github.com/gabrielbarros36/gchat/blob/main/src/server.rs"
    click B1 "https://github.com/gabrielbarros36/gchat/blob/main/src/client.rs"
    click B2 "https://github.com/gabrielbarros36/gchat/tree/main/src/routes"
    click B3 "https://github.com/gabrielbarros36/gchat/blob/main/src/state.rs"
    click B4 "https://github.com/gabrielbarros36/gchat/tree/main/templates"

    classDef frontend fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef backend fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
    classDef communication fill:#fff9c4,stroke:#f9a825,stroke-width:2px;
```
