--- title: '05 — Backend Components' description: 'Description of the backend components of the CalMiner application.' status: draft --- - **FastAPI application** (`main.py`): entry point that configures routers, middleware, and startup/shutdown events. - **Routers** (`routes/`): modular route handlers for scenarios, parameters, costs, consumption, production, equipment, maintenance, simulations, and reporting. Each router defines RESTful endpoints, request/response schemas, and orchestrates service calls. - leveraging a shared dependency module (`routes/dependencies.get_db`) for SQLAlchemy session management. - **Models** (`models/`): SQLAlchemy ORM models representing database tables and relationships, encapsulating domain entities like Scenario, CapEx, OpEx, Consumption, ProductionOutput, Equipment, Maintenance, and SimulationResult. - **Services** (`services/`): business logic layer that processes data, performs calculations, and interacts with models. Key services include reporting calculations and Monte Carlo simulation scaffolding. - `services/settings.py`: manages application settings backed by the `application_setting` table, including CSS variable defaults, persistence, and environment-driven overrides that surface in both the API and UI. - **Database** (`config/database.py`): sets up the SQLAlchemy engine and session management for PostgreSQL interactions.