# waqar741/fintrac architecture

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

- Interactive diagram: https://gitdiagram.com/waqar741/fintrac
- Repository: https://github.com/waqar741/fintrac

## Overview

##### Project Type & Purpose
- FinTrac is a full-stack, single-page web application for personal finance tracking.
- Frontend: React + TypeScript + Vite + Tailwind CSS, with client-side routing and contexts (AuthContext, ThemeContext).
- Backend: Supabase (hosted Postgres, Auth, real-time, storage, migrations).

##### File-Structure Analysis
- src/: React app entry (main.tsx, App.tsx), components (AIChat, Layout, ProtectedRoute), contexts, pages (Dashboard, Transactions, Goals, etc.), and supabase client wrapper (src/lib/supabase.ts).
- supabase/migrations/: SQL files that define and evolve the database schema.
- Config files: vite.config.ts, tailwind.config.js, tsconfig*.json, vercel.json for deployment.

##### README Insights
- Although the README is minimal, the presence of Supabase migrations plus a complete React directory implies a BaaS-backed SPA with authentication, data storage, and real-time features.

a. Main Components
- Browser Client (SPA)
- CI/CD & Hosting (Vercel)
- Supabase Backend Services
- Auth Service
- Postgres Database (with migrations)
- Real-time (WS)
- Storage (if used for images)
b. Relationships & Data Flows
1. User ↔ Browser UI (React + Tailwind)
2. UI → Vercel (static asset hosting)
3. UI → Supabase Auth (signup, login)
4. Authenticated UI → Supabase Postgres API (CRUD for accounts, transactions, goals, group expenses)
5. Real-time updates via Supabase subscriptions
6. Supabase migrations manage schema lifecycle
c. Architectural Patterns & Principles
- SPA with client-side routing (React Router in ProtectedRoute)
- Context API for cross-cutting concerns (auth state, theming)
- BaaS integration: no custom backend servers, direct client-to-Supabase comms
- Infrastructure-as-Code via migration scripts
d. Key Technologies
- React, TypeScript, Vite (dev server & bundler)
- Tailwind CSS
- Supabase client library (src/lib/supabase.ts)
- Vercel for CI/CD and global CDN hosting

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer" 
        direction TB
        BrowserClient["Browser Client\n(React SPA)"]:::frontend
        SupabaseWrapper["Supabase Client Wrapper\n(src/lib/supabase.ts)"]:::frontend
        subgraph "SPA Core"
            direction TB
            AppEntry["Entry Points\nmain.tsx, App.tsx, index.html"]:::frontend
            ProtectedRoute["ProtectedRoute"]:::frontend
            LayoutComp["Layout"]:::frontend
            AIChat["AIChat Widget"]:::frontend
            AuthCtx["AuthContext"]:::frontend
            ThemeCtx["ThemeContext"]:::frontend
            subgraph "Pages"
                direction TB
                Dashboard["Dashboard"]:::frontend
                Transactions["Transactions"]:::frontend
                Accounts["Accounts"]:::frontend
                Goals["Goals"]:::frontend
                GroupExpenses["Group Expenses"]:::frontend
                DebtsCredits["Debts & Credits"]:::frontend
                Analytics["Analytics"]:::frontend
                Settings["Settings"]:::frontend
                Login["Login"]:::frontend
                SignUp["Sign Up"]:::frontend
            end
        end
        BrowserClient -->|loads| AppEntry
        AppEntry --> ProtectedRoute
        ProtectedRoute --> LayoutComp
        LayoutComp --> AIChat
        LayoutComp --> AuthCtx
        LayoutComp --> ThemeCtx
        LayoutComp --> Pages
        Pages -->|uses| SupabaseWrapper
    end

    %% Deployment Layer
    subgraph "CI/CD & Hosting" 
        direction TB
        Vercel["Vercel CDN & CI/CD"]:::infra
        DevEnv["Vite Dev Server"]:::infra
        ConfigFiles["Configs\nvite.config.ts\ntailwind.config.js\ntsconfig*.json\n.env.example\npackage.json"]:::infra
    end
    AppEntry -->|dev build| DevEnv
    AppEntry -->|prod deploy| Vercel
    DevEnv --> ConfigFiles
    Vercel --> ConfigFiles

    %% Supabase Backend
    subgraph "Supabase Backend Services"
        direction TB
        AuthService["Supabase Auth"]:::backend
        PostgresAPI["Postgres API"]:::backend
        Realtime["Realtime (WS)"]:::backend
        Storage["Storage"]:::backend
        subgraph "Migrations"
            direction TB
            Migrations["SQL Migrations"]:::db
        end
        PostgresAPI -->|reads/writes| DB[(Postgres DB)]:::db
        Migrations -->|manages schema| DB
    end

    %% Data Flows
    BrowserClient -->|HTTPS| AuthService
    BrowserClient -->|HTTPS| PostgresAPI
    BrowserClient -->|WebSocket| Realtime
    BrowserClient -->|HTTPS| Storage

    %% Click Events
    click AppEntry "https://github.com/waqar741/fintrac/blob/main/src/main.tsx"
    click AppEntry "https://github.com/waqar741/fintrac/blob/main/src/App.tsx"
    click ProtectedRoute "https://github.com/waqar741/fintrac/blob/main/src/components/ProtectedRoute.tsx"
    click LayoutComp "https://github.com/waqar741/fintrac/blob/main/src/components/Layout.tsx"
    click AIChat "https://github.com/waqar741/fintrac/blob/main/src/components/AIChat.tsx"
    click AuthCtx "https://github.com/waqar741/fintrac/blob/main/src/contexts/AuthContext.tsx"
    click ThemeCtx "https://github.com/waqar741/fintrac/blob/main/src/contexts/ThemeContext.tsx"
    click Dashboard "https://github.com/waqar741/fintrac/blob/main/src/pages/Dashboard.tsx"
    click Transactions "https://github.com/waqar741/fintrac/blob/main/src/pages/Transactions.tsx"
    click Accounts "https://github.com/waqar741/fintrac/blob/main/src/pages/Accounts.tsx"
    click Goals "https://github.com/waqar741/fintrac/blob/main/src/pages/Goals.tsx"
    click GroupExpenses "https://github.com/waqar741/fintrac/blob/main/src/pages/GroupExpenses.tsx"
    click DebtsCredits "https://github.com/waqar741/fintrac/blob/main/src/pages/DebtsCredits.tsx"
    click Analytics "https://github.com/waqar741/fintrac/blob/main/src/pages/Analytics.tsx"
    click Settings "https://github.com/waqar741/fintrac/blob/main/src/pages/Settings.tsx"
    click Login "https://github.com/waqar741/fintrac/blob/main/src/pages/Login.tsx"
    click SignUp "https://github.com/waqar741/fintrac/blob/main/src/pages/SignUp.tsx"
    click SupabaseWrapper "https://github.com/waqar741/fintrac/blob/main/src/lib/supabase.ts"
    click Migrations "https://github.com/waqar741/fintrac/blob/main/supabase/migrations/*.sql"
    click ConfigFiles "https://github.com/waqar741/fintrac/blob/main/vite.config.ts"
    click ConfigFiles "https://github.com/waqar741/fintrac/blob/main/tailwind.config.js"
    click ConfigFiles "https://github.com/waqar741/fintrac/blob/main/tsconfig.json"
    click ConfigFiles "https://github.com/waqar741/fintrac/blob/main/tsconfig.app.json"
    click ConfigFiles "https://github.com/waqar741/fintrac/blob/main/tsconfig.node.json"
    click ConfigFiles "https://github.com/waqar741/fintrac/blob/main/.env.example"
    click ConfigFiles "https://github.com/waqar741/fintrac/blob/main/package.json"
    click ConfigFiles "https://github.com/waqar741/fintrac/blob/main/package-lock.json"
    click Vercel "https://github.com/waqar741/fintrac/blob/main/vercel.json"

    %% Styles
    classDef frontend fill:#D2E8FF,stroke:#3399FF,color:#000
    classDef infra fill:#FFF4BF,stroke:#FFCC00,color:#000
    classDef backend fill:#DFF2D8,stroke:#28A745,color:#000
    classDef db fill:#E0E0E0,stroke:#888888,color:#000
```
