# ldugaduga/lending-app architecture

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

- Interactive diagram: https://gitdiagram.com/ldugaduga/lending-app
- Repository: https://github.com/ldugaduga/lending-app

## Overview

This TanStack Start lending app manages borrowers, loan schedules, payments, collections, and a client trust-fund ledger. The main workflow runs from browser routes to server functions: loan terms are previewed or committed with an amortization schedule, payments are recorded against installments, and collections are derived from outstanding installments. The README and sampled files support these principal paths; unsampled server and route implementations are represented only where the README or source index documents their roles.

Main entry points: [`src/server/trustFund.ts`](https://github.com/ldugaduga/lending-app/blob/main/src/server/trustFund.ts) (Trust fund ledger), [`src/router.tsx`](https://github.com/ldugaduga/lending-app/blob/main/src/router.tsx) (App routing), [`src/routes/clients.tsx`](https://github.com/ldugaduga/lending-app/blob/main/src/routes/clients.tsx) (Client management), [`src/routes/loans.index.tsx`](https://github.com/ldugaduga/lending-app/blob/main/src/routes/loans.index.tsx) (Loan creation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Web application"]
  node_router["App routing<br/>[router.tsx]"]
  node_client_ui["Client management<br/>[clients.tsx]"]
  node_loan_list_ui["Loan creation<br/>[loans.index.tsx]"]
  node_loan_detail_ui["Loan details<br/>[loans.$loanId.tsx]"]
  node_collections_ui["Collections view<br/>[collections.tsx]"]
  node_contribution_ui["Fund contributions<br/>[contribution.tsx]"]
  node_ui_primitives["UI primitives"]
end

subgraph group_lending["Lending operations"]
  node_client_service["Client operations<br/>[clients.ts]"]
  node_loan_service["Loan operations<br/>[loans.ts]"]
  node_loan_engine["Schedule engine<br/>[loan-engine.ts]"]
  node_payment_service["Payment recording<br/>[payments.ts]"]
  node_collections_service["Installment collections<br/>[collections.ts]"]
end

subgraph group_fund["Trust fund"]
  node_fund_service["Trust fund ledger<br/>[trustFund.ts]"]
  node_format_utils["Balance utilities<br/>[utils.ts]"]
end

subgraph group_data["Persistence"]
  node_store[("Lending database<br/>[schema.ts]")]
end

node_user(("Lending staff"))

node_user -->|"uses"| node_router
node_router -->|"routes to"| node_client_ui
node_router -->|"routes to"| node_loan_list_ui
node_router -->|"routes to"| node_loan_detail_ui
node_router -->|"routes to"| node_collections_ui
node_router -->|"routes to"| node_contribution_ui
node_client_ui -->|"calls"| node_client_service
node_client_ui -->|"calls"| node_fund_service
node_loan_list_ui -->|"calls"| node_loan_service
node_loan_list_ui -->|"calls"| node_client_service
node_loan_list_ui -->|"calls"| node_fund_service
node_loan_detail_ui -->|"calls"| node_loan_service
node_loan_detail_ui -->|"records payment"| node_payment_service
node_collections_ui -->|"loads view"| node_collections_service
node_contribution_ui -->|"manages funds"| node_fund_service
node_loan_service -->|"generates schedule"| node_loan_engine
node_client_service -->|"reads and writes"| node_store
node_loan_service -->|"reads and writes"| node_store
node_payment_service -->|"records payments"| node_store
node_collections_service -->|"reads installments"| node_store
node_fund_service -->|"reads and writes"| node_store
node_fund_service -->|"gets earnings"| node_loan_service
node_fund_service -->|"lists clients"| node_client_service
node_fund_service -->|"distributes money"| node_loan_engine
node_client_ui -->|"calculates balances"| node_format_utils
node_client_ui -->|"renders controls"| node_ui_primitives
node_loan_list_ui -->|"renders controls"| node_ui_primitives
node_loan_detail_ui -->|"renders controls"| node_ui_primitives
node_collections_ui -->|"renders controls"| node_ui_primitives
node_contribution_ui -->|"renders controls"| node_ui_primitives

click node_router "https://github.com/ldugaduga/lending-app/blob/main/src/router.tsx"
click node_client_ui "https://github.com/ldugaduga/lending-app/blob/main/src/routes/clients.tsx"
click node_loan_list_ui "https://github.com/ldugaduga/lending-app/blob/main/src/routes/loans.index.tsx"
click node_loan_detail_ui "https://github.com/ldugaduga/lending-app/blob/main/src/routes/loans.%24loanId.tsx"
click node_collections_ui "https://github.com/ldugaduga/lending-app/blob/main/src/routes/collections.tsx"
click node_contribution_ui "https://github.com/ldugaduga/lending-app/blob/main/src/routes/contribution.tsx"
click node_ui_primitives "https://github.com/ldugaduga/lending-app/tree/main/src/components/ui"
click node_client_service "https://github.com/ldugaduga/lending-app/blob/main/src/server/clients.ts"
click node_loan_service "https://github.com/ldugaduga/lending-app/blob/main/src/server/loans.ts"
click node_loan_engine "https://github.com/ldugaduga/lending-app/blob/main/src/lib/loan-engine.ts"
click node_payment_service "https://github.com/ldugaduga/lending-app/blob/main/src/server/payments.ts"
click node_collections_service "https://github.com/ldugaduga/lending-app/blob/main/src/server/collections.ts"
click node_fund_service "https://github.com/ldugaduga/lending-app/blob/main/src/server/trustFund.ts"
click node_format_utils "https://github.com/ldugaduga/lending-app/blob/main/src/lib/utils.ts"
click node_store "https://github.com/ldugaduga/lending-app/blob/main/src/db/schema.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_router,node_client_ui,node_loan_list_ui,node_loan_detail_ui,node_collections_ui,node_contribution_ui,node_ui_primitives toneBlue
class node_client_service,node_loan_service,node_loan_engine,node_payment_service,node_collections_service toneAmber
class node_fund_service,node_format_utils toneMint
class node_store toneRose
class node_user toneIndigo
```

## Components

### Web application

- [App routing](https://github.com/ldugaduga/lending-app/blob/main/src/router.tsx): `src/router.tsx`
- [Client management](https://github.com/ldugaduga/lending-app/blob/main/src/routes/clients.tsx): `src/routes/clients.tsx`
- [Loan creation](https://github.com/ldugaduga/lending-app/blob/main/src/routes/loans.index.tsx): `src/routes/loans.index.tsx`
- [Loan details](https://github.com/ldugaduga/lending-app/blob/main/src/routes/loans.%24loanId.tsx): `src/routes/loans.$loanId.tsx`
- [Collections view](https://github.com/ldugaduga/lending-app/blob/main/src/routes/collections.tsx): `src/routes/collections.tsx`
- [Fund contributions](https://github.com/ldugaduga/lending-app/blob/main/src/routes/contribution.tsx): `src/routes/contribution.tsx`
- [UI primitives](https://github.com/ldugaduga/lending-app/tree/main/src/components/ui): `src/components/ui`

### Lending operations

- [Client operations](https://github.com/ldugaduga/lending-app/blob/main/src/server/clients.ts): `src/server/clients.ts`
- [Loan operations](https://github.com/ldugaduga/lending-app/blob/main/src/server/loans.ts): `src/server/loans.ts`
- [Schedule engine](https://github.com/ldugaduga/lending-app/blob/main/src/lib/loan-engine.ts): `src/lib/loan-engine.ts`
- [Payment recording](https://github.com/ldugaduga/lending-app/blob/main/src/server/payments.ts): `src/server/payments.ts`
- [Installment collections](https://github.com/ldugaduga/lending-app/blob/main/src/server/collections.ts): `src/server/collections.ts`

### Trust fund

- [Trust fund ledger](https://github.com/ldugaduga/lending-app/blob/main/src/server/trustFund.ts): `src/server/trustFund.ts`
- [Balance utilities](https://github.com/ldugaduga/lending-app/blob/main/src/lib/utils.ts): `src/lib/utils.ts`

### Persistence

- [Lending database](https://github.com/ldugaduga/lending-app/blob/main/src/db/schema.ts): `src/db/schema.ts`

### Other components

- **Lending staff**

## Connections

- Lending staff → App routing: uses
- App routing → Client management: routes to (evidence: `src/routeTree.gen.ts`)
- App routing → Loan creation: routes to (evidence: `src/routeTree.gen.ts`)
- App routing → Loan details: routes to (evidence: `src/routeTree.gen.ts`)
- App routing → Collections view: routes to (evidence: `src/routeTree.gen.ts`)
- App routing → Fund contributions: routes to (evidence: `src/routeTree.gen.ts`)
- Client management → Client operations: calls (evidence: `src/routes/clients.tsx`)
- Client management → Trust fund ledger: calls (evidence: `src/routes/clients.tsx`)
- Loan creation → Loan operations: calls (evidence: `src/routes/loans.index.tsx`)
- Loan creation → Client operations: calls (evidence: `src/routes/loans.index.tsx`)
- Loan creation → Trust fund ledger: calls (evidence: `src/routes/loans.index.tsx`)
- Loan details → Loan operations: calls (evidence: `src/routes/loans.$loanId.tsx`)
- Loan details → Payment recording: records payment (evidence: `src/routes/loans.$loanId.tsx`)
- Collections view → Installment collections: loads view (evidence: `src/routes/collections.tsx`)
- Fund contributions → Trust fund ledger: manages funds (evidence: `src/routes/contribution.tsx`)
- Loan operations → Schedule engine: generates schedule (evidence: `src/server/loans.ts`)
- Client operations → Lending database: reads and writes (evidence: `src/server/clients.ts`)
- Loan operations → Lending database: reads and writes (evidence: `src/server/loans.ts`)
- Payment recording → Lending database: records payments (evidence: `src/server/payments.ts`)
- Installment collections → Lending database: reads installments (evidence: `src/server/collections.ts`)
- Trust fund ledger → Lending database: reads and writes (evidence: `src/server/trustFund.ts`)
- Trust fund ledger → Loan operations: gets earnings (evidence: `src/server/trustFund.ts`)
- Trust fund ledger → Client operations: lists clients (evidence: `src/server/trustFund.ts`)
- Trust fund ledger → Schedule engine: distributes money (evidence: `src/server/trustFund.ts`)
- Client management → Balance utilities: calculates balances (evidence: `src/routes/clients.tsx`)
- Client management → UI primitives: renders controls (evidence: `src/routes/clients.tsx`)
- Loan creation → UI primitives: renders controls (evidence: `src/routes/loans.index.tsx`)
- Loan details → UI primitives: renders controls (evidence: `src/routes/loans.$loanId.tsx`)
- Collections view → UI primitives: renders controls (evidence: `src/routes/collections.tsx`)
- Fund contributions → UI primitives: renders controls (evidence: `src/routes/contribution.tsx`)
