# prottoy-bhattacharyya/chat-web-app architecture

> Architecture diagram of the GitHub repository prottoy-bhattacharyya/chat-web-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/prottoy-bhattacharyya/chat-web-app
- Repository: https://github.com/prottoy-bhattacharyya/chat-web-app

## Overview

##### Project Type & Purpose
- This is a full-stack Python web application (likely Flask) providing real-time chat between users plus an AI assistant powered by the local `meta_llama_AI.py` module.
- It persists users, friend relationships, and chat history in a MySQL database.
- It serves HTML templates for UI and static assets (CSS, JS, images).

##### File-Structure Analysis
- Top-level “app.py” contains the Flask (or uv/uvicorn) application entry point and route/controller logic.
- “meta_llama_AI.py” encapsulates the AI assistant integration.
- “DBconfig.py” holds the MySQL connection logic.
- “templates/” holds Jinja2 HTML views (login, chat, profile, AI chat, etc.).
- “static/” holds CSS, JS, images for the frontend.

##### Key Components
a. Frontend (Web Clients)
- Browser instances on user devices
- Static assets: CSS (front_page.css, login.css), JS (showpass.js)
b. Web Server / API Layer
- app.py: HTTP routes for auth, chat pages, friend operations
- WebSocket or long-polling endpoint for “real-time” messaging (if used)
- AI-chat endpoint invoking `meta_llama_AI.py`
c. AI Assistant
- `meta_llama_AI.py` module
- (Optionally) underlying Llama weights or external AI process
d. Database
- MySQL server
- DBconfig.py managing connections
- Tables: users, friends, messages, AI_history

##### Relationships & Data Flows
- Browser → HTTP(S) → Flask app (app.py) → Templates/Static → Browser
- Browser ↔ WebSocket (or AJAX polling) ↔ Flask app → MySQL
- Flask app → AI module → AI response → Flask app → Browser
- Flask app → MySQL (via DBconfig.py) for CRUD on users/messages

##### Architectural Patterns & Principles
- MVC-style separation:
- Models: MySQL + DBconfig.py
- Views: Jinja2 templates under /templates
- Controllers: Route handlers in app.py
- Single-process monolith—can scale by separating AI engine or DB as microservices
- Configuration externalized in DBconfig.py and environment variables

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (Blue)" 
        direction TB
        Browser["Web Browser"]:::frontend
        StaticAssets["Static Assets"]:::frontend
        click StaticAssets "https://github.com/prottoy-bhattacharyya/chat-web-app/tree/main/static/"
    end

    %% Backend Layer
    subgraph "Backend (Green)"
        direction TB
        App["Flask App\n(app.py)"]:::backend
        click App "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/app.py"
        DBConfig["DB Config\n(DBconfig.py)"]:::backend
        click DBConfig "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/DBconfig.py"
        subgraph "Templates" 
            direction TB
            Login["login.html"]:::backend
            click Login "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/templates/login.html"
            Signup["signup.html"]:::backend
            click Signup "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/templates/signup.html"
            FrontPageT["front_page.html"]:::backend
            click FrontPageT "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/templates/front_page.html"
            Home["home.html"]:::backend
            click Home "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/templates/home.html"
            Chat["chat.html"]:::backend
            click Chat "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/templates/chat.html"
            AIChat["aiChat.html"]:::backend
            click AIChat "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/templates/aiChat.html"
            AddFriend1["add_friend.html"]:::backend
            click AddFriend1 "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/templates/add_friend.html"
            AddFriend2["add_friend2.html"]:::backend
            click AddFriend2 "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/templates/add_friend2.html"
            FriendReq1["friend_request.html"]:::backend
            click FriendReq1 "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/templates/friend_request.html"
            FriendReq2["friend_request2.html"]:::backend
            click FriendReq2 "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/templates/friend_request2.html"
            SearchFriend["search_friend.html"]:::backend
            click SearchFriend "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/templates/search_friend.html"
            Admin["admin.html"]:::backend
            click Admin "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/templates/admin.html"
            Error1["error.html"]:::backend
            click Error1 "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/templates/error.html"
            Error2["error2.html"]:::backend
            click Error2 "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/templates/error2.html"
        end
    end

    %% AI Module
    subgraph "AI Module (Purple)"
        direction TB
        AI["meta_llama_AI.py"]:::ai
        click AI "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/meta_llama_AI.py"
    end

    %% Database Layer
    subgraph "Database (Orange)"
        direction TB
        MySQL["MySQL Database"]:::database
    end

    %% Project Metadata & Misc
    subgraph "Project Files"
        direction TB
        PyProject["pyproject.toml"]:::misc
        click PyProject "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/pyproject.toml"
        PythonVersion[".python-version"]:::misc
        click PythonVersion "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/.python-version"
        Commands["commands.bash"]:::misc
        click Commands "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/commands.bash"
        TempCode["tempCodeRunnerFile.py"]:::misc
        click TempCode "https://github.com/prottoy-bhattacharyya/chat-web-app/blob/main/tempCodeRunnerFile.py"
    end

    %% Connections
    Browser -->|"HTTP requests / WebSocket"| App
    Browser -->|"Requests static assets"| StaticAssets
    App -->|"Serves templates"| Login
    App -->|"Serves templates"| Signup
    App -->|"Serves templates"| FrontPageT
    App -->|"Serves templates"| Home
    App -->|"Serves templates"| Chat
    App -->|"Serves templates"| AIChat
    App -->|"Serves templates"| AddFriend1
    App -->|"Serves templates"| AddFriend2
    App -->|"Serves templates"| FriendReq1
    App -->|"Serves templates"| FriendReq2
    App -->|"Serves templates"| SearchFriend
    App -->|"Serves templates"| Admin
    App -->|"Serves templates"| Error1
    App -->|"Serves templates"| Error2

    App -->|"SQL queries (users, messages, AI_history)"| MySQL
    App -->|"uses DB config"| DBConfig
    App -->|"Generate AI response"| AI
    AI -->|"AI answer payload"| App

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#0D47A1,color:#0D47A1;
    classDef backend fill:#C8E6C9,stroke:#1B5E20,color:#1B5E20;
    classDef database fill:#FFE0B2,stroke:#E65100,color:#E65100;
    classDef ai fill:#E1BEE7,stroke:#6A1B9A,color:#6A1B9A;
    classDef misc fill:#ECEFF1,stroke:#455A64,color:#455A64;
```
