# tanuj0071/chatgpt-clone architecture

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

- Interactive diagram: https://gitdiagram.com/tanuj0071/chatgpt-clone
- Repository: https://github.com/tanuj0071/chatgpt-clone

## Overview

##### Project type and purpose
- This is a full-stack web application built with Python/Flask on the backend and a static HTML/CSS/JavaScript frontend.
- It serves as a ChatGPT-style chat interface that proxies user messages to the OpenRouter API (GPT-3.5-turbo) and returns AI-generated responses in real time.

##### File structure
- Top-level files:
- main.py – Flask application entry point
- package.json & package-lock.json + node_modules – Frontend build dependencies (Tailwind CSS, any JS libraries)
- tailwind.config.js + static/ – Static assets for styling (CSS) and behavior (JS)
- templates/index.html – HTML template served by Flask
- No database or persistent storage present: the app is stateless beyond the API integration.
- Key external dependency: OpenRouter API.

##### README for additional insights
- Confirms Flask backend, Tailwind CSS frontend, OpenRouter integration.
- No mention of additional microservices or data stores.
- Ready for deployment on Python-friendly PaaS (Heroku, Vercel, etc.).

##### Main components and interactions
a. Components
- Web Browser (Client)
- Static Asset Server (serving CSS/JS via Flask’s static route or CDN)
- Flask Web Server
- OpenRouter External API
b. Relationships / Data flow
1. User types a message in the chat UI (index.html + script.js).
2. script.js issues an HTTP POST to Flask endpoint (/api/chat or root).
3. Flask receives request in main.py, packages it, calls OpenRouter API over HTTPS.
4. OpenRouter responds with AI-generated text.
5. Flask forwards that response back to the browser as JSON.
6. script.js updates the DOM to display the chat reply.
c. Architectural patterns/design principles
- Single back-end service (monolithic Flask app)
- Separation of concerns: static frontend assets vs. dynamic API logic
- External API integration as a façade pattern
- Client-server interaction via RESTful HTTP calls (or AJAX/fetch)
d. Technologies and libraries
- Flask (Python) – HTTP server, routing, template rendering
- Jinja2 – template engine for index.html
- Tailwind CSS – utility-first styling
- Vanilla JavaScript (or any small JS lib) – AJAX requests and DOM updates
- OpenRouter API – external AI model service

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (Client)"
        direction TB
        Browser["Web Browser UI\n(index.html)"]:::frontend
        StaticServer["Static Asset Server\n(static/)"]:::frontend
        CSS1["CSS File\nmain.css"]:::frontend
        CSS2["CSS File\ninput.css"]:::frontend
        JS["JS Script\nscript.js"]:::frontend
        PackageJSON["package.json"]:::frontend
        NodeModules["node_modules/"]:::frontend
        TailwindConfig["tailwind.config.js"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Server"
        direction TB
        Flask["Flask App\nmain.py"]:::backend
        APIClient["OpenRouter Integration\n(in main.py)"]:::backend
    end

    %% External Service
    OpenRouter["OpenRouter API"]:::external

    %% Data Flows
    Browser -->|"GET /"| Flask
    Browser -->|"loads assets"| StaticServer
    StaticServer -->|"serves CSS"| CSS1
    StaticServer -->|"serves CSS"| CSS2
    StaticServer -->|"serves JS"| JS
    JS -->|"POST /api/chat"| Flask
    Flask -->|"POST /v1/chat/completions"| OpenRouter
    OpenRouter -->|"200 OK with JSON"| Flask
    Flask -->|"200 OK JSON"| JS
    JS -->|"update DOM"| Browser

    %% Click Events
    click Browser "https://github.com/tanuj0071/chatgpt-clone/blob/master/templates/index.html"
    click JS "https://github.com/tanuj0071/chatgpt-clone/blob/master/static/js/script.js"
    click CSS1 "https://github.com/tanuj0071/chatgpt-clone/blob/master/static/css/main.css"
    click CSS2 "https://github.com/tanuj0071/chatgpt-clone/blob/master/static/css/input.css"
    click StaticServer "https://github.com/tanuj0071/chatgpt-clone/tree/master/static/"
    click Flask "https://github.com/tanuj0071/chatgpt-clone/blob/master/main.py"
    click TailwindConfig "https://github.com/tanuj0071/chatgpt-clone/blob/master/tailwind.config.js"
    click PackageJSON "https://github.com/tanuj0071/chatgpt-clone/blob/master/package.json"
    click NodeModules "https://github.com/tanuj0071/chatgpt-clone/tree/master/node_modules/"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#F5DEB3,stroke:#333,stroke-width:1px
```
