# rishabh10gpt/chatter architecture

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

## Overview

##### Project Type and Purpose
- The application is a full-stack, real-time chat system that pairs users based on common tags.
- It focuses on WebSocket connections for real-time communication, auto-reconnect features, and capturing geo-location and browser info.
- The stack mainly includes Python (FastAPI, Uvicorn) on the backend and HTML/CSS/JavaScript on the frontend.

##### Main Components to Identify
a. Frontend:
- Represented by the static files (chat.js, styles.css) and the HTML template (index.html).
- This component handles the user interface and client-side JavaScript for managing WebSocket connections.
b. Backend:
- Located in the app directory (main.py, __init__.py).
- Serves the API endpoints, manages WebSocket connections, and performs tag-based matching.
- Uses FastAPI to configure routes and middlewares.
c. WebSocket Server:
- Although part of the backend, highlight the dedicated handling of WebSocket connections for real-time communication.
d. External Dependencies:
- Uvicorn for running the ASGI server.
- The “requests” library used for IP-based geolocation information.
- That these are integral to starting the application and managing external calls.

##### Relationships and Interactions
- The browser (client) sending HTTP requests and WebSocket upgrade requests to the Backend.
- The client connecting to the WebSocket server for bi-directional messaging.
- The backend communicating with external APIs (for geolocation, for instance) and handling tag-based matches.

##### Architectural Patterns & Design Principles
- Separation between frontend and backend.
- Real-time event-driven communication via WebSockets.
- Modular design by differentiating the static assets, templates, and server routes.
- Mention how auto-reconnect and error handling should be visualized as part of the WebSocket management.

##### Technologies and Frameworks
- “FastAPI” for backend with WebSocket support.
- “Uvicorn” for serving the application.
- “HTML, CSS, JavaScript” on the frontend side.
- Optionally, capture Python version dependency and any other key details from requirements.txt.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Side"
        Browser("Browser"):::frontend
        IT("HTML Template"):::frontend
        JS("Chat JS"):::frontend
        CSS("Styles CSS"):::frontend
    end

    subgraph "Server Side"
        MA("FastAPI Server"):::backend
        INIT("Init File"):::backend
    end

    ExternalDep("Dependencies"):::external

    Browser -->|"HTTPRequest"| IT
    Browser -->|"LoadCSS"| CSS
    Browser -->|"LoadJS"| JS
    JS -->|"WebSocketConnection_AutoReconnect"| MA
    MA ---|"Routes/WebSocketHandling"| INIT
    MA -->|"GeoLocationAPICall"| ExternalDep

    click IT "https://github.com/rishabh10gpt/chatter/blob/main/templates/index.html"
    click JS "https://github.com/rishabh10gpt/chatter/blob/main/static/chat.js"
    click CSS "https://github.com/rishabh10gpt/chatter/blob/main/static/styles.css"
    click MA "https://github.com/rishabh10gpt/chatter/blob/main/app/main.py"
    click INIT "https://github.com/rishabh10gpt/chatter/blob/main/app/__init__.py"
    click ExternalDep "https://github.com/rishabh10gpt/chatter/blob/main/requirements.txt"

    classDef frontend fill:#F9C,stroke:#333,stroke-width:2px,color:#000;
    classDef backend fill:#BBF,stroke:#333,stroke-width:2px,color:#000;
    classDef external fill:#AFA,stroke:#333,stroke-width:2px,color:#000;
```
