# sinha-19/bill-split architecture

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

- Interactive diagram: https://gitdiagram.com/sinha-19/bill-split
- Repository: https://github.com/sinha-19/bill-split

## Overview

##### Project Type and Purpose
- BillSplit is a front-end-only, component-based PWA for splitting bills.
- It uses React + Vite for UI and build, persists data in LocalStorage, and fetches live rates from an external ExchangeRate API.

a. Browser / Client Container
– Represents the user’s browser running as a PWA.
b. Static Assets & PWA Shell
– Files in public/ (index.html, manifest.json, sw.js).
– Service Worker (caching, offline).
c. React Application (src/)
– UI Components (Header, HomePage, CreateSplitPage, ResultPage, etc.)
– Utility Modules
- currencyUtils.js (external API calls)
- storageUtils.js (LocalStorage read/write)
– Styling pipeline (tailwind.config.js, postcss.config.js)
d. External ExchangeRate API
– Real-time currency data.

##### Relationships & Data Flows
- On page load, the Service Worker may serve cached index.html + JS/CSS → Browser.
- Browser instantiates React via main.tsx → mounts App.jsx / App.tsx.
- User interacts with UI → React state updates.
- Actions in components call storageUtils → save/load session in LocalStorage.
- CurrencySelector or calculation routines call currencyUtils → fetch rates from ExchangeRate API → update component state.
- ResultPage renders computed balances.

##### Architectural Patterns & Design Principles
- Component-Based Architecture (React) with clear separation of concerns: presentation vs. logic vs. utilities.
- Single-Page Application (SPA) pattern.
- PWA enhancements: offline support with Service Worker.
- Local persistence via browser LocalStorage.
- External integration via REST API.

##### Detailed Elements
– Vite build layer (optional): Vite config → bundles src → public → served by SW.
– Tailwind/PostCSS pipelines (optional): styling flow.
– Service Worker caching strategy (cache-first for static, network-first for API).

## Diagram (Mermaid)

```mermaid
flowchart TD
  subgraph "Browser / PWA"
    direction TB
    subgraph "PWA Shell & Static Assets"
      direction TB
      Index["index.html"]:::asset
      Manifest["manifest.json"]:::asset
      SW["Service Worker (sw.js)"]:::asset
    end
    SW -->|caches| Index
    SW -->|caches| Manifest

    subgraph "React Application"
      direction TB
      Main["main.tsx"]:::asset
      AppC["App.jsx"]:::ui

      Main -->|boots| AppC

      subgraph "UI Components"
        direction TB
        Header["Header Component"]:::ui
        Home["HomePage Component"]:::ui
        Create["CreateSplitPage Component"]:::ui
        Result["ResultPage Component"]:::ui
        CurrencySel["CurrencySelector Component"]:::ui
        ItemInput["ItemInput Component"]:::ui
        PersonInput["PersonInput Component"]:::ui
        Footer["Footer Component"]:::ui
      end

      subgraph "Utility Modules"
        direction TB
        CurrencyUtils["currencyUtils"]:::util
        StorageUtils["storageUtils"]:::util
      end

      AppC --> Header
      AppC --> Home
      AppC --> Create
      AppC --> Result
      AppC --> CurrencySel
      AppC --> ItemInput
      AppC --> PersonInput
      AppC --> Footer

      Home -->|reads/writes| StorageUtils
      Create -->|reads/writes| StorageUtils
      Result -->|reads/writes| StorageUtils
      CurrencySel -->|fetches rates via| CurrencyUtils

      StorageUtils -->|persists| LocalStorage
      CurrencyUtils -->|HTTP request| API
    end
  end

  LocalStorage["LocalStorage"]:::persistence
  API["ExchangeRate API"]:::external

  click Index "https://github.com/sinha-19/bill-split/blob/master/index.html"
  click Manifest "https://github.com/sinha-19/bill-split/blob/master/public/manifest.json"
  click SW "https://github.com/sinha-19/bill-split/blob/master/public/sw.js"
  click Main "https://github.com/sinha-19/bill-split/blob/master/src/main.tsx"
  click AppC "https://github.com/sinha-19/bill-split/blob/master/src/App.jsx"
  click Header "https://github.com/sinha-19/bill-split/blob/master/src/components/Header.jsx"
  click Home "https://github.com/sinha-19/bill-split/blob/master/src/components/HomePage.jsx"
  click Create "https://github.com/sinha-19/bill-split/blob/master/src/components/CreateSplitPage.jsx"
  click Result "https://github.com/sinha-19/bill-split/blob/master/src/components/ResultPage.jsx"
  click CurrencySel "https://github.com/sinha-19/bill-split/blob/master/src/components/CurrencySelector.jsx"
  click ItemInput "https://github.com/sinha-19/bill-split/blob/master/src/components/ItemInput.jsx"
  click PersonInput "https://github.com/sinha-19/bill-split/blob/master/src/components/PersonInput.jsx"
  click Footer "https://github.com/sinha-19/bill-split/blob/master/src/components/Footer.jsx"
  click CurrencyUtils "https://github.com/sinha-19/bill-split/blob/master/src/utils/currencyUtils.js"
  click StorageUtils "https://github.com/sinha-19/bill-split/blob/master/src/utils/storageUtils.js"

  classDef ui fill:#DDEEFF,stroke:#000
  classDef util fill:#DDFFDD,stroke:#000
  classDef asset fill:#EEEEEE,stroke:#000
  classDef persistence fill:#DDBB88,stroke:#000
  classDef external fill:#FFDD88,stroke:#000
```
