Skip to Content
ArchitectureOverview

Architecture Overview

Personal Finances follows a hexagonal (ports & adapters) architecture on the backend, with a clear separation between the Telegram bot interface, the REST API, and the business logic layer.

System Components

┌─────────────────┐ ┌──────────────────────────────────┐ ┌──────────────┐ │ Telegram App │────▶│ FastAPI Backend │────▶│ Supabase │ │ (user sends │ │ ┌─────────────┐ ┌─────────────┐ │ │ (PostgreSQL) │ │ receipts) │ │ │ Telegram │ │ REST API │ │ └──────────────┘ └─────────────────┘ │ │ Adapter │ │ (BFF) │ │ │ └─────────────┘ └─────────────┘ │ ┌──────────────┐ │ │ │ │────▶│ OpenRouter │ │ ▼ ▼ │ │ (LLM API) │ │ ┌─────────────────────────────┐ │ └──────────────┘ │ │ Domain / Use Cases │ │ │ └─────────────────────────────┘ │ └──────────────────────────────────┘ ┌───────────────┘ ┌───────────────┐ │ Next.js │ │ Dashboard │ └───────────────┘

Key Design Decisions

DecisionRationale
OpenRouter instead of Anthropic directOpenAI-compatible SDK; easier model switching
Two LLM modelsSonnet 4.6 for vision/reports (quality); Haiku 4.5 for text tasks (cost)
Mandatory confirmationNever persist an expense without explicit user approval
In-memory pending stateKeeps DB clean; TTL 10 min to auto-expire unconfirmed entries
OpenAPI hidden in productionSecurity hardening; enabled only in development

Sub-sections

  • Backend — hexagonal layers, package layout
  • Frontend — Next.js structure, auth flow
  • Telegram Bot — bot flow, commands, confirmation
Last updated on