# balasubramaniam12007/chattr architecture

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

- Interactive diagram: https://gitdiagram.com/balasubramaniam12007/chattr
- Repository: https://github.com/balasubramaniam12007/chattr

## Overview

##### Project type and purpose
- Chattr is a full-stack, real-time chat application.
- Frontend: React 18 Single Page App (SPA) built with Vite and styled with Tailwind CSS.
- Backend: Supabase (PostgreSQL database + Auth + Real-time subscriptions + Storage).
- Purpose: Enable authenticated users to chat in real time, manage profiles (avatars, bio), see presence, and handle read receipts.

##### File structure
- Top-level config/build files:
- vite.config.js, tailwind.config.js, postcss.config.js, eslint.config.js
- package.json / package-lock.json define dependencies (React, React Router, Lucide, etc.)
- public/index.html is the SPA entry point.
- src/
- App.jsx, main.jsx: bootstrap React app and routing.
- components/: reusable UI (ChatWindow, ChatMessage, ConversationList, UserProfilesBar, ProtectedRoute).
- pages/: route targets (Auth.jsx, Chat.jsx, NotFound.jsx, ProfileFormModal.jsx).
- contexts/AuthContext.jsx: global auth/user state.
- utils/supabase.js: initializes Supabase client (URL + anon key).
- assets/, styles (App.css, index.css).
- There is no custom backend code—everything uses Supabase as a BaaS.

##### Key insights from README
- Real-time messaging via Supabase subscriptions.
- RLS policies on profiles, conversations, messages.
- Supabase Storage used for avatar uploads.
- ProtectedRoute component ensures only authenticated users access chat/profile pages.
- Mobile-first responsive design and UI behaviors (auto-scroll, typing indicators).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Browser (Frontend)"
        direction TB
        Main["src/main.jsx"]:::frontend
        App["src/App.jsx"]:::frontend
        AuthContext["src/contexts/AuthContext.jsx"]:::frontend
        SupabaseClient["src/utils/supabase.js"]:::frontend
        ProtectedRoute["src/components/ProtectedRoute.jsx"]:::frontend
        subgraph "UI Components"
            direction TB
            ChatWindow["src/components/ChatWindow.jsx"]:::frontend
            ChatMessage["src/components/ChatMessage.jsx"]:::frontend
            ConversationList["src/components/ConversationList.jsx"]:::frontend
            UserProfilesBar["src/components/UserProfilesBar.jsx"]:::frontend
        end
        subgraph "Pages"
            direction TB
            AuthPage["src/pages/Auth.jsx"]:::frontend
            ChatPage["src/pages/Chat.jsx"]:::frontend
            ProfileModal["src/pages/ProfileFormModel.jsx"]:::frontend
            NotFound["src/pages/NotFound.jsx"]:::frontend
        end
        Main -->|bootsraps| App
        App -->|uses Routing| AuthPage
        App --> ChatPage
        App --> NotFound
        App --> ProfileModal
        App --> ProtectedRoute
        App --> AuthContext
        AuthContext --> SupabaseClient
        App --> ChatWindow
        ChatWindow --> ConversationList
        ChatWindow --> ChatMessage
        ChatWindow --> UserProfilesBar
    end

    %% Supabase Services Layer
    subgraph "Supabase Backend" 
        direction TB
        AuthService["Supabase Auth"]:::supabase
        Realtime["Supabase Realtime"]:::supabase
        Storage["Supabase Storage"]:::db
        Database["Supabase PostgreSQL"]:::db
    end

    %% Build & Config
    subgraph "Build & Config Tools"
        direction TB
        ViteConfig["vite.config.js"]:::tool
        TailwindConfig["tailwind.config.js"]:::tool
        PostCSS["postcss.config.js"]:::tool
        ESLint["eslint.config.js"]:::tool
        Package["package.json / package-lock.json"]:::tool
        HTML["public/index.html"]:::tool
        Assets["src/assets"]:::tool
        StylesGlobal["src/index.css"]:::tool
        StylesApp["src/App.css"]:::tool
    end

    %% Interactions
    App -->|"login/register, token"| AuthService
    App -->|"CRUD profiles, messages"| Database
    SupabaseClient --> AuthService
    SupabaseClient --> Database
    SupabaseClient --> Realtime
    SupabaseClient --> Storage
    App --> SupabaseClient
    App --> Database
    App --> Realtime
    App --> Storage

    %% Database policies annotation
    Database -.->|"RLS policies enforced"| Database

    %% Click Events
    click Main "https://github.com/balasubramaniam12007/chattr/blob/main/src/main.jsx"
    click App "https://github.com/balasubramaniam12007/chattr/blob/main/src/App.jsx"
    click AuthContext "https://github.com/balasubramaniam12007/chattr/blob/main/src/contexts/AuthContext.jsx"
    click SupabaseClient "https://github.com/balasubramaniam12007/chattr/blob/main/src/utils/supabase.js"
    click ProtectedRoute "https://github.com/balasubramaniam12007/chattr/blob/main/src/components/ProtectedRoute.jsx"
    click ChatWindow "https://github.com/balasubramaniam12007/chattr/blob/main/src/components/ChatWindow.jsx"
    click ChatMessage "https://github.com/balasubramaniam12007/chattr/blob/main/src/components/ChatMessage.jsx"
    click ConversationList "https://github.com/balasubramaniam12007/chattr/blob/main/src/components/ConversationList.jsx"
    click UserProfilesBar "https://github.com/balasubramaniam12007/chattr/blob/main/src/components/UserProfilesBar.jsx"
    click AuthPage "https://github.com/balasubramaniam12007/chattr/blob/main/src/pages/Auth.jsx"
    click ChatPage "https://github.com/balasubramaniam12007/chattr/blob/main/src/pages/Chat.jsx"
    click ProfileModal "https://github.com/balasubramaniam12007/chattr/blob/main/src/pages/ProfileFormModel.jsx"
    click NotFound "https://github.com/balasubramaniam12007/chattr/blob/main/src/pages/NotFound.jsx"
    click StylesGlobal "https://github.com/balasubramaniam12007/chattr/blob/main/src/index.css"
    click StylesApp "https://github.com/balasubramaniam12007/chattr/blob/main/src/App.css"
    click ViteConfig "https://github.com/balasubramaniam12007/chattr/blob/main/vite.config.js"
    click TailwindConfig "https://github.com/balasubramaniam12007/chattr/blob/main/tailwind.config.js"
    click PostCSS "https://github.com/balasubramaniam12007/chattr/blob/main/postcss.config.js"
    click ESLint "https://github.com/balasubramaniam12007/chattr/blob/main/eslint.config.js"
    click Package "https://github.com/balasubramaniam12007/chattr/blob/main/package.json / package-lock.json"
    click HTML "https://github.com/balasubramaniam12007/chattr/blob/main/public/index.html"
    click Assets "https://github.com/balasubramaniam12007/chattr/tree/main/src/assets"

    %% Styles
    classDef frontend fill:#CCE5FF,stroke:#005B99,color:#000
    classDef supabase fill:#DFF2E1,stroke:#2E7D32,color:#000
    classDef db fill:#FFE5B4,stroke:#E65100,color:#000
    classDef tool fill:#F0F0F0,stroke:#666,color:#000
```
