📝 Configuration
LibreFolio uses a .env file for configuration, powered by Pydantic's BaseSettings. This allows for easy management of environment variables for both local development and
Docker deployments.
📄 .env File
The .env file is located at the root of the project. A sample file, .env.example, is provided. To get started, simply copy it:
🔑 Key Environment Variables
-
PORT: The port on which the FastAPI server will run.- Default:
8000
- Default:
-
DATABASE_URL: The connection string for the main application database.- Default:
sqlite:///./backend/data/prod/sqlite/app.db
- Default:
-
TEST_DATABASE_URL: The connection string for the test database.- Default:
sqlite:///./backend/data/test/sqlite/app.db
- Default:
-
SECRET_KEY: A secret key used for signing JWTs (JSON Web Tokens) for authentication.- Important: For production, this should be changed to a long, random, and secret string.
-
ACCESS_TOKEN_EXPIRE_MINUTES: The expiration time for access tokens in minutes.- Default:
30
- Default:
-
LOG_LEVEL: The logging level for the application.- Options:
DEBUG,INFO,WARNING,ERROR,CRITICAL - Default:
INFO
- Options:
-
LIBREFOLIO_TEST_MODE: A flag to indicate if the application is running in test mode. This is used internally by the test suite.- Set to
1to enable test mode.
- Set to
-
PREVIEW_CACHE_MAX_MB: Maximum size (in MB) for the in-memory image preview cache.- Default:
50 - Cached thumbnails are evicted using LRU when limit is reached.
- Default:
📂 Data Separation
LibreFolio uses separate data directories for production and test:
- Production:
backend/data/prod/(sqlite, custom-uploads, broker_reports, logs) - Test:
backend/data/test/(same structure, completely isolated)
The get_data_dir() function in config.py automatically selects the correct path based on LIBREFOLIO_TEST_MODE.
⚙️ How it Works
The settings are loaded into a Pydantic Settings class located in backend/app/config.py. This class automatically reads variables from the .env file and validates their
types.
This approach provides:
- Type Safety: Settings are validated at application startup.
- Centralized Configuration: All settings are defined in one place.
- Flexibility: Settings can be provided via a
.envfile or as actual environment variables, making it easy to configure in different environments (local, Docker, etc.).