# carson-lianng/asset-snapshot architecture

> Architecture diagram of the GitHub repository carson-lianng/asset-snapshot, 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/carson-lianng/asset-snapshot
- Repository: https://github.com/carson-lianng/asset-snapshot

## Overview

家底快照是本机单用户资产盘点与净值追踪工具。用户通过网页维护账户和字典，在盘点流程中记录余额并保存快照，再查看净值趋势、收益、快照对比和报表；设置还提供 CSV/JSON 导入导出及备份恢复。图中呈现网页、API 路由、领域计算和 SQLite 数据层。部分路由及领域实现未提供源码摘录，因此仅按 README 或索引确认的调用关系连线。

Main entry points: [`app/web/src/App.tsx`](https://github.com/carson-lianng/asset-snapshot/blob/main/app/web/src/App.tsx) (网页应用), [`app/server/src/app.ts`](https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/app.ts) (请求装配与防护), [`app/server/src/modules/data.ts`](https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/modules/data.ts) (导入导出与备份), [`app/server/src/main.ts`](https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/main.ts) (本机服务入口)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["网页体验"]
  node_webapp["网页应用<br/>[App.tsx]"]
  node_webboot["网页启动<br/>[main.tsx]"]
  node_api_client["API 数据源与缓存<br/>[index.ts]"]
  node_inventory_ui["盘点流程<br/>[InventoryPage.tsx]"]
  node_accounts_ui["账户管理<br/>[AccountsPage.tsx]"]
  node_snapshots_ui["快照与对比"]
  node_reports_ui["报表分析<br/>[ReportsPage.tsx]"]
  node_settings_ui["设置与数据迁移<br/>[SettingsPage.tsx]"]
  node_help_ui["使用手册<br/>[HelpPage.tsx]"]
end

subgraph group_api["服务端 API"]
  node_server["本机服务入口<br/>[main.ts]"]
  node_http_app["请求装配与防护<br/>[app.ts]"]
  node_accounts_api["账户接口<br/>[accounts.ts]"]
  node_catalog_api["字典与汇率接口<br/>[catalog.ts]"]
  node_inventory_api["盘点接口<br/>[inventory.ts]"]
  node_snapshots_api["快照接口<br/>[snapshots.ts]"]
  node_reports_api["报表接口<br/>[reports.ts]"]
  node_data_api["导入导出与备份<br/>[data.ts]"]
end

subgraph group_domain["资产计算"]
  node_domain_money["定点金额计算<br/>[money.ts]"]
  node_domain_inventory["盘点规则<br/>[inventory.ts]"]
  node_domain_returns["收益计算<br/>[returns.ts]"]
end

subgraph group_storage["本地数据"]
  node_sqlite[("SQLite 数据库<br/>[client.ts]")]
  node_repo["数据读取层<br/>[repo.ts]"]
  node_writes["数据写入层<br/>[writes.ts]"]
  node_backup["备份恢复<br/>[backup.ts]"]
  node_seed["演示数据<br/>[seed.ts]"]
end

node_user(("本机用户"))

node_user -->|"使用"| node_webapp
node_webboot -->|"挂载"| node_webapp
node_webapp -->|"呈现"| node_inventory_ui
node_webapp -->|"呈现"| node_accounts_ui
node_webapp -->|"呈现"| node_snapshots_ui
node_webapp -->|"呈现"| node_reports_ui
node_webapp -->|"呈现"| node_settings_ui
node_webapp -->|"呈现"| node_help_ui
node_webboot -->|"预热数据"| node_api_client
node_webapp -->|"发起变更"| node_api_client
node_server -->|"打开数据库"| node_sqlite
node_server -->|"创建服务"| node_http_app
node_http_app -->|"挂载路由"| node_accounts_api
node_http_app -->|"挂载路由"| node_catalog_api
node_http_app -->|"挂载路由"| node_inventory_api
node_http_app -->|"挂载路由"| node_snapshots_api
node_http_app -->|"挂载路由"| node_reports_api
node_http_app -->|"挂载路由"| node_data_api
node_inventory_api -.->|"读取数据"| node_repo
node_inventory_api -.->|"保存盘点"| node_writes
node_data_api -->|"读取数据"| node_repo
node_data_api -->|"写入数据"| node_writes
node_data_api -->|"执行备份"| node_backup
node_server -->|"初始化种子"| node_seed
node_repo -->|"访问数据库"| node_sqlite
node_domain_inventory -->|"使用金额"| node_domain_money
node_domain_returns -->|"使用金额"| node_domain_money

click node_webapp "https://github.com/carson-lianng/asset-snapshot/blob/main/app/web/src/App.tsx"
click node_webboot "https://github.com/carson-lianng/asset-snapshot/blob/main/app/web/src/main.tsx"
click node_api_client "https://github.com/carson-lianng/asset-snapshot/blob/main/app/web/src/api/index.ts"
click node_inventory_ui "https://github.com/carson-lianng/asset-snapshot/blob/main/app/web/src/features/inventory/InventoryPage.tsx"
click node_accounts_ui "https://github.com/carson-lianng/asset-snapshot/blob/main/app/web/src/features/accounts/AccountsPage.tsx"
click node_snapshots_ui "https://github.com/carson-lianng/asset-snapshot/blob/main/app/web/src/features/snapshots/SnapshotsListPage.tsx"
click node_reports_ui "https://github.com/carson-lianng/asset-snapshot/blob/main/app/web/src/features/reports/ReportsPage.tsx"
click node_settings_ui "https://github.com/carson-lianng/asset-snapshot/blob/main/app/web/src/features/settings/SettingsPage.tsx"
click node_help_ui "https://github.com/carson-lianng/asset-snapshot/blob/main/app/web/src/features/help/HelpPage.tsx"
click node_server "https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/main.ts"
click node_http_app "https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/app.ts"
click node_accounts_api "https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/modules/accounts.ts"
click node_catalog_api "https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/modules/catalog.ts"
click node_inventory_api "https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/modules/inventory.ts"
click node_snapshots_api "https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/modules/snapshots.ts"
click node_reports_api "https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/modules/reports.ts"
click node_data_api "https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/modules/data.ts"
click node_domain_money "https://github.com/carson-lianng/asset-snapshot/blob/main/app/domain/src/money.ts"
click node_domain_inventory "https://github.com/carson-lianng/asset-snapshot/blob/main/app/domain/src/inventory.ts"
click node_domain_returns "https://github.com/carson-lianng/asset-snapshot/blob/main/app/domain/src/returns.ts"
click node_sqlite "https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/db/client.ts"
click node_repo "https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/db/repo.ts"
click node_writes "https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/db/writes.ts"
click node_backup "https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/db/backup.ts"
click node_seed "https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/db/seed.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_webapp,node_webboot,node_api_client,node_inventory_ui,node_accounts_ui,node_snapshots_ui,node_reports_ui,node_settings_ui,node_help_ui toneBlue
class node_server,node_http_app,node_accounts_api,node_catalog_api,node_inventory_api,node_snapshots_api,node_reports_api,node_data_api toneAmber
class node_domain_money,node_domain_inventory,node_domain_returns toneMint
class node_sqlite,node_repo,node_writes,node_backup,node_seed toneRose
class node_user toneIndigo
```

## Components

### 网页体验

- [网页应用](https://github.com/carson-lianng/asset-snapshot/blob/main/app/web/src/App.tsx): `app/web/src/App.tsx`
- [网页启动](https://github.com/carson-lianng/asset-snapshot/blob/main/app/web/src/main.tsx): `app/web/src/main.tsx`
- [API 数据源与缓存](https://github.com/carson-lianng/asset-snapshot/blob/main/app/web/src/api/index.ts): `app/web/src/api/index.ts`
- [盘点流程](https://github.com/carson-lianng/asset-snapshot/blob/main/app/web/src/features/inventory/InventoryPage.tsx): `app/web/src/features/inventory/InventoryPage.tsx`
- [账户管理](https://github.com/carson-lianng/asset-snapshot/blob/main/app/web/src/features/accounts/AccountsPage.tsx): `app/web/src/features/accounts/AccountsPage.tsx`
- [快照与对比](https://github.com/carson-lianng/asset-snapshot/blob/main/app/web/src/features/snapshots/SnapshotsListPage.tsx): `app/web/src/features/snapshots/SnapshotsListPage.tsx`
- [报表分析](https://github.com/carson-lianng/asset-snapshot/blob/main/app/web/src/features/reports/ReportsPage.tsx): `app/web/src/features/reports/ReportsPage.tsx`
- [设置与数据迁移](https://github.com/carson-lianng/asset-snapshot/blob/main/app/web/src/features/settings/SettingsPage.tsx): `app/web/src/features/settings/SettingsPage.tsx`
- [使用手册](https://github.com/carson-lianng/asset-snapshot/blob/main/app/web/src/features/help/HelpPage.tsx): `app/web/src/features/help/HelpPage.tsx`

### 服务端 API

- [本机服务入口](https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/main.ts): `app/server/src/main.ts`
- [请求装配与防护](https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/app.ts): `app/server/src/app.ts`
- [账户接口](https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/modules/accounts.ts): `app/server/src/modules/accounts.ts`
- [字典与汇率接口](https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/modules/catalog.ts): `app/server/src/modules/catalog.ts`
- [盘点接口](https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/modules/inventory.ts): `app/server/src/modules/inventory.ts`
- [快照接口](https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/modules/snapshots.ts): `app/server/src/modules/snapshots.ts`
- [报表接口](https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/modules/reports.ts): `app/server/src/modules/reports.ts`
- [导入导出与备份](https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/modules/data.ts): `app/server/src/modules/data.ts`

### 资产计算

- [定点金额计算](https://github.com/carson-lianng/asset-snapshot/blob/main/app/domain/src/money.ts): `app/domain/src/money.ts`
- [盘点规则](https://github.com/carson-lianng/asset-snapshot/blob/main/app/domain/src/inventory.ts): `app/domain/src/inventory.ts`
- [收益计算](https://github.com/carson-lianng/asset-snapshot/blob/main/app/domain/src/returns.ts): `app/domain/src/returns.ts`

### 本地数据

- [SQLite 数据库](https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/db/client.ts): `app/server/src/db/client.ts`
- [数据读取层](https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/db/repo.ts): `app/server/src/db/repo.ts`
- [数据写入层](https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/db/writes.ts): `app/server/src/db/writes.ts`
- [备份恢复](https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/db/backup.ts): `app/server/src/db/backup.ts`
- [演示数据](https://github.com/carson-lianng/asset-snapshot/blob/main/app/server/src/db/seed.ts): `app/server/src/db/seed.ts`

### Other components

- **本机用户**

## Connections

- 本机用户 → 网页应用: 使用 (evidence: `README.md`)
- 网页启动 → 网页应用: 挂载 (evidence: `app/web/src/main.tsx`)
- 网页应用 → 盘点流程: 呈现 (evidence: `app/web/src/App.tsx`)
- 网页应用 → 账户管理: 呈现 (evidence: `app/web/src/App.tsx`)
- 网页应用 → 快照与对比: 呈现 (evidence: `app/web/src/App.tsx`)
- 网页应用 → 报表分析: 呈现 (evidence: `app/web/src/App.tsx`)
- 网页应用 → 设置与数据迁移: 呈现 (evidence: `app/web/src/App.tsx`)
- 网页应用 → 使用手册: 呈现 (evidence: `app/web/src/App.tsx`)
- 网页启动 → API 数据源与缓存: 预热数据 (evidence: `app/web/src/main.tsx`)
- 网页应用 → API 数据源与缓存: 发起变更 (evidence: `app/web/src/App.tsx`)
- 本机服务入口 → SQLite 数据库: 打开数据库 (evidence: `app/server/src/main.ts`)
- 本机服务入口 → 请求装配与防护: 创建服务 (evidence: `app/server/src/main.ts`)
- 请求装配与防护 → 账户接口: 挂载路由 (evidence: `app/server/src/app.ts`)
- 请求装配与防护 → 字典与汇率接口: 挂载路由 (evidence: `app/server/src/app.ts`)
- 请求装配与防护 → 盘点接口: 挂载路由 (evidence: `app/server/src/app.ts`)
- 请求装配与防护 → 快照接口: 挂载路由 (evidence: `app/server/src/app.ts`)
- 请求装配与防护 → 报表接口: 挂载路由 (evidence: `app/server/src/app.ts`)
- 请求装配与防护 → 导入导出与备份: 挂载路由 (evidence: `app/server/src/app.ts`)
- 盘点接口 → 数据读取层: 读取数据
- 盘点接口 → 数据写入层: 保存盘点
- 导入导出与备份 → 数据读取层: 读取数据 (evidence: `app/server/src/modules/data.ts`)
- 导入导出与备份 → 数据写入层: 写入数据 (evidence: `app/server/src/modules/data.ts`)
- 导入导出与备份 → 备份恢复: 执行备份 (evidence: `app/server/src/modules/data.ts`)
- 本机服务入口 → 演示数据: 初始化种子 (evidence: `app/server/src/main.ts`)
- 数据读取层 → SQLite 数据库: 访问数据库 (evidence: `app/server/src/db/repo.ts`)
- 盘点规则 → 定点金额计算: 使用金额 (evidence: `app/domain/src/inventory.ts`)
- 收益计算 → 定点金额计算: 使用金额 (evidence: `app/domain/src/returns.ts`)
