# mihir-28/kittypay architecture

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

- Interactive diagram: https://gitdiagram.com/mihir-28/kittypay
- Repository: https://github.com/mihir-28/kittypay

## Overview

##### Project Type and Purpose
- KittyPay is a client-heavy, full-stack Progressive Web App (PWA) for splitting group expenses.
- The entire frontend is a React single-page application (SPA) built with Vite, styled with Tailwind CSS, and deployed on Netlify.
- The “backend” is a serverless Firebase suite: Authentication, Firestore, Cloud Functions, Storage, and Analytics.

##### File Structure Analysis
- Top-level files: configuration (.env.example, vite.config.js), Firebase setup (firestore.rules, FIREBASE_SETUP.md), public assets, and index.html.
- src/ directory:
- App entry (main.jsx, App.jsx)
- Components (feature folders: common, dashboard, pages, ui, layouts, contexts)
- Firebase integration helpers (src/firebase/*)
- Service worker tests (src/sw-test.js)
- Third-party service adapters (src/services/github.js)
- This structure signals a client-only codebase orchestrating service calls against Firebase.

##### README Insights
- Tech stack: React 18+, Vite, Tailwind, Framer Motion, Recharts, React Router, Context API.
- Firebase roles: Auth, Firestore DB, Storage, Functions, Security Rules, Analytics.
- PWA support: service worker, offline caching, install prompts.
- Deployment: Netlify CI/CD.

a. Main Components
- Client/browser layer
- React SPA (App.jsx → Routes → Page Components)
- UI components (Navbar, Footer, DashboardTabs, etc.)
- Service Worker (offline caching, sync)
- Application logic
- React Contexts (AuthContext)
- Data fetching modules (src/firebase/*.js)
- Business-logic services (expense settlement algos in kitties.js)
- External Services
- Firebase Auth (email/password + Google)
- Firebase Firestore (realtime DB for kitties, expenses, members)
- Firebase Cloud Functions (member management, settlements)
- Firebase Cloud Storage (receipt images, profile pics)
- Firebase Google Analytics
- GitHub API (optional: src/services/github.js)
- Hosting & CI/CD
- Netlify (build & deploy)
- CDN for static assets (Netlify or public folder)

b. Relationships & Data Flows
- User interactions in the browser trigger React Router navigations and component renders.
- Components call Firebase helper modules over HTTPS / WebSocket (Firestore SDK) to read/write data.
- Auth flows communicate with Firebase Auth endpoints, sending tokens that guard Firestore rules.
- Service Worker intercepts network requests to cache assets and data, enabling offline mode and sync.
- Analytics events are emitted to Google Analytics via Firebase SDK.
- Build pipeline: Vite compiles React code → Netlify deploys optimized bundle → users fetch index.html + JS/CSS.

c. Architectural Patterns & Principles
- SPA Pattern (React Router for client-side routing)
- Serverless Backend (Firebase as BaaS)
- Context-driven state management (AuthContext, Theme toggle)
- PWA design (Service Worker, manifest.json, offline first)
- Modular component architecture (feature folders, common vs. dashboard vs. pages)

d. Key Technologies
- Frontend: React, Tailwind CSS, Framer Motion, Recharts
- Build & Bundling: Vite
- Routing: React Router v6
- State: React Context API & Hooks
- Backend as a Service: Firebase (Auth, Firestore, Storage, Functions, Analytics)
- Hosting: Netlify

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client / Browser Layer
    subgraph "Client / Browser" 
        direction TB
        ReactSPA["React SPA"]:::client
        ServiceWorker["Service Worker"]:::pwa
    end

    subgraph "UI Components" 
        direction TB
        Navbar["Navbar"]:::client
        LeftNav["Left-Aligned Navbar"]:::client
        Footer["Footer"]:::client
        ThemeToggle["Theme Toggle"]:::client
        PWAInstall["PWA Install Prompt"]:::client
    end

    subgraph "Pages / Routes"
        direction TB
        Home["Home Page"]:::client
        DashboardPage["Dashboard Page"]:::client
        KittiesPage["Kitties Page"]:::client
        Login["Login Page"]:::client
        Signup["Signup Page"]:::client
        Profile["Profile Page"]:::client
        Contact["Contact Page"]:::client
        Roadmap["Roadmap Page"]:::client
        Policy["Policy Page"]:::client
        Terms["Terms Page"]:::client
    end

    subgraph "Application Logic"
        direction TB
        AuthContext["Authentication Context"]:::client
        ProtectedRoute["ProtectedRoute"]:::client
        RouteTracker["Route Tracker"]:::client
        ScrollTop["ScrollToTop"]:::client
        FirebaseConfig["Firebase Config"]:::backend
        AuthHelper["Auth Helpers"]:::backend
        KittiesLogic["Firestore Kitties Logic"]:::backend
        AnalyticsAdapter["Analytics Adapter"]:::backend
        GitHubAdapter["GitHub API Adapter"]:::backend
    end

    subgraph "External Services"
        direction TB
        FirebaseAuth["Firebase Auth"]:::backend
        FirestoreDB["Firestore Database"]:::backend
        CloudFunctions["Cloud Functions"]:::backend
        CloudStorage["Cloud Storage"]:::backend
        Analytics["Google Analytics"]:::backend
        GitHubAPI["GitHub API"]:::backend
    end

    subgraph "Hosting & CI/CD"
        direction TB
        ViteBuild["Vite Build"]:::infra
        Netlify["Netlify"]:::infra
        CDN["CDN / Static Assets"]:::infra
    end

    %% Connections
    ReactSPA -->|uses| Navbar
    ReactSPA -->|uses| LeftNav
    ReactSPA -->|uses| Footer
    ReactSPA -->|uses| ThemeToggle
    ReactSPA -->|uses| PWAInstall

    ReactSPA -->|routes to| Home
    ReactSPA -->|routes to| DashboardPage
    ReactSPA -->|routes to| KittiesPage
    ReactSPA -->|routes to| Login
    ReactSPA -->|routes to| Signup
    ReactSPA -->|routes to| Profile
    ReactSPA -->|routes to| Contact
    ReactSPA -->|routes to| Roadmap
    ReactSPA -->|routes to| Policy
    ReactSPA -->|routes to| Terms

    ReactSPA -->|wraps| AuthContext
    AuthContext -->|protects| ProtectedRoute
    ReactSPA -->|tracks| RouteTracker
    ReactSPA -->|scrolls| ScrollTop

    ReactSPA -->|calls| FirebaseConfig
    ReactSPA -->|calls| AuthHelper
    ReactSPA -->|calls| KittiesLogic
    ReactSPA -->|calls| AnalyticsAdapter
    ReactSPA -->|calls| GitHubAdapter

    ServiceWorker -->|caches| CDN
    ServiceWorker -->|syncs offline| FirestoreDB

    FirebaseConfig --> FirebaseAuth
    AuthHelper --> FirebaseAuth
    KittiesLogic --> FirestoreDB
    KittiesLogic --> CloudFunctions
    AnalyticsAdapter --> Analytics
    GitHubAdapter --> GitHubAPI

    ViteBuild -->|deploys| Netlify
    Netlify -->|hosts| CDN
    CDN -->|serves| ReactSPA

    %% Click events
    click ReactSPA "https://github.com/mihir-28/kittypay/blob/master/src/main.jsx"
    click ReactSPA "https://github.com/mihir-28/kittypay/blob/master/src/App.jsx"
    click Home "https://github.com/mihir-28/kittypay/blob/master/src/pages/Home.jsx"
    click DashboardPage "https://github.com/mihir-28/kittypay/blob/master/src/pages/Dashboard.jsx"
    click KittiesPage "https://github.com/mihir-28/kittypay/blob/master/src/pages/Kitties.jsx"
    click Login "https://github.com/mihir-28/kittypay/blob/master/src/pages/Login.jsx"
    click Signup "https://github.com/mihir-28/kittypay/blob/master/src/pages/Signup.jsx"
    click Profile "https://github.com/mihir-28/kittypay/blob/master/src/pages/Profile.jsx"
    click Contact "https://github.com/mihir-28/kittypay/blob/master/src/pages/Contact.jsx"
    click Roadmap "https://github.com/mihir-28/kittypay/blob/master/src/pages/Roadmap.jsx"
    click Policy "https://github.com/mihir-28/kittypay/blob/master/src/pages/Policy.jsx"
    click Terms "https://github.com/mihir-28/kittypay/blob/master/src/pages/Terms.jsx"
    click Navbar "https://github.com/mihir-28/kittypay/blob/master/src/ui/Navbar.jsx"
    click LeftNav "https://github.com/mihir-28/kittypay/blob/master/src/ui/LeftAlignedNavbar.jsx"
    click Footer "https://github.com/mihir-28/kittypay/blob/master/src/ui/Footer.jsx"
    click ThemeToggle "https://github.com/mihir-28/kittypay/blob/master/src/components/common/ThemeToggle.jsx"
    click PWAInstall "https://github.com/mihir-28/kittypay/blob/master/src/components/common/PWAInstallPrompt.jsx"
    click ProtectedRoute "https://github.com/mihir-28/kittypay/blob/master/src/components/ProtectedRoute.jsx"
    click RouteTracker "https://github.com/mihir-28/kittypay/blob/master/src/components/common/RouteTracker.jsx"
    click ScrollTop "https://github.com/mihir-28/kittypay/blob/master/src/components/common/ScrollToTop.jsx"
    click AuthContext "https://github.com/mihir-28/kittypay/blob/master/src/contexts/AuthContext.jsx"
    click FirebaseConfig "https://github.com/mihir-28/kittypay/blob/master/src/firebase/config.js"
    click AuthHelper "https://github.com/mihir-28/kittypay/blob/master/src/firebase/auth.js"
    click KittiesLogic "https://github.com/mihir-28/kittypay/blob/master/src/firebase/kitties.js"
    click AnalyticsAdapter "https://github.com/mihir-28/kittypay/blob/master/src/firebase/analytics.js"
    click GitHubAdapter "https://github.com/mihir-28/kittypay/blob/master/src/services/github.js"
    click ServiceWorker "https://github.com/mihir-28/kittypay/blob/master/src/sw-test.js"
    click CDN "https://github.com/mihir-28/kittypay/tree/master/public/icons/"
    click ViteBuild "https://github.com/mihir-28/kittypay/blob/master/vite.config.js"
    click Netlify "https://github.com/mihir-28/kittypay/tree/master/public/_redirects"
    click FirebaseAuth "https://github.com/mihir-28/kittypay/blob/master/firestore.rules"
    click CloudFunctions "https://github.com/mihir-28/kittypay/blob/master/FIREBASE_SETUP.md"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#3273DC,color:#000
    classDef pwa fill:#FFE8B5,stroke:#FF8C00,color:#000
    classDef backend fill:#DFFFE0,stroke:#28A745,color:#000
    classDef infra fill:#E0E0E0,stroke:#868B8E,color:#000
```
