# dthengoc/chat-app architecture

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

- Interactive diagram: https://gitdiagram.com/dthengoc/chat-app
- Repository: https://github.com/dthengoc/chat-app

## Overview

##### Project type and purpose
- This is a full-stack (client-centric) real-time chat application built entirely as a React single-page app.
- It uses Firebase Realtime Database for messaging and Cloudinary for image uploads.

##### File structure
- Top-level config:
- package.json / package-lock.json (dependencies, scripts)
- vite.config.js, postcss.config.js, tailwind.config.js, eslint.config.js
- index.html (entry point)
- Public/static: public/
- Source code (src/):
- main.jsx → app bootstrap (ReactDOM.render)
- App.jsx → root component + router or layout
- firebase.js + cloudinary.js → SDK initialization + helper methods
- components/
– context/ChatContext.jsx → React Context for global chat state
– ChatWindow.jsx, Message.jsx, MessageInput.jsx → core UI widgets
– pages/ChatRoom.jsx, Login.jsx → page-level components
- assets/, index.css

##### Review README for additional insights
- Stacks: React 18 + Vite + Tailwind CSS
- Backend services: Firebase Realtime Database (real-time sync) & Cloudinary (image upload)
- No custom server-side code—purely front-end + external BaaS

##### Main components & their relationships
a. React SPA (UI Layer)
– Renders Login, ChatRoom, ChatWindow, Message bubbles, MessageInput
– Holds global state in ChatContext (users, messages, connection status)
b. Firebase Realtime Database (Data Layer)
– Listens for message events (onValue, onChildAdded)
– Writes new messages
c. Cloudinary (Media Storage)
– Exposes REST API for image uploads
– Returns secure URLs saved alongside text messages
d. Optional hosting/CDN (e.g., Vercel)
– Serves bundled assets (output of Vite build)

Data Flow
- User types text or picks image → MessageInput calls Cloudinary API (if image) → receives URL → writes a message object (text + image URL + metadata) to Firebase
- Firebase triggers real-time update → ChatContext subscription pushes new message → ChatWindow re-renders

##### Architectural patterns & design principles
- Client-only “thin client” architecture relying on Backend-as-a-Service
- React + Context API for global state (avoids Redux overhead)
- Event-driven (pub/sub) real-time updates via Firebase SDK
- Separation of concerns:
- cloudinary.js & firebase.js isolate external API logic
- components/ handle pure UI
- context/ handles state orchestration

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "React SPA (Vite/Bundler)"
        direction TB
        indexHTML["index.html"]:::infra
        Main["main.jsx"]:::infra
        indexHTML --> Main
        App["App.jsx"]:::ui
        Main --> App

        subgraph "Configs & Assets"
            direction TB
            Public["public/"]:::infra
            AssetsDir["src/assets"]:::infra
            indexCSS["src/index.css"]:::infra
            packageJSON["package.json / package-lock.json"]:::infra
            viteCFG["vite.config.js"]:::infra
            tailwindCFG["tailwind.config.js"]:::infra
            postCSS["postcss.config.js"]:::infra
            eslintCFG["eslint.config.js"]:::infra
        end

        subgraph "Services Modules"
            direction TB
            FBMod["firebase.js"]:::service
            CLMod["cloudinary.js"]:::service
        end

        subgraph "Context"
            direction TB
            ChatCtx["ChatContext.jsx"]:::state
        end

        subgraph "UI Components"
            direction TB
            Login["Login.jsx"]:::ui
            ChatRoom["ChatRoom.jsx"]:::ui
            ChatWindow["ChatWindow.jsx"]:::ui
            Message["Message.jsx"]:::ui
            MessageInput["MessageInput.jsx"]:::ui
        end

        App --> ChatCtx
        App --> Login
        App --> ChatRoom
        ChatRoom --> ChatWindow
        ChatWindow --> Message
        ChatWindow --> MessageInput
        ChatCtx --> ChatWindow
        ChatCtx --> Message

        MessageInput --> FBMod
        FBMod -->|"write messages"| FirebaseDB
        FirebaseDB -->|"onUpdate"| FBMod
        FBMod --> ChatCtx

        MessageInput --> CLMod
        CLMod -->|"upload images"| CloudinaryAPI
        CLMod --> MessageInput
    end

    subgraph "External Services"
        direction TB
        FirebaseDB["Firebase Realtime Database"]:::external
        CloudinaryAPI["Cloudinary API"]:::external
    end

    Hosting["Hosting/CDN (Vercel/Netlify)"]:::infra
    Hosting --> indexHTML

    click Main "https://github.com/dthengoc/chat-app/blob/master/src/main.jsx"
    click App "https://github.com/dthengoc/chat-app/blob/master/src/App.jsx"
    click FBMod "https://github.com/dthengoc/chat-app/blob/master/src/firebase.js"
    click CLMod "https://github.com/dthengoc/chat-app/blob/master/src/cloudinary.js"
    click ChatCtx "https://github.com/dthengoc/chat-app/blob/master/src/components/context/ChatContext.jsx"
    click ChatRoom "https://github.com/dthengoc/chat-app/blob/master/src/components/pages/ChatRoom.jsx"
    click Login "https://github.com/dthengoc/chat-app/blob/master/src/components/pages/Login.jsx"
    click ChatWindow "https://github.com/dthengoc/chat-app/blob/master/src/components/ChatWindow.jsx"
    click Message "https://github.com/dthengoc/chat-app/blob/master/src/components/Message.jsx"
    click MessageInput "https://github.com/dthengoc/chat-app/blob/master/src/components/MessageInput.jsx"
    click Public "https://github.com/dthengoc/chat-app/tree/master/public/"
    click AssetsDir "https://github.com/dthengoc/chat-app/tree/master/src/assets"
    click indexCSS "https://github.com/dthengoc/chat-app/blob/master/src/index.css"
    click indexHTML "https://github.com/dthengoc/chat-app/blob/master/index.html"
    click viteCFG "https://github.com/dthengoc/chat-app/blob/master/vite.config.js"
    click tailwindCFG "https://github.com/dthengoc/chat-app/blob/master/tailwind.config.js"
    click postCSS "https://github.com/dthengoc/chat-app/blob/master/postcss.config.js"
    click eslintCFG "https://github.com/dthengoc/chat-app/blob/master/eslint.config.js"
    click packageJSON "https://github.com/dthengoc/chat-app/blob/master/package.json / package-lock.json"

    classDef ui fill:#E0F7FA,stroke:#0288D1,stroke-width:1px
    classDef state fill:#C8E6C9,stroke:#2E7D32,stroke-width:1px
    classDef service fill:#A5D6A7,stroke:#388E3C,stroke-width:1px
    classDef external fill:#FFE0B2,stroke:#F57C00,stroke-width:1px
    classDef infra fill:#E1BEE7,stroke:#6A1B9A,stroke-width:1px
```
