# ggwarrior001/ledgerx architecture

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

- Interactive diagram: https://gitdiagram.com/ggwarrior001/ledgerx
- Repository: https://github.com/ggwarrior001/ledgerx

## Overview

1. **Product shape**
   LedgerX is a client-side finance/accounting application with one shared React/TypeScript codebase that is packaged for three runtimes: browser (Vite), desktop (Electron), and Android (Capacitor). The core domain is offline-first personal/business finance data, with optional Firebase sign-in and cloud sync.

2. **Top-level UI shell**
   The app is organized around a routed shell in `src/App.tsx`, `src/main.tsx`, and `src/app/AppShell.tsx`. The shell composes the global layout, navigation, and feature pages. Page-level routes map to business areas like Dashboard, Invoices, Expenses, Clients, Vendors, Reports, Ledger, Settings, and Auth.

3. **Feature-oriented structure**
   Business logic is split by domain under `src/features/*`. Each feature typically has:
   - a view component for the page surface,
   - one or more modal components for create/edit flows,
   - a feature service for data access/business operations,
   - a feature store for local state.
   This keeps invoices, expenses, clients, vendors, and auth isolated from one another while sharing common primitives.

4. **State and app boundaries**
   Global application state lives in `src/contexts/AppContext.tsx`, while authentication state lives in `src/contexts/AuthContext.tsx`. Feature stores such as `useInvoiceStore`, `useExpenseStore`, `useClientStore`, etc. manage feature-specific collections and UI state. The architecture is a mix of React context for cross-cutting concerns and feature stores for domain state.

5. **Data access layer**
   There is a clear separation between UI and persistence. Shared services in `src/shared/services` and `src/lib` provide the data boundary:
   - `storage.ts` / `storageService.ts` for encrypted local persistence,
   - `firestoreService.ts` / `firestoreSync.ts` for cloud reads/writes,
   - `dataService.ts` as the higher-level data orchestration layer.
   Feature services call into this shared layer rather than talking directly to storage from UI components.

6. **Offline-first local data model**
   The default persistence path is local and encrypted. The README describes AES-256 encryption with PBKDF2-derived keys, and the codebase reflects that with storage helpers in `src/lib/storage.ts` and the shared storage service. This makes local device storage the primary system of record unless cloud sync is enabled.

7. **Optional Firebase sync path**
   Firebase is an opt-in boundary, not a hard dependency. `src/lib/firebase.ts` initializes Firebase auth and Firestore, and `src/features/auth/services/authService.ts` plus `src/lib/firestoreSync.ts` handle authenticated cloud behavior. When a user signs in, the app can mirror finance data to Firestore under that user account; otherwise it remains fully local.

8. **Authentication and onboarding**
   Auth is a dedicated subsystem with `src/pages/Auth.tsx`, `src/features/auth/components/AuthPage.tsx`, `AuthContext`, and an auth store. First-run setup is handled by onboarding components, and `AutoLock` enforces inactivity-based session locking. These pieces sit at the boundary between secure access and the rest of the app.

9. **Domain screens and shared UI**
   The visible product surfaces are mostly feature views in `src/features/*/components/*View.tsx`, backed by reusable UI from `src/components/ui` and layout components such as `Sidebar` and `Topbar`. Modals for clients, invoices, expenses, and vendors are the main create/edit interaction pattern, while dashboard and reports are read-heavy analytical surfaces.

10. **Financial reporting flow**
   Dashboard, Reports, and Ledger consume the same underlying transaction data but present it differently: summary metrics and charts, analytical breakdowns, and full transaction history. The presence of `Recharts` in the README and chart-related UI in the component tree indicates that aggregated data is computed in the app layer rather than fetched from a separate analytics backend.

11. **Cross-cutting UX concerns**
   Notifications, privacy mode, multi-currency behavior, fiscal-year configuration, and data export are app-wide concerns housed in shared components, constants, and settings screens. `src/lib/constants.ts` and `src/features/settings` are the main places where these configuration-driven behaviors are surfaced.

12. **Platform wrappers**
   Electron and Capacitor are packaging/runtime layers around the same frontend code, not separate business applications. `electron/main.js` and `electron/preload.js` define the desktop shell and bridge, while `android/` holds the generated/native Android project. The core finance logic remains in `src/`, which is what makes the architecture portable across runtimes.

13. **Testing and automation**
   The repository includes unit tests with Vitest and end-to-end tests with Playwright. Those tests exercise the same frontend-centric architecture, with the main operational risk concentrated in state, storage/encryption, and auth/sync boundaries rather than in backend services.

