# ashleyl1u/spendlens architecture

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

- Interactive diagram: https://gitdiagram.com/ashleyl1u/spendlens
- Repository: https://github.com/ashleyl1u/spendlens

## Overview

Spendlens is a personal spending tracker: a signed-in user imports an RBC card statement, reviews categorized transactions, explores spending summaries, and asks questions answered from fixed queries. The graph preserves the documented import, categorization, correction, dashboard, and assistant branches. Some router and page implementations were not sampled, so their documented relationships are cited to the README; unsampled implementation details are not inferred.

Main entry points: [`frontend/src/App.tsx`](https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/App.tsx) (App routes), [`backend/app/main.py`](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/main.py) (FastAPI app), [`frontend/src/lib/api.ts`](https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/lib/api.ts) (API client), [`backend/app/categorization/pipeline.py`](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/categorization/pipeline.py) (Categorization pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_app["App routes<br/>[App.tsx]"]
  node_authui["Auth context<br/>[AuthContext.tsx]"]
  node_authhook["Auth state<br/>[useAuth.ts]"]
  node_apiclient["API client<br/>[api.ts]"]
  node_async["Async loading<br/>[useAsync.ts]"]
  node_accountsui["Accounts page<br/>[AccountsPage.tsx]"]
  node_uploadui["Upload page<br/>[UploadPage.tsx]"]
  node_transactionsui["Transaction review"]
  node_dashboardui["Dashboard page<br/>[DashboardPage.tsx]"]
  node_askui["Ask page<br/>[AskPage.tsx]"]
end

subgraph group_api["API and identity"]
  node_api["FastAPI app<br/>[main.py]"]
  node_authroutes["Auth routes<br/>[auth.py]"]
  node_accountsroute["Account routes<br/>[accounts.py]"]
  node_transactionsroute["Transaction routes<br/>[transactions.py]"]
  node_deps["Request dependencies<br/>[deps.py]"]
  node_security["Token security<br/>[security.py]"]
  node_schemas["API schemas<br/>[schemas.py]"]
end

subgraph group_import["Import and categorization"]
  node_uploadroute["Upload route<br/>[uploads.py]"]
  node_rbc["RBC CSV adapter<br/>[rbc_credit_card.py]"]
  node_adapterbase["Adapter interface<br/>[base.py]"]
  node_pipeline["Categorization pipeline<br/>[pipeline.py]"]
  node_normalize["Merchant normalization<br/>[normalize.py]"]
  node_rules["Keyword rules<br/>[rules.py]"]
  node_categories["Category definitions<br/>[categories.py]"]
  node_providers["LLM providers<br/>[providers.py]"]
  node_gemini["Gemini client<br/>[gemini.py]"]
  node_corrections["Merchant corrections<br/>[corrections.py]"]
end

subgraph group_insights["Spending insights"]
  node_dashboardroute["Dashboard routes<br/>[dashboard.py]"]
  node_assistantroute["Assistant route<br/>[assistant.py]"]
  node_assistantservice["Assistant service<br/>[service.py]"]
  node_assistantmodels["Assistant models<br/>[models.py]"]
  node_tools["Read-only tools<br/>[tools.py]"]
  node_queries["Spending queries<br/>[queries.py]"]
end

node_user(("Cardholder"))

node_user -->|"uses"| node_app
node_app -->|"routes to"| node_accountsui
node_app -->|"routes to"| node_uploadui
node_app -->|"routes to"| node_transactionsui
node_app -->|"routes to"| node_dashboardui
node_app -->|"routes to"| node_askui
node_app -->|"uses"| node_authui
node_authui -->|"provides state"| node_authhook
node_authui -->|"calls"| node_apiclient
node_accountsui -.->|"requests API"| node_apiclient
node_uploadui -.->|"requests API"| node_apiclient
node_transactionsui -->|"requests transactions"| node_apiclient
node_transactionsui -->|"loads data"| node_async
node_dashboardui -->|"requests API"| node_apiclient
node_askui -.->|"requests API"| node_apiclient
node_apiclient -->|"HTTP requests"| node_api
node_api -->|"registers routes"| node_authroutes
node_api -->|"registers routes"| node_accountsroute
node_api -->|"registers routes"| node_uploadroute
node_api -->|"registers routes"| node_transactionsroute
node_api -->|"registers routes"| node_dashboardroute
node_api -->|"registers routes"| node_assistantroute
node_authroutes -->|"uses"| node_security
node_authroutes -->|"uses dependencies"| node_deps
node_accountsroute -->|"uses dependencies"| node_deps
node_transactionsroute -->|"uses dependencies"| node_deps
node_transactionsroute -->|"applies corrections"| node_corrections
node_deps -->|"validates token"| node_security
node_uploadroute -->|"parses statement"| node_rbc
node_rbc -->|"implements"| node_adapterbase
node_uploadroute -->|"categorizes transactions"| node_pipeline
node_pipeline -->|"normalizes names"| node_normalize
node_pipeline -->|"checks rules"| node_rules
node_pipeline -->|"asks remaining"| node_providers
node_pipeline -->|"uses thresholds"| node_categories
node_providers -->|"validates categories"| node_categories
node_providers -->|"calls client"| node_gemini
node_assistantroute -.->|"dispatches ask"| node_assistantservice
node_assistantservice -->|"uses models"| node_assistantmodels
node_assistantservice -->|"invokes tools"| node_tools
node_tools -->|"runs queries"| node_queries
node_dashboardroute -.->|"reads summaries"| node_queries

click node_app "https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/App.tsx"
click node_authui "https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/auth/AuthContext.tsx"
click node_authhook "https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/auth/useAuth.ts"
click node_apiclient "https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/lib/api.ts"
click node_async "https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/lib/useAsync.ts"
click node_accountsui "https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/pages/AccountsPage.tsx"
click node_uploadui "https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/pages/UploadPage.tsx"
click node_transactionsui "https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/pages/TransactionsPage.tsx"
click node_dashboardui "https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/pages/DashboardPage.tsx"
click node_askui "https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/pages/AskPage.tsx"
click node_api "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/main.py"
click node_authroutes "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/routers/auth.py"
click node_accountsroute "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/routers/accounts.py"
click node_transactionsroute "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/routers/transactions.py"
click node_deps "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/deps.py"
click node_security "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/security.py"
click node_schemas "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/schemas.py"
click node_uploadroute "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/routers/uploads.py"
click node_rbc "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/adapters/rbc_credit_card.py"
click node_adapterbase "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/adapters/base.py"
click node_pipeline "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/categorization/pipeline.py"
click node_normalize "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/categorization/normalize.py"
click node_rules "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/categorization/rules.py"
click node_categories "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/categorization/categories.py"
click node_providers "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/categorization/providers.py"
click node_gemini "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/gemini.py"
click node_corrections "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/categorization/corrections.py"
click node_dashboardroute "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/routers/dashboard.py"
click node_assistantroute "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/routers/assistant.py"
click node_assistantservice "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/assistant/service.py"
click node_assistantmodels "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/assistant/models.py"
click node_tools "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/assistant/tools.py"
click node_queries "https://github.com/ashleyl1u/spendlens/blob/main/backend/app/queries.py"

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_app,node_authui,node_authhook,node_apiclient,node_async,node_accountsui,node_uploadui,node_transactionsui,node_dashboardui,node_askui toneBlue
class node_api,node_authroutes,node_accountsroute,node_transactionsroute,node_deps,node_security,node_schemas toneAmber
class node_uploadroute,node_rbc,node_adapterbase,node_pipeline,node_normalize,node_rules,node_categories,node_providers,node_gemini,node_corrections toneMint
class node_dashboardroute,node_assistantroute,node_assistantservice,node_assistantmodels,node_tools,node_queries toneRose
class node_user toneIndigo
```

## Components

### Web client

- [App routes](https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Auth context](https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/auth/AuthContext.tsx): `frontend/src/auth/AuthContext.tsx`
- [Auth state](https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/auth/useAuth.ts): `frontend/src/auth/useAuth.ts`
- [API client](https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/lib/api.ts): `frontend/src/lib/api.ts`
- [Async loading](https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/lib/useAsync.ts): `frontend/src/lib/useAsync.ts`
- [Accounts page](https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/pages/AccountsPage.tsx): `frontend/src/pages/AccountsPage.tsx`
- [Upload page](https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/pages/UploadPage.tsx): `frontend/src/pages/UploadPage.tsx`
- [Transaction review](https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/pages/TransactionsPage.tsx): `frontend/src/pages/TransactionsPage.tsx`
- [Dashboard page](https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/pages/DashboardPage.tsx): `frontend/src/pages/DashboardPage.tsx`
- [Ask page](https://github.com/ashleyl1u/spendlens/blob/main/frontend/src/pages/AskPage.tsx): `frontend/src/pages/AskPage.tsx`

### API and identity

- [FastAPI app](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/main.py): `backend/app/main.py`
- [Auth routes](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/routers/auth.py): `backend/app/routers/auth.py`
- [Account routes](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/routers/accounts.py): `backend/app/routers/accounts.py`
- [Transaction routes](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/routers/transactions.py): `backend/app/routers/transactions.py`
- [Request dependencies](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/deps.py): `backend/app/deps.py`
- [Token security](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/security.py): `backend/app/security.py`
- [API schemas](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/schemas.py): `backend/app/schemas.py`

### Import and categorization

- [Upload route](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/routers/uploads.py): `backend/app/routers/uploads.py`
- [RBC CSV adapter](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/adapters/rbc_credit_card.py): `backend/app/adapters/rbc_credit_card.py`
- [Adapter interface](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/adapters/base.py): `backend/app/adapters/base.py`
- [Categorization pipeline](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/categorization/pipeline.py): `backend/app/categorization/pipeline.py`
- [Merchant normalization](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/categorization/normalize.py): `backend/app/categorization/normalize.py`
- [Keyword rules](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/categorization/rules.py): `backend/app/categorization/rules.py`
- [Category definitions](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/categorization/categories.py): `backend/app/categorization/categories.py`
- [LLM providers](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/categorization/providers.py): `backend/app/categorization/providers.py`
- [Gemini client](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/gemini.py): `backend/app/gemini.py`
- [Merchant corrections](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/categorization/corrections.py): `backend/app/categorization/corrections.py`

### Spending insights

- [Dashboard routes](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/routers/dashboard.py): `backend/app/routers/dashboard.py`
- [Assistant route](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/routers/assistant.py): `backend/app/routers/assistant.py`
- [Assistant service](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/assistant/service.py): `backend/app/assistant/service.py`
- [Assistant models](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/assistant/models.py): `backend/app/assistant/models.py`
- [Read-only tools](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/assistant/tools.py): `backend/app/assistant/tools.py`
- [Spending queries](https://github.com/ashleyl1u/spendlens/blob/main/backend/app/queries.py): `backend/app/queries.py`

### Other components

- **Cardholder**

## Connections

- Cardholder → App routes: uses (evidence: `frontend/src/App.tsx`)
- App routes → Accounts page: routes to (evidence: `frontend/src/App.tsx`)
- App routes → Upload page: routes to (evidence: `frontend/src/App.tsx`)
- App routes → Transaction review: routes to (evidence: `frontend/src/App.tsx`)
- App routes → Dashboard page: routes to (evidence: `frontend/src/App.tsx`)
- App routes → Ask page: routes to (evidence: `frontend/src/App.tsx`)
- App routes → Auth context: uses (evidence: `frontend/src/App.tsx`)
- Auth context → Auth state: provides state (evidence: `frontend/src/auth/AuthContext.tsx`)
- Auth context → API client: calls (evidence: `frontend/src/auth/AuthContext.tsx`)
- Accounts page → API client: requests API
- Upload page → API client: requests API
- Transaction review → API client: requests transactions (evidence: `frontend/src/pages/TransactionsPage.tsx`)
- Transaction review → Async loading: loads data (evidence: `frontend/src/pages/TransactionsPage.tsx`)
- Dashboard page → API client: requests API (evidence: `frontend/src/pages/DashboardPage.tsx`)
- Ask page → API client: requests API
- API client → FastAPI app: HTTP requests (evidence: `README.md`)
- FastAPI app → Auth routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI app → Account routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI app → Upload route: registers routes (evidence: `backend/app/main.py`)
- FastAPI app → Transaction routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI app → Dashboard routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI app → Assistant route: registers routes (evidence: `backend/app/main.py`)
- Auth routes → Token security: uses (evidence: `backend/app/routers/auth.py`)
- Auth routes → Request dependencies: uses dependencies (evidence: `backend/app/routers/auth.py`)
- Account routes → Request dependencies: uses dependencies (evidence: `backend/app/routers/accounts.py`)
- Transaction routes → Request dependencies: uses dependencies (evidence: `backend/app/routers/transactions.py`)
- Transaction routes → Merchant corrections: applies corrections (evidence: `backend/app/routers/transactions.py`)
- Request dependencies → Token security: validates token (evidence: `backend/app/deps.py`)
- Upload route → RBC CSV adapter: parses statement (evidence: `backend/app/routers/uploads.py`)
- RBC CSV adapter → Adapter interface: implements (evidence: `backend/app/adapters/rbc_credit_card.py`)
- Upload route → Categorization pipeline: categorizes transactions (evidence: `backend/app/routers/uploads.py`)
- Categorization pipeline → Merchant normalization: normalizes names (evidence: `backend/app/categorization/pipeline.py`)
- Categorization pipeline → Keyword rules: checks rules (evidence: `backend/app/categorization/pipeline.py`)
- Categorization pipeline → LLM providers: asks remaining (evidence: `backend/app/categorization/pipeline.py`)
- Categorization pipeline → Category definitions: uses thresholds (evidence: `backend/app/categorization/pipeline.py`)
- LLM providers → Category definitions: validates categories (evidence: `backend/app/categorization/providers.py`)
- LLM providers → Gemini client: calls client (evidence: `backend/app/categorization/providers.py`)
- Assistant route → Assistant service: dispatches ask
- Assistant service → Assistant models: uses models (evidence: `backend/app/assistant/service.py`)
- Assistant service → Read-only tools: invokes tools (evidence: `backend/app/assistant/service.py`)
- Read-only tools → Spending queries: runs queries (evidence: `backend/app/assistant/tools.py`)
- Dashboard routes → Spending queries: reads summaries
