Skip to content

Commit b15a02a

Browse files
committed
some initial docs
1 parent 62d072c commit b15a02a

28 files changed

Lines changed: 8290 additions & 4 deletions

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
# UI
1616
ui/node_modules/
1717
ui/dist/
18+
19+
# Docs
20+
docs/site/node_modules/
21+
docs/site/_site/
1822
ui/.vite/
1923
ui/test-results/
2024
ui/playwright-report/
@@ -41,7 +45,3 @@ logs/
4145
# Backups
4246
*.bak
4347
backups/
44-
45-
# Private docs (not yet public)
46-
docs/
47-
CLAUDE.md

CLAUDE.md

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
# CLAUDE.md - Development Context for Hone
2+
3+
This file provides context for AI-assisted development sessions.
4+
5+
## Project Overview
6+
7+
Hone is a self-hosted personal finance tool that detects wasteful spending:
8+
- Zombie subscriptions (forgotten recurring charges)
9+
- Price increases (services that quietly raised prices)
10+
- Duplicate services (multiple streaming/storage/etc)
11+
12+
## Architecture
13+
14+
See `README.md` for architecture diagram. Stack: React + Vite frontend, Axum REST API, SQLite database.
15+
16+
## Crate Structure
17+
18+
- **hone-core**: Shared library
19+
- `db/` - SQLite with r2d2 pooling, SQLCipher encryption
20+
- `backup/` - Pluggable backup system (local filesystem, R2 stub)
21+
- `models.rs` - Domain types
22+
- `import.rs` - CSV parsers for major US banks
23+
- `export.rs` - Transaction CSV export, full JSON backup/restore
24+
- `detect.rs` - Waste detection algorithms
25+
- `tags.rs` - Tag assignment engine
26+
- `ai/` - Pluggable local AI backend (Ollama, OpenAI-compatible, Mock)
27+
- `prompts.rs` - Prompt library with override support
28+
- `model_router.rs` - Task-based model routing with health tracking
29+
- `context.rs` - Context assembler for LLM prompts
30+
- `training.rs`, `training_pipeline.rs` - Fine-tuning infrastructure
31+
- `insights/` - Proactive financial insights engine
32+
33+
- **hone-cli**: Command-line interface
34+
- `commands/` - Command implementations split by domain
35+
- Commands: init, import, detect, serve, dashboard, status, accounts, transactions, subscriptions, alerts, entities, tags, rules, tag, untag, report, receipts, ollama, prompts, training, export, import-full, backup, rebuild, reset
36+
37+
- **hone-server**: Axum REST API
38+
- `lib.rs` - Server config, router, auth middleware, security headers
39+
- `handlers/` - Domain-specific HTTP handlers (22 modules)
40+
- `mcp/` - MCP server for LLM tool access (enable with `--mcp-port 3001`)
41+
- Cloudflare Access authentication, audit logging
42+
43+
## Key Design Decisions
44+
45+
1. **CSV-only import** - No bank credentials stored, privacy-first
46+
2. **Encryption required** - SQLCipher encryption by default (`HONE_DB_KEY`); `--no-encrypt` for dev
47+
3. **Local AI only** - Ollama and OpenAI-compatible servers. No cloud APIs
48+
4. **Deduplication** - SHA256 hash of (date, description, amount) prevents double-imports
49+
5. **Secure by default** - Cloudflare Access auth required; `--no-auth` for local dev
50+
6. **Audit logging** - All API access logged
51+
7. **Full processing by default** - Import runs tagging + detection automatically
52+
8. **Raw data preservation** - Original CSV data stored as JSON for reprocessing
53+
54+
## Development Stage
55+
56+
**Pre-shipping**: We are NOT yet at the "shipping" stage. This means:
57+
- **No migrations required** - Schema changes can be made directly; just reset the database
58+
- **No backwards compatibility** - APIs, data formats, and behavior can change freely
59+
- **No deprecation cycles** - Old code/approaches can be removed immediately
60+
61+
When we explicitly agree to enter the "shipping" stage, we'll add migrations and maintain backwards compatibility.
62+
63+
## Database Schema
64+
65+
Key tables (see `docs/SPLITS_DESIGN.md` for entity/split schema):
66+
- `accounts` - Bank accounts with optional `entity_id`
67+
- `transactions` - Individual charges (with `archived`, `original_data`, `import_format`)
68+
- `subscriptions` - Detected recurring patterns with `account_id`
69+
- `alerts` - Waste detection findings
70+
- `tags` - Hierarchical category tags (17 root tags seeded)
71+
- `transaction_tags` - Transaction-to-tag mapping with source tracking
72+
- `tag_rules` - User-defined patterns for auto-tagging
73+
- `audit_log` - API access history
74+
- `entities` - People, pets, vehicles, properties
75+
- `locations`, `trips`, `mileage_logs` - Location and travel tracking
76+
- `receipts` - Receipt storage with status workflow
77+
- `merchant_*_cache` - Learned merchant classifications, names, tags
78+
- `import_sessions`, `import_skipped_transactions` - Import tracking
79+
- `user_feedback` - Feedback on AI-generated content
80+
- `training_experiments` - Fine-tuning experiment tracking
81+
- `reprocess_runs`, `reprocess_snapshots` - Reprocess comparison
82+
- `insight_findings` - Proactive financial insights
83+
- `ollama_metrics` - AI call tracking (latency, success, tool calls metadata for explore queries)
84+
85+
## Current State
86+
87+
See `docs/FEATURES.md` for comprehensive feature list.
88+
89+
**Test coverage**: 788 Rust tests, Playwright UX tests
90+
91+
**Not yet implemented**: Cloud backup to Cloudflare R2 (stub ready)
92+
93+
## Detection Algorithms
94+
95+
See `docs/DETECTION.md` for algorithm details. Six algorithms:
96+
- Zombie Detection - forgotten recurring charges
97+
- Price Increase Detection - subscription price changes
98+
- Duplicate Detection - multiple services in same category
99+
- Auto-Cancellation Detection - stopped subscriptions
100+
- Resume Detection - reactivated subscriptions
101+
- Spending Anomaly Detection - unusual spending patterns
102+
103+
## AI Integration
104+
105+
See `docs/ollama.md` for setup and configuration.
106+
107+
**Three modes:**
108+
1. **Classification Mode** (`OLLAMA_HOST`) - merchant classification, normalization, subscription detection
109+
2. **Agentic Mode** (`ANTHROPIC_COMPATIBLE_HOST`) - tool-calling for deeper analysis
110+
3. **Explore Mode** - conversational interface using agentic mode to answer financial questions
111+
- Multi-turn conversations with session persistence
112+
- Model selector to switch between available Ollama models at runtime
113+
- Queries tracked in AI Metrics as `explore_query` operations with tool call history
114+
115+
**Prompts**: Stored in `prompts/` with override support (`~/.local/share/hone/prompts/overrides/`)
116+
117+
**Model routing**: Config in `config/models.toml` with task-based routing and health tracking
118+
119+
## Development Commands
120+
121+
```bash
122+
# Build
123+
make build
124+
125+
# Run backend (port 3000)
126+
export HONE_DB_KEY="your-passphrase-here"
127+
cargo run -- serve --port 3000
128+
129+
# Run frontend dev server (port 5173)
130+
cd ui && npm run dev
131+
132+
# Enable Ollama
133+
export OLLAMA_HOST="http://localhost:11434"
134+
export OLLAMA_MODEL="gemma3"
135+
136+
# Quick test flow
137+
cargo run -- --no-encrypt init
138+
cargo run -- --no-encrypt import --file samples/sample.csv
139+
cargo run -- --no-encrypt dashboard
140+
141+
# Reset database
142+
cargo run -- --no-encrypt reset --soft -y
143+
144+
# Run tests
145+
cd ui && npm run test:ux
146+
```
147+
148+
## UI Structure
149+
150+
```
151+
ui/src/
152+
├── components/
153+
│ ├── common/ # Shared UI components
154+
│ ├── Dashboard/ # Dashboard view
155+
│ ├── Transactions/ # Transaction list, detail tabs
156+
│ ├── Subscriptions/ # Subscription management
157+
│ ├── Alerts/ # Alert cards with detail modal
158+
│ ├── Insights/ # Proactive insights
159+
│ ├── Import/ # CSV import, history
160+
│ ├── Tags/ # Tag tree management
161+
│ ├── Reports/ # Charts and reports (Recharts)
162+
│ ├── Receipts/ # Receipt upload, linking
163+
│ ├── Ollama/ # AI Metrics page (all AI call tracking)
164+
│ ├── Feedback/ # Feedback history page
165+
│ └── Explore/ # Conversational query interface with model selector
166+
├── hooks/ # Custom React hooks
167+
├── App.tsx # Layout and routing
168+
├── api.ts # API client
169+
└── types.ts # TypeScript interfaces
170+
```
171+
172+
## Code Style
173+
174+
- Rust: Follow standard idioms, use Result types, propagate errors with `?`
175+
- TypeScript: Strict mode, prefer named exports
176+
- CSS: Tailwind utilities, custom components in index.css
177+
- Comments: Explain "why" not "what"
178+
179+
## UI Design Principles
180+
181+
- Clean, confident typography - numbers feel important
182+
- Semantic color: green=income, amber=attention, red=waste (not all expenses)
183+
- Normal expenses use neutral colors
184+
- Subtle motion - alive but not distracting
185+
- Satisfying interactions
186+
- No clutter - every element earns its place
187+
188+
## Dark Mode Patterns
189+
190+
Tailwind dark mode uses `dark:` prefix (follows system preference).
191+
192+
- Primary text: `text-hone-900 dark:text-hone-100`
193+
- Secondary text: `text-hone-600 dark:text-hone-400`
194+
- Cards: `bg-white dark:bg-hone-900` (via `.card` class)
195+
- Table headers: `bg-hone-50 dark:bg-hone-800`
196+
- Hover: `hover:bg-hone-50 dark:hover:bg-hone-800`
197+
198+
## Test Data Guidelines
199+
200+
- Major public company names are fine (Netflix, Amazon, Costco)
201+
- Avoid small regional/local business names
202+
- Use fictional names for non-public entities
203+
204+
## Deployment
205+
206+
See `docs/deployment.md` for Docker deployment guide.
207+
208+
Docker images: `ghcr.io/heskew/hone-money` (multi-arch: amd64, arm64)

