# mahender8559/2.2-coinbuddy architecture

> Architecture diagram of the GitHub repository mahender8559/2.2-coinbuddy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mahender8559/2.2-coinbuddy
- Repository: https://github.com/mahender8559/2.2-coinbuddy

## Overview

#### Purpose and Entry Points
CoinBuddy is a client-side personal-finance application for accounts, transactions, budgets/affordability, loans, goals, recurring payments, shared finances, and planning insights. The browser app starts at `src/main.tsx`, renders the application shell in `src/App.tsx`, and is styled through `src/index.css` and versioned UI CSS such as `src/v35.css`.

#### Application State and UI Shell
`src/context/AppContext.tsx` is the central application-state boundary, supplying finance data and mutations to page-level components. `src/App.tsx` coordinates navigation, modal/page composition, onboarding, lock/exit behavior, and major service components. The primary user-facing workspaces are implemented in components including:
- `src/components/Dashboard.tsx`
- `src/components/ManageFinances.tsx`
- `src/components/Settings.tsx`

The component layer also contains dedicated account, category, transaction-detail, goal, activity, and insight views under the V35 UI (`src/components/V35AccountsPanel.tsx`, `src/components/V35TransactionDetail.tsx`, `src/components/V35Insights.tsx`).

#### Persistence and Finance Data Boundary
Persistence is abstracted behind a database client/repository layer rather than being distributed across UI components. `src/db/dbClient.ts` and `src/db/dbClientCore.ts` provide the main storage interface and lifecycle operations; `src/db/sqliteSchema.ts` defines the persisted schema. Shared-finance-specific persistence is separated in `src/db/sharedFinanceRepository.ts`.

UI mutations flow through application context into this data layer; persisted records are then used by dashboards, planners, schedules, and exports. This boundary is important for durable CRUD, clear/reset behavior, account initialization, and data integrity.

#### Ledger, Accounts, and Transaction Workflows
Account and transaction interaction is organized around modals, management screens, and ledger rules:
- `src/components/AddAccountModal.tsx`
- `src/components/AddTransactionModal.tsx`
- `src/components/ReconcileWizard.tsx`

Domain rules in `src/domain/ledgerRules.ts` and `src/domain/ledgerSafety.ts` protect ledger semantics, while `src/utils/balanceManager.ts` derives or updates balances. Transaction search/import/export-related behavior is supported by `src/utils/transactionSearch.ts`, `src/utils/ledgerSchema.ts`, and `src/utils/exportExcel.ts`.

#### Planning and Financial Domain Engine
Pure domain modules separate financial calculations from rendering. Affordability is a principal planning subsystem, combining settings, goals, category limits, irregular/normal spending, and upcoming money:
- `src/domain/affordability.ts`
- `src/domain/affordabilityPlanner.ts`
- `src/domain/affordabilitySettings.ts`

Its UI surfaces are `src/components/AffordabilityPlanner.tsx`, `src/components/CategoryAffordabilityReview.tsx`, and `src/components/SmarterPlanningDashboard.tsx`. Related projection engines cover savings goals (`src/domain/savingsGoals.ts`), loans (`src/domain/loanRevisionProjection.ts`), credit-card statements (`src/domain/creditCardStatements.ts`), and recurring schedules (`src/domain/recurring.ts`).

#### Automation, Backup, and External Google Services
The app includes local backup management and automated backup UX through `src/utils/backupManager.ts` and `src/components/BackupAutomationService.tsx`. Backup security/warnings are surfaced by `src/components/BackupSecurity.tsx` and `src/components/BackupWarningBanner.tsx`.

Google authentication and Google Drive backup are implemented as serverless API routes, suitable for Vercel deployment:
- `api/auth/google/connect.js`
- `api/auth/google/callback.js`
- `api/google-drive/backup.js`

`api/_googleDrive.js` is the shared Drive integration boundary; routes also expose connection status, backup listing, and deletion. The frontend connection/backup flow is therefore separated from OAuth token and Drive API handling.

#### Runtime and Deployment
The frontend is a TypeScript React application built with Vite (`vite.config.ts`, `package.json`). API endpoints are deployed as Vercel functions, configured by `vercel.json`. Browser-facing PWA/mobile metadata resides in `public/manifest.json`, while Google Drive credentials/environment expectations are represented by `.env.example` and `google-drive-vercel.env.template`.

