# mickunaru/balancr architecture

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

- Interactive diagram: https://gitdiagram.com/mickunaru/balancr
- Repository: https://github.com/mickunaru/balancr

## Overview

Balancr is a personal-finance web app: users sign in, link banks through Plaid or import CSVs, then review accounts, transactions, budgets, and financial summaries. Bank linking stores encrypted credentials and accounts; transaction sync updates categorized records and balances, while dashboard queries and budget views turn stored financial activity into results. The graph preserves documented capabilities such as reconnects, recurring-charge detection, and CSV de-duplication. Some feature internals are unsampled, so those relationships are shown only where the README or source index supports them.

Main entry points: [`lib/db.ts`](https://github.com/mickunaru/balancr/blob/main/lib/db.ts) (Postgres database), [`lib/sync.ts`](https://github.com/mickunaru/balancr/blob/main/lib/sync.ts) (Transaction sync), [`app/api/plaid/exchange/route.ts`](https://github.com/mickunaru/balancr/blob/main/app/api/plaid/exchange/route.ts) (Link exchange), [`app/dashboard/page.tsx`](https://github.com/mickunaru/balancr/blob/main/app/dashboard/page.tsx) (Dashboard summary)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_identity["Identity"]
  node_auth["Authentication<br/>[auth.ts]"]
  node_auth_actions["Sign-in and signup<br/>[actions.ts]"]
end

subgraph group_banking["Bank connections"]
  node_link_routes["Plaid link routes<br/>[route.ts]"]
  node_exchange["Link exchange<br/>[route.ts]"]
  node_webhook["Plaid webhook<br/>[route.ts]"]
  node_reconnect["Reconnect handling<br/>[route.ts]"]
  node_sync["Transaction sync<br/>[sync.ts]"]
  node_crypto["Token encryption<br/>[crypto.ts]"]
end

subgraph group_finance["Finance workflows"]
  node_accounts["Accounts view<br/>[page.tsx]"]
  node_transactions["Transactions view<br/>[page.tsx]"]
  node_categories["Categories and rules<br/>[categories.ts]"]
  node_budgets["Budget management<br/>[page.tsx]"]
  node_csv_ui["CSV import workflow<br/>[import-client.tsx]"]
  node_csv_parser["CSV normalization<br/>[csv-import.ts]"]
end

subgraph group_insights["Financial insights"]
  node_dashboard["Dashboard summary<br/>[page.tsx]"]
  node_analytics["Financial aggregates<br/>[dashboard-data.ts]"]
  node_charts["Charts and trends<br/>[charts.tsx]"]
  node_subscriptions["Recurring charges<br/>[subscriptions.ts]"]
end

subgraph group_storage["Persistence"]
  node_database[("Postgres database<br/>[db.ts]")]
end

node_user(("Finance user"))
node_plaid_api{{"Plaid service"}}

node_user -->|"signs in"| node_auth_actions
node_auth_actions -->|"authenticates"| node_auth
node_auth -->|"reads users"| node_database
node_user -->|"starts linking"| node_link_routes
node_link_routes -->|"requests link token"| node_plaid_api
node_user -->|"submits token"| node_exchange
node_exchange -->|"exchanges token"| node_plaid_api
node_exchange -->|"encrypts credential"| node_crypto
node_exchange -->|"stores accounts"| node_database
node_exchange -->|"starts initial sync"| node_sync
node_webhook -->|"triggers sync"| node_sync
node_reconnect -->|"resumes sync"| node_sync
node_sync -->|"fetches transactions"| node_plaid_api
node_sync -->|"decrypts credential"| node_crypto
node_sync -->|"resolves categories"| node_categories
node_sync -->|"updates records"| node_database
node_user -->|"reviews accounts"| node_accounts
node_user -->|"reviews transactions"| node_transactions
node_user -->|"sets limits"| node_budgets
node_transactions -->|"reads transactions"| node_database
node_budgets -->|"reads and writes budgets"| node_database
node_budgets -->|"loads taxonomy"| node_categories
node_user -->|"imports statement"| node_csv_ui
node_csv_ui -.->|"normalizes rows"| node_csv_parser
node_csv_ui -->|"commits transactions"| node_database
node_user -->|"views finances"| node_dashboard
node_dashboard -->|"loads aggregates"| node_analytics
node_dashboard -->|"renders trends"| node_charts
node_dashboard -->|"loads recurring charges"| node_subscriptions
node_analytics -->|"queries finance data"| node_database
node_accounts -->|"reads accounts"| node_database

click node_auth "https://github.com/mickunaru/balancr/blob/main/auth.ts"
click node_auth_actions "https://github.com/mickunaru/balancr/blob/main/app/(auth)/actions.ts"
click node_link_routes "https://github.com/mickunaru/balancr/blob/main/app/api/plaid/create-link-token/route.ts"
click node_exchange "https://github.com/mickunaru/balancr/blob/main/app/api/plaid/exchange/route.ts"
click node_webhook "https://github.com/mickunaru/balancr/blob/main/app/api/plaid/webhook/route.ts"
click node_reconnect "https://github.com/mickunaru/balancr/blob/main/app/api/plaid/reconnected/route.ts"
click node_sync "https://github.com/mickunaru/balancr/blob/main/lib/sync.ts"
click node_crypto "https://github.com/mickunaru/balancr/blob/main/lib/crypto.ts"
click node_accounts "https://github.com/mickunaru/balancr/blob/main/app/dashboard/accounts/page.tsx"
click node_transactions "https://github.com/mickunaru/balancr/blob/main/app/dashboard/transactions/page.tsx"
click node_categories "https://github.com/mickunaru/balancr/blob/main/lib/categories.ts"
click node_budgets "https://github.com/mickunaru/balancr/blob/main/app/dashboard/budgets/page.tsx"
click node_csv_ui "https://github.com/mickunaru/balancr/blob/main/app/dashboard/import/import-client.tsx"
click node_csv_parser "https://github.com/mickunaru/balancr/blob/main/lib/csv-import.ts"
click node_dashboard "https://github.com/mickunaru/balancr/blob/main/app/dashboard/page.tsx"
click node_analytics "https://github.com/mickunaru/balancr/blob/main/lib/dashboard-data.ts"
click node_charts "https://github.com/mickunaru/balancr/blob/main/app/dashboard/charts.tsx"
click node_subscriptions "https://github.com/mickunaru/balancr/blob/main/lib/subscriptions.ts"
click node_database "https://github.com/mickunaru/balancr/blob/main/lib/db.ts"

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_auth,node_auth_actions,node_user toneBlue
class node_link_routes,node_exchange,node_webhook,node_reconnect,node_sync,node_crypto toneAmber
class node_accounts,node_transactions,node_categories,node_budgets,node_csv_ui,node_csv_parser toneMint
class node_dashboard,node_analytics,node_charts,node_subscriptions toneRose
class node_database,node_plaid_api toneIndigo
```

## Components

### Identity

- [Authentication](https://github.com/mickunaru/balancr/blob/main/auth.ts): `auth.ts`
- [Sign-in and signup](https://github.com/mickunaru/balancr/blob/main/app/(auth)/actions.ts): `app/(auth)/actions.ts`

### Bank connections

- [Plaid link routes](https://github.com/mickunaru/balancr/blob/main/app/api/plaid/create-link-token/route.ts): `app/api/plaid/create-link-token/route.ts`
- [Link exchange](https://github.com/mickunaru/balancr/blob/main/app/api/plaid/exchange/route.ts): `app/api/plaid/exchange/route.ts`
- [Plaid webhook](https://github.com/mickunaru/balancr/blob/main/app/api/plaid/webhook/route.ts): `app/api/plaid/webhook/route.ts`
- [Reconnect handling](https://github.com/mickunaru/balancr/blob/main/app/api/plaid/reconnected/route.ts): `app/api/plaid/reconnected/route.ts`
- [Transaction sync](https://github.com/mickunaru/balancr/blob/main/lib/sync.ts): `lib/sync.ts`
- [Token encryption](https://github.com/mickunaru/balancr/blob/main/lib/crypto.ts): `lib/crypto.ts`

### Finance workflows

- [Accounts view](https://github.com/mickunaru/balancr/blob/main/app/dashboard/accounts/page.tsx): `app/dashboard/accounts/page.tsx`
- [Transactions view](https://github.com/mickunaru/balancr/blob/main/app/dashboard/transactions/page.tsx): `app/dashboard/transactions/page.tsx`
- [Categories and rules](https://github.com/mickunaru/balancr/blob/main/lib/categories.ts): `lib/categories.ts`
- [Budget management](https://github.com/mickunaru/balancr/blob/main/app/dashboard/budgets/page.tsx): `app/dashboard/budgets/page.tsx`
- [CSV import workflow](https://github.com/mickunaru/balancr/blob/main/app/dashboard/import/import-client.tsx): `app/dashboard/import/import-client.tsx`
- [CSV normalization](https://github.com/mickunaru/balancr/blob/main/lib/csv-import.ts): `lib/csv-import.ts`

### Financial insights

- [Dashboard summary](https://github.com/mickunaru/balancr/blob/main/app/dashboard/page.tsx): `app/dashboard/page.tsx`
- [Financial aggregates](https://github.com/mickunaru/balancr/blob/main/lib/dashboard-data.ts): `lib/dashboard-data.ts`
- [Charts and trends](https://github.com/mickunaru/balancr/blob/main/app/dashboard/charts.tsx): `app/dashboard/charts.tsx`
- [Recurring charges](https://github.com/mickunaru/balancr/blob/main/lib/subscriptions.ts): `lib/subscriptions.ts`

### Persistence

- [Postgres database](https://github.com/mickunaru/balancr/blob/main/lib/db.ts): `lib/db.ts`

### Other components

- **Finance user**
- **Plaid service**

## Connections

- Finance user → Sign-in and signup: signs in (evidence: `app/(auth)/actions.ts`)
- Sign-in and signup → Authentication: authenticates (evidence: `app/(auth)/actions.ts`)
- Authentication → Postgres database: reads users (evidence: `auth.ts`)
- Finance user → Plaid link routes: starts linking (evidence: `README.md`)
- Plaid link routes → Plaid service: requests link token (evidence: `app/api/plaid/create-link-token/route.ts`)
- Finance user → Link exchange: submits token (evidence: `README.md`)
- Link exchange → Plaid service: exchanges token (evidence: `app/api/plaid/exchange/route.ts`)
- Link exchange → Token encryption: encrypts credential (evidence: `app/api/plaid/exchange/route.ts`)
- Link exchange → Postgres database: stores accounts (evidence: `app/api/plaid/exchange/route.ts`)
- Link exchange → Transaction sync: starts initial sync (evidence: `app/api/plaid/exchange/route.ts`)
- Plaid webhook → Transaction sync: triggers sync (evidence: `app/api/plaid/webhook/route.ts`)
- Reconnect handling → Transaction sync: resumes sync (evidence: `app/api/plaid/reconnected/route.ts`)
- Transaction sync → Plaid service: fetches transactions (evidence: `lib/sync.ts`)
- Transaction sync → Token encryption: decrypts credential (evidence: `lib/sync.ts`)
- Transaction sync → Categories and rules: resolves categories (evidence: `lib/sync.ts`)
- Transaction sync → Postgres database: updates records (evidence: `lib/sync.ts`)
- Finance user → Accounts view: reviews accounts (evidence: `README.md`)
- Finance user → Transactions view: reviews transactions (evidence: `README.md`)
- Finance user → Budget management: sets limits (evidence: `README.md`)
- Transactions view → Postgres database: reads transactions (evidence: `app/dashboard/transactions/page.tsx`)
- Budget management → Postgres database: reads and writes budgets (evidence: `app/dashboard/budgets/page.tsx`)
- Budget management → Categories and rules: loads taxonomy (evidence: `app/dashboard/budgets/page.tsx`)
- Finance user → CSV import workflow: imports statement (evidence: `README.md`)
- CSV import workflow → CSV normalization: normalizes rows
- CSV import workflow → Postgres database: commits transactions (evidence: `app/dashboard/import/import-client.tsx`)
- Finance user → Dashboard summary: views finances (evidence: `README.md`)
- Dashboard summary → Financial aggregates: loads aggregates (evidence: `app/dashboard/page.tsx`)
- Dashboard summary → Charts and trends: renders trends (evidence: `app/dashboard/page.tsx`)
- Dashboard summary → Recurring charges: loads recurring charges (evidence: `app/dashboard/page.tsx`)
- Financial aggregates → Postgres database: queries finance data (evidence: `lib/dashboard-data.ts`)
- Accounts view → Postgres database: reads accounts (evidence: `app/dashboard/accounts/page.tsx`)