docs/.eleventyignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Uppercase docs are internal reference only
2+
FEATURES.md
3+
DETECTION.md
4+
SPLITS_DESIGN.md
5+
6+
# Site build artifacts
7+
site/
8+
_site/
9+
10+
# Other ignores
11+
node_modules/
12+
README.md

docs/DETECTION.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
title: Detection Algorithms
3+
description: How Hone identifies wasteful spending
4+
date: 2026-01-24
5+
---
6+
7+
# Detection Algorithms
8+
9+
Hone uses six detection algorithms to identify wasteful spending.
10+
11+
## Subscription Pre-Filter
12+
13+
Before creating subscriptions, a two-layer filter reduces false positives:
14+
15+
1. Check `merchant_subscription_cache` for cached classifications
16+
2. User exclusions (`source='user_override'`) take precedence over Ollama
17+
3. Ollama classifies unknown merchants as SUBSCRIPTION or RETAIL
18+
4. Retail merchants (grocery stores, gas stations) are skipped
19+
20+
## Zombie Detection
21+
22+
Identifies forgotten recurring charges.
23+
24+
1. Group transactions by (account_id, merchant) for account-specific subscriptions
25+
2. Identify recurring patterns (consistent amount, regular interval)
26+
3. Flag if: recurring 3+ months AND user hasn't acknowledged
27+
4. Skip excluded subscriptions (user marked "not a subscription")
28+
29+
### Stale Acknowledgment Re-check
30+
31+
Acknowledged subscriptions are re-checked after 90 days (configurable via `acknowledgment_stale_days`):
32+
33+
1. Track `acknowledged_at` timestamp when user acknowledges subscription
34+
2. If acknowledgment is older than threshold (default 90 days), treat as unacknowledged
35+
3. Subscription will be flagged as zombie again, prompting user to re-confirm
36+
4. Re-acknowledging updates the timestamp, resetting the 90-day window
37+
5. Legacy subscriptions without timestamp are treated as freshly acknowledged
38+
39+
## Price Increase Detection
40+
41+
Tracks subscription price changes.
42+
43+
1. Track subscription amounts over time
44+
2. Alert if: current > 3-months-ago by >5% or >$1
45+
3. Skip excluded subscriptions
46+
47+
## Duplicate Detection
48+
49+
Finds multiple services in the same category.
50+
51+
1. Categorize subscriptions (streaming, music, cloud storage, etc.)
52+
2. Alert if: 2+ active subscriptions in same category
53+
3. Ollama explains overlap and unique features (when enabled)
54+
55+
## Auto-Cancellation Detection
56+
57+
Detects subscriptions that stopped charging.
58+
59+
1. Check acknowledged subscriptions for missed expected charges
60+
2. Apply grace period:
61+
- 7 days for monthly
62+
- 3 days for weekly
63+
- 30 days for yearly
64+
3. Auto-mark as cancelled if expected charge date + grace period has passed
65+
4. Feeds into savings report
66+
67+
## Resume Detection
68+
69+
Catches reactivated subscriptions.
70+
71+
1. Check cancelled subscriptions for new matching transactions
72+
2. If new charge found after cancellation, reactivate subscription
73+
3. Create Resume alert to notify user
74+
4. Mark as acknowledged to prevent immediate zombie flagging
75+
76+
## Spending Anomaly Detection
77+
78+
Flags unusual spending patterns.
79+
80+
1. Compare current month spending by category vs 3-month rolling average baseline
81+
2. Alert if: increase >30% OR decrease >40% from baseline
82+
3. Only trigger if baseline >= $50 (avoid noise from low-spend categories)
83+
4. Ollama provides explanation with summary and reasons when available
84+
5. Re-analysis: can re-run with different models via API/UI
85+
86+
## Subscription Detection Thresholds
87+
88+
### Strict Pattern Matching (Default)
89+
- Requires 3+ transactions
90+
- 5% max amount variance
91+
- 70% interval consistency
92+
- Reduces false positives from regular shopping
93+
94+
### Smart Detection (Ollama-Enhanced)
95+
When Ollama confirms merchant is a subscription service (>=70% confidence):
96+
- 50% amount variance allowed (for variable charges like utilities)
97+
- 50% interval consistency
98+
- 2 minimum transactions
99+
- Catches metered services (AWS, utility bills)
100+
101+
Configuration via `DetectionConfig`:
102+
- `smart_amount_variance`
103+
- `smart_interval_consistency`
104+
- `smart_min_transactions`
105+
- `ollama_confidence_threshold`

0 commit comments

Comments
 (0)