Main entry points: [`src/App.tsx`](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/App.tsx) (Application shell), [`src/context/AppContext.tsx`](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/context/AppContext.tsx) (App state), [`src/components/AddTransactionModal.tsx`](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/components/AddTransactionModal.tsx) (Ledger workflows), [`src/components/AffordabilityPlanner.tsx`](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/components/AffordabilityPlanner.tsx) (Planning workspaces)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser application"]
  node_vite["Vite entry<br/>React bootstrap<br/>[main.tsx]"]
  node_app["Application shell<br/>navigation and composition<br/>[App.tsx]"]
  node_context["App state<br/>state boundary<br/>[AppContext.tsx]"]
  node_workspaces["Finance workspaces<br/>dashboard and management UI<br/>[Dashboard.tsx]"]
  node_ledger_ui["Ledger workflows<br/>account and transaction UI"]
  node_planning_ui["Planning workspaces<br/>affordability UI"]
end

subgraph group_domain["Finance domain"]
  node_ledger_rules["Ledger rules &amp; safety<br/>domain invariants<br/>[ledgerRules.ts]"]
  node_balances["Balance manager<br/>balance derivation<br/>[balanceManager.ts]"]
  node_affordability["Affordability engine<br/>planning calculations<br/>[affordability.ts]"]
  node_projections["Financial projections<br/>goals, loans, cards, recurring<br/>[savingsGoals.ts]"]
end

subgraph group_data["Persistence"]
  node_db_client[("Database client<br/>storage interface<br/>[dbClient.ts]")]
  node_db_core["Database core<br/>repository core<br/>[dbClientCore.ts]"]
  node_schema["SQLite schema<br/>persisted data model<br/>[sqliteSchema.ts]"]
  node_shared_repo["Shared-finance repository<br/>specialized persistence"]
end

subgraph group_backup["Backup &amp; Google services"]
  node_local_backup["Local backup manager<br/>backup orchestration<br/>[backupManager.ts]"]
  node_backup_ui["Backup automation UI<br/>backup user flow"]
  node_google_routes{{"Google API routes<br/>Vercel functions<br/>[connect.js]"}}
  node_drive["Google Drive integration<br/>shared external API boundary<br/>[_googleDrive.js]"]
  node_deployment["Vercel deployment<br/>serverless configuration<br/>[vercel.json]"]
end

node_vite -->|"renders"| node_app
node_app -->|"composes"| node_context
node_app -->|"routes to"| node_workspaces
node_app -->|"opens"| node_ledger_ui
node_app -->|"opens"| node_planning_ui
node_workspaces -->|"reads and mutates"| node_context
node_ledger_ui -->|"submits mutations"| node_context
node_planning_ui -->|"uses finance data"| node_context
node_context -->|"persists through"| node_db_client
node_db_client -->|"delegates to"| node_db_core
node_db_core -->|"uses"| node_schema
node_db_client -->|"separates shared finance"| node_shared_repo
node_ledger_ui -->|"enforces"| node_ledger_rules
node_ledger_rules -->|"protects updates"| node_balances
node_planning_ui -->|"calculates with"| node_affordability
node_affordability -->|"uses projections"| node_projections
node_backup_ui -->|"automates"| node_local_backup
node_backup_ui -->|"connects and backs up"| node_google_routes
node_google_routes -->|"calls"| node_drive
node_deployment -->|"deploys"| node_google_routes