14. **Diagram takeaway**
   If you draw the system, the central node should be the React app shell. From there, branch into domain features, then into shared UI/state, then into the persistence boundary where data either stays in encrypted local storage or flows through Firebase auth into Firestore sync. Electron and Capacitor sit outside that core as runtime adapters.

Main entry points: [`src/app/AppShell.tsx`](https://github.com/ggwarrior001/ledgerx/blob/main/src/app/AppShell.tsx) (Shell), [`src/shared/services/dataService.ts`](https://github.com/ggwarrior001/ledgerx/blob/main/src/shared/services/dataService.ts) (Data service), [`src/features/auth/components/AuthPage.tsx`](https://github.com/ggwarrior001/ledgerx/blob/main/src/features/auth/components/AuthPage.tsx) (Auth page), [`src/shared/services/firestoreService.ts`](https://github.com/ggwarrior001/ledgerx/blob/main/src/shared/services/firestoreService.ts) (Firestore svc)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime wrappers"]
end

subgraph group_shell["App shell"]
  node_main["main<br/>bootstrap<br/>[main.tsx]"]
  node_app["App<br/>root component<br/>[App.tsx]"]
  node_appshell["Shell<br/>layout/router<br/>[AppShell.tsx]"]
  node_home["Home<br/>route page<br/>[Index.tsx]"]
  node_dashboard_page["Dashboard<br/>route page<br/>[Dashboard.tsx]"]
  node_invoices_page["Invoices<br/>route page<br/>[Invoices.tsx]"]
  node_expenses_page["Expenses<br/>route page<br/>[Expenses.tsx]"]
  node_clients_page["Clients<br/>route page<br/>[Clients.tsx]"]
  node_vendors_page["Vendors<br/>route page<br/>[Vendors.tsx]"]
  node_ledger_page["Ledger<br/>route page<br/>[Ledger.tsx]"]
  node_reports_page["Reports<br/>route page<br/>[Reports.tsx]"]
  node_settings_page["Settings<br/>route page<br/>[Settings.tsx]"]
  node_auth_page["Auth<br/>route page<br/>[Auth.tsx]"]
end

subgraph group_features["Feature domains"]
  node_dashboard_view["Dashboard view<br/>feature view<br/>[DashboardView.tsx]"]
  node_invoice_view["Invoice view<br/>feature view<br/>[InvoicesView.tsx]"]
  node_expense_view["Expense view<br/>feature view<br/>[ExpensesView.tsx]"]
  node_clients_view["Clients view<br/>feature view<br/>[ClientsView.tsx]"]
  node_vendors_view["Vendors view<br/>feature view<br/>[VendorsView.tsx]"]
  node_ledger_view["Ledger view<br/>feature view<br/>[LedgerView.tsx]"]
  node_reports_view["Reports view<br/>feature view<br/>[ReportsView.tsx]"]
  node_settings_view["Settings view<br/>feature view<br/>[SettingsView.tsx]"]
  node_auth_feature["Auth page<br/>feature view<br/>[AuthPage.tsx]"]
end

subgraph group_shared["Shared state and data"]
  node_app_context(("App state<br/>react context<br/>[AppContext.tsx]"))
  node_auth_context(("Auth state<br/>react context<br/>[AuthContext.tsx]"))
  node_data_service["Data service<br/>orchestration<br/>[dataService.ts]"]
  node_storage_service[("Storage svc<br/>local persistence<br/>[storageService.ts]")]
  node_firestore_service[("Firestore svc<br/>cloud persistence")]
  node_storage_lib["Storage lib<br/>crypto storage<br/>[storage.ts]"]
  node_firebase_lib["Firebase<br/>sdk init<br/>[firebase.ts]"]
  node_sync_lib["Sync<br/>[firestoreSync.ts]"]
end

subgraph group_ui["Shared UI"]
  node_sidebar["Sidebar<br/>navigation ui<br/>[Sidebar.tsx]"]
  node_topbar["Topbar<br/>navigation ui<br/>[Topbar.tsx]"]
  node_onboarding["Onboarding<br/>secure flow<br/>[Onboarding.tsx]"]
  node_autolock["AutoLock<br/>security ui<br/>[AutoLock.tsx]"]
end

node_main -->|"mounts"| node_app
node_app -->|"routes into"| node_appshell
node_appshell -->|"route"| node_home
node_appshell -->|"route"| node_dashboard_page
node_appshell -->|"route"| node_invoices_page
node_appshell -->|"route"| node_expenses_page
node_appshell -->|"route"| node_clients_page
node_appshell -->|"route"| node_vendors_page
node_appshell -->|"route"| node_ledger_page
node_appshell -->|"route"| node_reports_page
node_appshell -->|"route"| node_settings_page
node_appshell -->|"route"| node_auth_page
node_dashboard_page -->|"renders"| node_dashboard_view
node_invoices_page -->|"renders"| node_invoice_view
node_expenses_page -->|"renders"| node_expense_view
node_clients_page -->|"renders"| node_clients_view
node_vendors_page -->|"renders"| node_vendors_view
node_ledger_page -->|"renders"| node_ledger_view
node_reports_page -->|"renders"| node_reports_view
node_settings_page -->|"renders"| node_settings_view
node_auth_page -->|"renders"| node_auth_feature
node_appshell -->|"uses"| node_sidebar
node_appshell -->|"uses"| node_topbar
node_auth_feature -->|"includes"| node_onboarding
node_auth_feature -->|"enforces"| node_autolock
node_app_context -->|"coordinates"| node_data_service
node_auth_context -->|"authenticates"| node_firebase_lib
node_data_service -->|"uses"| node_storage_service
node_data_service -->|"uses"| node_firestore_service
node_storage_service -->|"wraps"| node_storage_lib
node_firestore_service -->|"depends on"| node_firebase_lib
node_sync_lib -->|"syncs via"| node_firestore_service
node_sync_lib -->|"orchestrates"| node_data_service

click node_main "https://github.com/ggwarrior001/ledgerx/blob/main/src/main.tsx"
click node_app "https://github.com/ggwarrior001/ledgerx/blob/main/src/App.tsx"
click node_appshell "https://github.com/ggwarrior001/ledgerx/blob/main/src/app/AppShell.tsx"
click node_home "https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Index.tsx"
click node_dashboard_page "https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Dashboard.tsx"
click node_invoices_page "https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Invoices.tsx"
click node_expenses_page "https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Expenses.tsx"
click node_clients_page "https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Clients.tsx"
click node_vendors_page "https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Vendors.tsx"
click node_ledger_page "https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Ledger.tsx"
click node_reports_page "https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Reports.tsx"
click node_settings_page "https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Settings.tsx"
click node_auth_page "https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Auth.tsx"
click node_dashboard_view "https://github.com/ggwarrior001/ledgerx/blob/main/src/features/dashboard/components/DashboardView.tsx"
click node_invoice_view "https://github.com/ggwarrior001/ledgerx/blob/main/src/features/invoices/components/InvoicesView.tsx"
click node_expense_view "https://github.com/ggwarrior001/ledgerx/blob/main/src/features/expenses/components/ExpensesView.tsx"
click node_clients_view "https://github.com/ggwarrior001/ledgerx/blob/main/src/features/clients/components/ClientsView.tsx"
click node_vendors_view "https://github.com/ggwarrior001/ledgerx/blob/main/src/features/vendors/components/VendorsView.tsx"
click node_ledger_view "https://github.com/ggwarrior001/ledgerx/blob/main/src/features/ledger/components/LedgerView.tsx"
click node_reports_view "https://github.com/ggwarrior001/ledgerx/blob/main/src/features/reports/components/ReportsView.tsx"
click node_settings_view "https://github.com/ggwarrior001/ledgerx/blob/main/src/features/settings/components/SettingsView.tsx"
click node_auth_feature "https://github.com/ggwarrior001/ledgerx/blob/main/src/features/auth/components/AuthPage.tsx"
click node_app_context "https://github.com/ggwarrior001/ledgerx/blob/main/src/contexts/AppContext.tsx"
click node_auth_context "https://github.com/ggwarrior001/ledgerx/blob/main/src/contexts/AuthContext.tsx"
click node_data_service "https://github.com/ggwarrior001/ledgerx/blob/main/src/shared/services/dataService.ts"
click node_storage_service "https://github.com/ggwarrior001/ledgerx/blob/main/src/shared/services/storageService.ts"
click node_firestore_service "https://github.com/ggwarrior001/ledgerx/blob/main/src/shared/services/firestoreService.ts"
click node_storage_lib "https://github.com/ggwarrior001/ledgerx/blob/main/src/lib/storage.ts"
click node_firebase_lib "https://github.com/ggwarrior001/ledgerx/blob/main/src/lib/firebase.ts"
click node_sync_lib "https://github.com/ggwarrior001/ledgerx/blob/main/src/lib/firestoreSync.ts"
click node_sidebar "https://github.com/ggwarrior001/ledgerx/blob/main/src/components/layout/Sidebar.tsx"
click node_topbar "https://github.com/ggwarrior001/ledgerx/blob/main/src/components/layout/Topbar.tsx"
click node_onboarding "https://github.com/ggwarrior001/ledgerx/blob/main/src/components/Onboarding.tsx"
click node_autolock "https://github.com/ggwarrior001/ledgerx/blob/main/src/components/AutoLock.tsx"

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_main,node_app,node_appshell,node_home,node_dashboard_page,node_invoices_page,node_expenses_page,node_clients_page,node_vendors_page,node_ledger_page,node_reports_page,node_settings_page,node_auth_page toneAmber
class node_dashboard_view,node_invoice_view,node_expense_view,node_clients_view,node_vendors_view,node_ledger_view,node_reports_view,node_settings_view,node_auth_feature toneMint
class node_app_context,node_auth_context,node_data_service,node_storage_service,node_firestore_service,node_storage_lib,node_firebase_lib,node_sync_lib toneRose
class node_sidebar,node_topbar,node_onboarding,node_autolock toneIndigo
```

## Components

### App shell

Routing, global layout, and top-level composition

- [main](https://github.com/ggwarrior001/ledgerx/blob/main/src/main.tsx): bootstrap · Vite entrypoint · `src/main.tsx`
- [App](https://github.com/ggwarrior001/ledgerx/blob/main/src/App.tsx): root component · Top-level route host · `src/App.tsx`
- [Shell](https://github.com/ggwarrior001/ledgerx/blob/main/src/app/AppShell.tsx): layout/router · Global navigation and page composition · `src/app/AppShell.tsx`
- [Home](https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Index.tsx): route page · Index route wrapper · `src/pages/Index.tsx`
- [Dashboard](https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Dashboard.tsx): route page · Dashboard route wrapper · `src/pages/Dashboard.tsx`
- [Invoices](https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Invoices.tsx): route page · Invoices route wrapper · `src/pages/Invoices.tsx`
- [Expenses](https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Expenses.tsx): route page · Expenses route wrapper · `src/pages/Expenses.tsx`
- [Clients](https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Clients.tsx): route page · Clients route wrapper · `src/pages/Clients.tsx`
- [Vendors](https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Vendors.tsx): route page · Vendors route wrapper · `src/pages/Vendors.tsx`
- [Ledger](https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Ledger.tsx): route page · Ledger route wrapper · `src/pages/Ledger.tsx`
- [Reports](https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Reports.tsx): route page · Reports route wrapper · `src/pages/Reports.tsx`
- [Settings](https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Settings.tsx): route page · Settings route wrapper · `src/pages/Settings.tsx`
- [Auth](https://github.com/ggwarrior001/ledgerx/blob/main/src/pages/Auth.tsx): route page · Authentication route wrapper · `src/pages/Auth.tsx`

### Feature domains

Business modules for finance workflows

- [Dashboard view](https://github.com/ggwarrior001/ledgerx/blob/main/src/features/dashboard/components/DashboardView.tsx): feature view · Summary metrics and charts · `src/features/dashboard/components/DashboardView.tsx`
- [Invoice view](https://github.com/ggwarrior001/ledgerx/blob/main/src/features/invoices/components/InvoicesView.tsx): feature view · Invoice list and workflow · `src/features/invoices/components/InvoicesView.tsx`
- [Expense view](https://github.com/ggwarrior001/ledgerx/blob/main/src/features/expenses/components/ExpensesView.tsx): feature view · Expense tracking surface · `src/features/expenses/components/ExpensesView.tsx`
- [Clients view](https://github.com/ggwarrior001/ledgerx/blob/main/src/features/clients/components/ClientsView.tsx): feature view · Client management surface · `src/features/clients/components/ClientsView.tsx`
- [Vendors view](https://github.com/ggwarrior001/ledgerx/blob/main/src/features/vendors/components/VendorsView.tsx): feature view · Vendor management surface · `src/features/vendors/components/VendorsView.tsx`
- [Ledger view](https://github.com/ggwarrior001/ledgerx/blob/main/src/features/ledger/components/LedgerView.tsx): feature view · Transaction history surface · `src/features/ledger/components/LedgerView.tsx`
- [Reports view](https://github.com/ggwarrior001/ledgerx/blob/main/src/features/reports/components/ReportsView.tsx): feature view · Analytical breakdowns · `src/features/reports/components/ReportsView.tsx`
- [Settings view](https://github.com/ggwarrior001/ledgerx/blob/main/src/features/settings/components/SettingsView.tsx): feature view · App configuration surface · `src/features/settings/components/SettingsView.tsx`
- [Auth page](https://github.com/ggwarrior001/ledgerx/blob/main/src/features/auth/components/AuthPage.tsx): feature view · Sign-in and onboarding surface · `src/features/auth/components/AuthPage.tsx`

### Shared state and data

Cross-cutting state, services, and local/cloud persistence

- [App state](https://github.com/ggwarrior001/ledgerx/blob/main/src/contexts/AppContext.tsx): react context · Cross-cutting application state · `src/contexts/AppContext.tsx`
- [Auth state](https://github.com/ggwarrior001/ledgerx/blob/main/src/contexts/AuthContext.tsx): react context · Authentication and lock state · `src/contexts/AuthContext.tsx`
- [Data service](https://github.com/ggwarrior001/ledgerx/blob/main/src/shared/services/dataService.ts): orchestration · Shared data boundary · `src/shared/services/dataService.ts`
- [Storage svc](https://github.com/ggwarrior001/ledgerx/blob/main/src/shared/services/storageService.ts): local persistence · Encrypted local storage access · `src/shared/services/storageService.ts`
- [Firestore svc](https://github.com/ggwarrior001/ledgerx/blob/main/src/shared/services/firestoreService.ts): cloud persistence · Cloud reads and writes · `src/shared/services/firestoreService.ts`
- [Storage lib](https://github.com/ggwarrior001/ledgerx/blob/main/src/lib/storage.ts): crypto storage · AES/PBKDF2 local data helpers · `src/lib/storage.ts`
- [Firebase](https://github.com/ggwarrior001/ledgerx/blob/main/src/lib/firebase.ts): sdk init · Auth and Firestore initialization · `src/lib/firebase.ts`
- [Sync](https://github.com/ggwarrior001/ledgerx/blob/main/src/lib/firestoreSync.ts): cloud sync · Firestore synchronization logic · `src/lib/firestoreSync.ts`

### Shared UI

Reusable layout, modal, and interface primitives

- [Sidebar](https://github.com/ggwarrior001/ledgerx/blob/main/src/components/layout/Sidebar.tsx): navigation ui · Primary navigation layout · `src/components/layout/Sidebar.tsx`
- [Topbar](https://github.com/ggwarrior001/ledgerx/blob/main/src/components/layout/Topbar.tsx): navigation ui · Top-level app header · `src/components/layout/Topbar.tsx`
- [Onboarding](https://github.com/ggwarrior001/ledgerx/blob/main/src/components/Onboarding.tsx): secure flow · First-run setup flow · `src/components/Onboarding.tsx`
- [AutoLock](https://github.com/ggwarrior001/ledgerx/blob/main/src/components/AutoLock.tsx): security ui · Inactivity-based lock · `src/components/AutoLock.tsx`

## Connections

- main → App: mounts · Bootstraps the React application
- App → Shell: routes into · Delegates to the routed shell
- Shell → Home: route · Index entrypoint
- Shell → Dashboard: route · Dashboard page
- Shell → Invoices: route · Invoices page
- Shell → Expenses: route · Expenses page
- Shell → Clients: route · Clients page
- Shell → Vendors: route · Vendors page
- Shell → Ledger: route · Ledger page
- Shell → Reports: route · Reports page
- Shell → Settings: route · Settings page
- Shell → Auth: route · Auth page
- Dashboard → Dashboard view: renders · Dashboard UI surface
- Invoices → Invoice view: renders · Invoice UI surface
- Expenses → Expense view: renders · Expense UI surface
- Clients → Clients view: renders · Client UI surface
- Vendors → Vendors view: renders · Vendor UI surface
- Ledger → Ledger view: renders · Ledger UI surface
- Reports → Reports view: renders · Reports UI surface
- Settings → Settings view: renders · Settings UI surface
- Auth → Auth page: renders · Auth and onboarding surface
- Shell → Sidebar: uses · Primary navigation
- Shell → Topbar: uses · Global header
- Auth page → Onboarding: includes · First-run setup
- Auth page → AutoLock: enforces · Session inactivity lock
- App state → Data service: coordinates · App-wide data state flows into shared data operations
- Auth state → Firebase: authenticates · Firebase-backed sign-in boundary
- Data service → Storage svc: uses · Primary local persistence path
- Data service → Firestore svc: uses · Optional cloud persistence path
- Storage svc → Storage lib: wraps · Encrypted device storage helpers
- Firestore svc → Firebase: depends on · Uses Firebase initialization and SDK
- Sync → Firestore svc: syncs via · Mirrors finance data to Firestore
- Sync → Data service: orchestrates · Synchronizes shared app data
