ποΈ System Architecture Overview
LibreFolio is designed as a modern web application with a clear separation between the backend API and the frontend user interface.
πΊοΈ High-Level Diagram
The architecture can be visualized as three main components:
graph TD
subgraph User's Browser
Frontend[SvelteKit Frontend]
end
subgraph Server
Backend[FastAPI Backend]
Database[(SQLite Database)]
end
subgraph External Services
direction TB
BrokerAPIs[Broker APIs / CSVs]
PricingAPIs[Pricing APIs]
FXAPIs[FX Rate APIs]
end
subgraph Plugins
direction TB
B_Plugins[BRIM Plugins]
A_Plugins[Asset Plugins]
F_Plugins[FX Plugins]
end
Frontend -- HTTP API Calls --> Backend
Backend -- SQLAlchemy ORM --> Database
Backend -- Uses --> Plugins
B_Plugins -- Parses --> BrokerAPIs
A_Plugins -- Fetches --> PricingAPIs
F_Plugins -- Fetches --> FXAPIs
π§± Components
-
π₯οΈ Frontend (SvelteKit): A single-page application (SPA) that runs in the user's browser. It communicates with the backend via a RESTful API to fetch and display data.
-
βοΈ Backend (FastAPI): A Python-based API server that handles all business logic, including:
- π User authentication and authorization.
- ποΈ Database operations (CRUD).
- π₯ Data import from brokers (BRIM).
- π Fetching asset prices and FX rates from external sources.
-
ποΈ Database (SQLite): A single-file database that stores all user data, including transactions, assets, user settings, and cached data.
-
π Provider Plugins: A system of pluggable modules that abstract the interaction with external data sources. This makes it easy to add support for new brokers, pricing APIs, or FX rate providers without modifying the core application logic.
π Key Subsystems
For detailed architectural documentation of specific subsystems, see:
- ποΈ Database Schema: Data models and relationships.
- π€ Users & Brokers: Authentication and multi-user access control.
- π Access Control (RBAC): Role-based broker access (Owner/Editor/Viewer).
- βοΈ Settings System: User preferences and global settings.
- π₯ BRIM Architecture: Broker Report Import Manager.
- π Asset Pricing: Asset data fetching and metadata.
- π± FX Architecture: Foreign Exchange system.
- π See also: FX Configuration & Routing for multi-provider setup.
- π File Upload System: Static file uploads with image preview cache (50MB, TTL 1h), avatar seeding, and BRIM file management. See
backend/app/services/static_uploads.py.
π Request Flow Example: Displaying Portfolio
- User logs in and navigates to the dashboard.
- The Frontend makes an API request to
GET /api/v1/portfolio. - The Backend receives the request, authenticates the user, and queries the Database for the user's transactions.
- For each asset, the backend may need to fetch the latest price. It calls the appropriate Asset Provider Plugin (e.g., Yahoo Finance).
- If currency conversion is needed, the backend calls the FX Provider Plugin to get the latest exchange rate.
- The backend processes the data, calculates portfolio metrics, and returns a JSON response to the frontend.
- The Frontend receives the JSON data and renders the portfolio dashboard.
π§° Tech Stack
βοΈ Backend
- π FastAPI: A high-performance web framework for building APIs with Python 3.11+, based on standard Python type hints. It provides automatic interactive documentation (Swagger UI and ReDoc).
- ποΈ SQLAlchemy: The SQL toolkit and Object-Relational Mapper (ORM) used for all database interactions. LibreFolio uses SQLAlchemy's asyncio support for non-blocking database queries.
- π Pydantic: A data validation and settings management library. Used extensively for defining data schemas, validating API requests, and managing application settings.
- π Alembic: A lightweight database migration tool for SQLAlchemy. See Database Migrations.
- ποΈ SQLite: The default database engine. Simple, serverless, and perfect for a self-hosted application. Configured in WAL (Write-Ahead Logging) mode for better concurrency.
π¨ Frontend
- π₯οΈ SvelteKit: A web application framework for building fast, modern user interfaces with server-side rendering, routing, and great developer experience.
- π TypeScript: A statically typed superset of JavaScript that adds type safety to the frontend codebase.
- π¨ TailwindCSS: A utility-first CSS framework for rapidly building custom designs.
- β‘ Vite: The build tool and development server. Provides extremely fast Hot Module Replacement (HMR).
π§ͺ Testing
- π Pytest: The framework used for writing and running backend tests.
- π Playwright: A framework for end-to-end testing of the web application.
- π Coverage.py: A tool for measuring code coverage of Python programs.