click node_vite "https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/main.tsx"
click node_app "https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/App.tsx"
click node_context "https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/context/AppContext.tsx"
click node_workspaces "https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/components/Dashboard.tsx"
click node_ledger_ui "https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/components/AddTransactionModal.tsx"
click node_planning_ui "https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/components/AffordabilityPlanner.tsx"
click node_db_client "https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/db/dbClient.ts"
click node_db_core "https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/db/dbClientCore.ts"
click node_schema "https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/db/sqliteSchema.ts"
click node_shared_repo "https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/db/sharedFinanceRepository.ts"
click node_ledger_rules "https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/domain/ledgerRules.ts"
click node_balances "https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/utils/balanceManager.ts"
click node_affordability "https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/domain/affordability.ts"
click node_projections "https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/domain/savingsGoals.ts"
click node_local_backup "https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/utils/backupManager.ts"
click node_backup_ui "https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/components/BackupAutomationService.tsx"
click node_google_routes "https://github.com/mahender8559/2.2-coinbuddy/blob/main/api/auth/google/connect.js"
click node_drive "https://github.com/mahender8559/2.2-coinbuddy/blob/main/api/_googleDrive.js"
click node_deployment "https://github.com/mahender8559/2.2-coinbuddy/blob/main/vercel.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_vite,node_app,node_context,node_workspaces,node_ledger_ui,node_planning_ui toneBlue
class node_ledger_rules,node_balances,node_affordability,node_projections toneAmber
class node_db_client,node_db_core,node_schema,node_shared_repo toneMint
class node_local_backup,node_backup_ui,node_google_routes,node_drive,node_deployment toneRose
```

## Components

### Browser application

- [Vite entry](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/main.tsx): React bootstrap · `src/main.tsx`
- [Application shell](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/App.tsx): navigation and composition · `src/App.tsx`
- [App state](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/context/AppContext.tsx): state boundary · Supplies finance data and mutations to page components. · `src/context/AppContext.tsx`
- [Finance workspaces](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/components/Dashboard.tsx): dashboard and management UI · `src/components/Dashboard.tsx`
- [Ledger workflows](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/components/AddTransactionModal.tsx): account and transaction UI · `src/components/AddTransactionModal.tsx`
- [Planning workspaces](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/components/AffordabilityPlanner.tsx): affordability UI · `src/components/AffordabilityPlanner.tsx`

### Finance domain

- [Ledger rules & safety](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/domain/ledgerRules.ts): domain invariants · `src/domain/ledgerRules.ts`
- [Balance manager](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/utils/balanceManager.ts): balance derivation · `src/utils/balanceManager.ts`
- [Affordability engine](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/domain/affordability.ts): planning calculations · Combines spending, goals, settings, limits, and upcoming money. · `src/domain/affordability.ts`
- [Financial projections](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/domain/savingsGoals.ts): goals, loans, cards, recurring · `src/domain/savingsGoals.ts`

### Persistence

- [Database client](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/db/dbClient.ts): storage interface · Owns storage lifecycle and durable CRUD. · `src/db/dbClient.ts`
- [Database core](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/db/dbClientCore.ts): repository core · `src/db/dbClientCore.ts`
- [SQLite schema](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/db/sqliteSchema.ts): persisted data model · `src/db/sqliteSchema.ts`
- [Shared-finance repository](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/db/sharedFinanceRepository.ts): specialized persistence · `src/db/sharedFinanceRepository.ts`

### Backup & Google services

- [Local backup manager](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/utils/backupManager.ts): backup orchestration · `src/utils/backupManager.ts`
- [Backup automation UI](https://github.com/mahender8559/2.2-coinbuddy/blob/main/src/components/BackupAutomationService.tsx): backup user flow · `src/components/BackupAutomationService.tsx`
- [Google API routes](https://github.com/mahender8559/2.2-coinbuddy/blob/main/api/auth/google/connect.js): Vercel functions · Handles OAuth connection and Drive backup operations. · `api/auth/google/connect.js`
- [Google Drive integration](https://github.com/mahender8559/2.2-coinbuddy/blob/main/api/_googleDrive.js): shared external API boundary · `api/_googleDrive.js`
- [Vercel deployment](https://github.com/mahender8559/2.2-coinbuddy/blob/main/vercel.json): serverless configuration · `vercel.json`

## Connections

- Vite entry → Application shell: renders
- Application shell → App state: composes
- Application shell → Finance workspaces: routes to
- Application shell → Ledger workflows: opens
- Application shell → Planning workspaces: opens
- Finance workspaces → App state: reads and mutates
- Ledger workflows → App state: submits mutations
- Planning workspaces → App state: uses finance data
- App state → Database client: persists through
- Database client → Database core: delegates to
- Database core → SQLite schema: uses
- Database client → Shared-finance repository: separates shared finance
- Ledger workflows → Ledger rules & safety: enforces
- Ledger rules & safety → Balance manager: protects updates
- Planning workspaces → Affordability engine: calculates with
- Affordability engine → Financial projections: uses projections
- Backup automation UI → Local backup manager: automates
- Backup automation UI → Google API routes: connects and backs up
- Google API routes → Google Drive integration: calls
- Vercel deployment → Google API routes: deploys
