⚙️ Settings System
LibreFolio has a two-tiered settings system — User Settings (per-user preferences) and
Global Settings (instance-wide, admin-managed) — held together by a single declarative
catalogue, SETTINGS_REGISTRY. The settings that plugins declare for themselves are a separate
system: see Plugin Settings.
A third layer, outside these two tiers: process configuration (.env)
Startup values (ports, data folder, log level, instance profile, secrets, risk-engine workers)
come from .env and the environment; the admin-facing list is
Configuration. How they load:
Settings(BaseSettings)inbackend/app/config/__init__.pyreads the project-root.env; environment variables override it, names are case-sensitive, unknown keys are ignored.get_settings()builds a fresh, validated instance on every call.main.pycalls it at import, so a mistyped or out-of-range value stops the startup. It also computesDATABASE_URLand applies theLIBREFOLIO_LOG_LEVELoverride.- Profile defaults (
PROFILE_DEFAULTSin__init__.py, decisions D5 and F27): for each profileLIBREFOLIO_PROFILEaccepts, the values it gives theSettingsfields that the environment and.envleave unset.selfhostedlists none: a self-hosted install keeps every code default.managedsetsRISK_SIMULATION_IDLE_TIMEOUT_SECONDSandRISK_OPTIMIZATION_IDLE_TIMEOUT_SECONDSto60.0and turns onLIBREFOLIO_FRAME_PROTECTIONandLIBREFOLIO_CSP_REPORT_ONLY, twoboolfields off in the code (The Content-Security-Policy and Frame Protection).Settings._apply_profile_defaults, amodel_validator(mode="after"), gives the active profile's value (LIBREFOLIO_PROFILEalready normalised by its field validator) to every listed field that is not inmodel_fields_set. pydantic-settings passes every value a source found, so a value the operator set wins even when it equals the code default:RISK_SIMULATION_IDLE_TIMEOUT_SECONDS=600orLIBREFOLIO_FRAME_PROTECTION=falsestay on a managed instance. The value is written withobject.__setattr__, not by assignment: an assignment would add the field tomodel_fields_set, and later code could no longer tell an operator's value from the profile's. Either way the value is not validated (Settingshas novalidate_assignment), so./dev.py test services profile-defaults(backend/test_scripts/test_services/test_profile_defaults.py) checks the table strictly: one entry per profileLIBREFOLIO_PROFILEaccepts; every key aSettingsfield with a code default; every value valid for its field in strict mode and, formanaged, different from the code default; a set value kept; and, parametrised over every field any profile lists, the code default kept by a self-hosted install. The table reachesSettingsfields only; the variables of the section modules have their own table, in the next point. To give aSettingsfield a new managed default, a workstream adds one entry toPROFILE_DEFAULTS["managed"]: a field with a code default, and a value of the field's own type, written as its code default is (60.0,True; never"60", nor1for a flag), that differs from the code default. It adds the same entry toMANAGED_DEFAULTSin the test file, the decided table thatPROFILE_DEFAULTS["managed"]must equal; the parametrised cases (the managed value given to a field nobody set, the guards on the table, the self-hosted code defaults) then cover the new field. A new securitySettingsfield states its managed value there in the same lot, or says whymanagedkeeps the code default: a review rule, row «Config & Data Paths» of.github/instructions/backend.instructions.md. At run time nothing refuses a managed entry lost from the table, nor a value an operator sets: for the two security switches, the configuration checksplatform.frame_protection, awarning, andplatform.csp_report_only, aninfo, show a managed instance where either is off (H-39; see Configuration Checks). - Profile defaults of the section modules' variables (
ENVIRONMENT_PROFILE_DEFAULTSin__init__.py): for each profile, the values it gives the variables that a section module ofbackend/app/config/reads fromos.environ, outsideSettings.selfhostedlists none: a self-hosted install keeps every code default. A section module callsprofile_default(name, fallback), and only while its variable is unset. Underselfhostedthe function returnsfallbackitself, the code's own default. Any other profile (todaymanaged) must listname, and the function returns that profile's value: a name it does not list raisesProfileDefaultError(H-37), naming the variable, the profile and the table, and the reader stops. A missing entry thus fails closed instead of quietly giving a managed instance the self-hosted behaviour (no upload limit for a restore, below). The profile isget_settings().LIBREFOLIO_PROFILE, read at each call. A blank or an invalid value stays under the module's own rules: a module can, for example, treat a blank value as unset, and answer an invalid one with a coded error when the value is used rather than stop the startup.profile_default()converts nothing, but checks the active profile's entry before returning it: the entry must be of the exact type offallback, the reader's own default (500for the fallback0; neverNone,"500",500.0norTrue:Truedoes not pass for anintfallback, nor60for afloatone). An entry of any other type raisesProfileDefaultErrortoo, aTypeErrordefined in__init__.pywhose message names the variable, the profile, both types and the table, and the reader stops instead of using the value: unchecked, aNoneundermanagedwould mean no upload limit at all for a restore (backup_max_upload_mb(), below). Underselfhosted, the fallback itself is returned unchecked. Both checks, for a missing entry and for an entry's type, run at the reader's call, never as a startup check of their own: only the reader knows the variables it reads and the type it expects; the table is code, guarded before release by the tests below; and a startup refused for one missing entry would take every managed instance down, where a reader that stops closes only the feature that reads it. The backup's startup checks call the upload limit's reader, and only log its error (Configuration Checks of the Backup). The first entry is the upload limit of a restore:LIBREFOLIO_BACKUP_MAX_UPLOAD_MB,500megabytes inmanaged(decision 43), read bybackup_max_upload_mb()inconfig/backup.pywithprofile_default(MAX_UPLOAD_VARIABLE, 0): no limit on a self-hosted install. Since B-35 the same entry also bounds a restore's check:LIBREFOLIO_BACKUP_MAX_RESTORE_MB, the most an archive may unpack to, read bybackup_max_restore_mb()in the same module, is, when unset,RESTORE_TO_UPLOAD_RATIO(8) times the upload limit in any profile butselfhosted(4000 megabytes inmanaged;0, no limit, when the upload limit is none), and0underselfhosted; an explicit value always wins,0meaning no limit../dev.py test services profile-defaultsguards this table too: one entry per profile;selfhostedempty;managedequal, value and type, toENVIRONMENT_MANAGED_DEFAULTS, the decided table of the test file; no key that is aSettingsfield or sits in both tables; every key read, as a string constant, by a section module, and documented in.env.example; for every listed name,profile_default()returning the fallback underselfhostedand the table's value undermanaged; undermanaged, a name the table does not list raisingProfileDefaultError, as an entry of another type does, whileselfhostedstill gets the fallback; the realbackup_max_upload_mb()raising on aNonemanaged entry, and on a managed entry removed, instead of lifting the limit; and, read in the sources, everyprofile_default(NAME, …)call of a section module written with a literal fallback, checked both ways: every entry of the table read by such a call, of exactly the type of the call's fallback, and every call'sNAMElisted by every profile butselfhosted(H-37). Two self-tests check that the guard reports a broken table:Nonefor the managed entry of the upload limit (the type), and that entry removed (the listing). To read a new variable throughprofile_default, a workstream adds its entry toENVIRONMENT_PROFILE_DEFAULTS["managed"]: mandatory, even at the fallback's own value whenmanagedkeeps the self-hosted behaviour, since a namemanageddoes not list raises. It adds the same entry toENVIRONMENT_MANAGED_DEFAULTSin the test file, says the managed value in the variable's commented line of.env.example, and callsprofile_default(NAME, fallback)in its section module while the variable is unset, with a literal fallback of the variable's own type, as the upload limit's0. get_data_dir()picks the data root: in test modeLIBREFOLIO_TEST_DATA_DIRorbackend/data/test(refused if it overlaps production), otherwiseLIBREFOLIO_DATA_DIR, otherwisebackend/data/prod.- Keys outside the class —
LIBREFOLIO_DATA_DIR,LIBREFOLIO_TEST_DATA_DIR,LIBREFOLIO_TEST_MODE,LIBREFOLIO_LOG_LEVEL,JWT_SECRET,LIBREFOLIO_INSTANCE_KEY(both also as_FILE),LIBREFOLIO_NO_SCHEDULER,LIBREFOLIO_DISABLE_DONATION_POPUP,LIBREFOLIO_DISABLE_WHATS_NEW(both hidden switches, set by./dev.py server --teston every test lane, decision D-A7; the second turns off the «What's new» window of lot C-54),LIBREFOLIO_REGISTRATION,LIBREFOLIO_MAX_USERS,LIBREFOLIO_DEFAULT_LANGUAGE,LIBREFOLIO_DEFAULT_CURRENCY,LIBREFOLIO_DEFAULT_TIMEZONE,LIBREFOLIO_PUBLIC_URL,LIBREFOLIO_BILLING_URL,LIBREFOLIO_LOGIN_LIMIT,LIBREFOLIO_SUPPORT_URL,LIBREFOLIO_TOS_URL,LIBREFOLIO_PRIVACY_URL,LIBREFOLIO_TEST_LANE_ID,LF_APP_VERSION(the version a release job or./dev.py docker buildfreezes),LIBREFOLIO_BLOCKED,LIBREFOLIO_DELETION_DATE,LIBREFOLIO_WEB_LINK_FINDER_*(the API key also as_FILE), the variables of the plugin settings (LIBREFOLIO_PLUGIN_*and the aliases of secret fields, all also as_FILE), the order of the asset providers in the search (LIBREFOLIO_ASSET_PROVIDERS_PREMIUM,LIBREFOLIO_ASSET_PROVIDERS_ORDER) — are read inbackend/app/config/(base or section module), fromos.environonly. pydantic-settings does not export.envthere, so they arrive through the launcher:./dev.py servercopies.envinto the environment (shell values win), Compose usesenv_file:. - Secrets go through
env_secret(name)in__init__.py:NAMEwhen it is not blank, otherwise the content of the file named byNAME_FILEwhen that is not blank (Docker and Kubernetes secrets), otherwiseNone. Blank means empty or whitespace only, so a stray space never becomes a key. ANAME_FILEthat cannot give its secret, an empty or blank file included, raisesSecretFileError; the full rules are in Security → Secrets from Files. A new secret is namedLIBREFOLIO_*and read withenv_secret(): its_FILEform then works, and the startup check of secrets set twice covers it without a list to update.INSTANCE_TRUST_SECRETSlists, in both forms, the secrets that a test runtime never inherits (configure_test_runtime()inscripts/cli_base.py), like the rest of the instance's configuration: see Security → Test lanes and the instance's configuration. - Addresses go through
env_url(name)in__init__.py, one rule for everyLIBREFOLIO_*_URL: an empty or blank value isNone; otherwise the value, stripped, must be anhttp://orhttps://address with a host name (a name, an IPv4 or an IPv6 address, with a port or not), no user info (no@in its authority, as inhttps://user:pass@host: the user name and the password would be handed out with the address; an@in the path, the query or the fragment is not user info) and no space, tab or line break inside, and one trailing slash is removed; anything else,https://alone included, raisesValueError, which names the variable and quotes the value, unless the value holds an@anywhere: it may carry a user name or a password, so the message never quotes it. The accessor's caller decides what an invalid address costs, and logs the error.support_url()(platform.py) also takesmailto:and one email address, the scheme in any case:?,#,%,,,;,<,>,",/and any whitespace are refused before pydantic'sEmailStrreads the address, without DNS, and it returnsmailto:and the address asEmailStrnormalizes it.env_url()itself stays http(s) only, and so dotos_url()andprivacy_url(), in the same module, which returnenv_url()of their variable. backend/app/config/is a package; the import path is stillbackend.app.config.__init__.pyis the base: constants, data directories, test mode, the secret readerenv_secret(), the address readerenv_url(),Settingsandget_settings(). New variables go into one section module per topic, owned by the workstream of that area. Eight exist today:platform.py(H:scheduler_disabled(),configured_jwt_secret(),configured_jwt_secret_origin(),configured_instance_key(),configured_instance_key_origin(),owning_test_lane_id(),frozen_app_version(),instance_blocked(),instance_deletion_date(),support_url(), andtos_url()andprivacy_url(), the legal pages, written by A),accounts.py(A:donation_popup_disabled(),registration_mode_override(),registration_mode_pinned(),max_users(),public_url(),billing_url(),login_limit_value()andlogin_limit_enabled(), the switch of the limit on failed sign-ins, andadmin_bootstrap_config(), the initial administrator, its token also as_FILE),plugins.py(X:web_link_finder_enabled(),web_link_finder_engine(),web_link_finder_api_key(),web_link_finder_ddgs_region(),web_link_finder_ddgs_backend(),web_link_finder_timeout(),web_link_finder_max_results(),plugin_setting_env()andplugin_setting_env_origin()for the plugin settings, andasset_providers_premium()andasset_providers_order()for the search order),email.py(E:smtp_host(),smtp_tls_mode(),smtp_port(),smtp_user(),smtp_password(),smtp_sender(),smtp_reply_to(),smtp_max_per_hour(); see Email Service),sleep_wake.py(Z: the pauses a provider gets after answering HTTP 429,provider_cooldown_base_seconds(),provider_cooldown_max_seconds()andprovider_cooldown_settings(); the shutdown budget,shutdown_timeout_seconds(), and uvicorn's share of it,shutdown_drain_seconds()anduvicorn_drain_env(); see Stopping the Server in Configuration; the token of the scheduled wake-up,wake_token(), also as_FILE, with the rules of the panel's backup token; the idle suspension,idle_suspend_mode()andidle_suspend_minutes()),backup.py(B:backup_download_token(), the token a hosting panel presents to download the instance's backups, also as_FILE),brim.py(W:brim_prewarm_enabled(), the opt-in warm-up of the BRIM parse pool, which raisesBrimConfigErroron a value it cannot use) andhosting_panel.py(H:panel_status_token(), the token of the hosting panel's status route, also as_FILE, with the rules of the backup token, raisingHostingPanelConfigError). Unlike aSettingsfield, an invalidLIBREFOLIO_REGISTRATION,LIBREFOLIO_PUBLIC_URLorLIBREFOLIO_BILLING_URLnever stops the startup: its accessor raisesValueError, andregistration_service.pylogs it and falls back safely — registration closed for the first, the bare path or no billing link for the URLs (Registration Modes). ALIBREFOLIO_MAX_USERSthat is not a whole number of at least 1, aLIBREFOLIO_DEFAULT_LANGUAGEthat is noten,it,frores, aLIBREFOLIO_DEFAULT_CURRENCYthat is not an ISO 4217 code and aLIBREFOLIO_DEFAULT_TIMEZONEthat is not an IANA name the server knows do stop it:log_configuration_audit()callsmax_users(),default_language(),default_currency()anddefault_timezone(). The last two check the value as the global setting is checked when an administrator saves it (validate_global_setting_value), and name the variable in the error. Until an administrator saves thedefault_language,default_currencyorscheduler_timezonesetting,global_settings_service.effective_stored_value()answers with the variable (CL-10, CL-13). An invalidLIBREFOLIO_SUPPORT_URLdoes not stop it either:support_link()(services/platform/instance_links.py) logs it once, andGET /system/instanceanswerssupport_url: null, so the app keeps its link to the project's GitHub issues. Nor does an invalidLIBREFOLIO_TOS_URLorLIBREFOLIO_PRIVACY_URL:terms_link()andprivacy_link(), in the same module, log it once per process, the sameInvalid instance linkerror with its ownconsequence, andGET /system/instanceanswersnullfor that link inlegal: the legal notice shows without it. An unusableLIBREFOLIO_ADMIN_*value does stop it, asadmin_bootstrap_config()runs in the startup audit, and so does aLIBREFOLIO_LOGIN_LIMITother thanonoroff:login_limit_enabled()runs right after it.- The rule: every environment variable of the application is read inside
backend/app/config/. A module elsewhere calls a function there instead of readingos.environ. The rule holds with no exception, and a guard test checks it (runner selectorservices config-package, filebackend/test_scripts/test_services/test_config_package.py). .env.example, at the repository root, documents the variables, grouped by function. A new variable goes into its section as a commented line that shows the default: the uncommented lines must not change, because the file becomes/app/.envin the Docker image. A guard test checks that the variables the code reads, theSettingsfields and the variables of the compose files are documented there, and that the uncommented lines stay the same (runner selectorservices config-env-example, filebackend/test_scripts/test_services/test_env_example.py).
🗃️ Two storage models, kept separate on purpose
| User Settings | Global Settings | |
|---|---|---|
| Storage | Typed columns on the per-user UserSettings row |
Key-value rows in the GlobalSetting table |
| Who reads | The user themselves (GET /api/v1/settings/user) |
Any signed-in user (GET /api/v1/settings/global): 401 without a session. The app reads them for every user — the globalSettings store loaded at bootstrap (the default currency, the upload limit of the Files page), the instance defaults of the Preferences tab — although only administrators have the Global Settings tab since lot N69-2. The login page reads none of them: what it needs before sign-in is in GET /system/instance |
| Who writes | The user themselves (PUT /api/v1/settings/user) |
Admins only (Global Settings tab of Settings › Administration, or PATCH /api/v1/settings/global/bulk) |
| Examples | language, base_currency, theme, avatar_url |
session_ttl_hours, registration_mode, scheduler_*, default_currency … |
The split is a deliberate design decision (P2-9), not an accident of history: per-user
preferences are fixed in number and benefit from typed columns with defaults on row creation,
while global settings are an open-ended key space that admins extend without migrations.
settings_service.py (user + global CRUD) and global_settings_service.py (typed read helpers
for global keys) stay separate services for the same reason.
A stored theme the app does not know (lot A-11). UserSettings.theme is a plain column, so a
row edited by hand, a global default_theme edited by hand and copied into new rows, or a theme of a
later release after a downgrade can hold a value outside the Literal of UserSettingsRead.theme
(light, dark, auto, read into KNOWN_THEMES in settings_service.py). Every answer that
carries the user's settings — POST /api/v1/auth/login, POST /api/v1/auth/setup,
GET /api/v1/settings/user and PUT /api/v1/settings/user — builds them with _settings_read(),
which shows such a theme as the instance's default_theme when that is a known theme, otherwise
auto (FALLBACK_THEME), and logs one WARNING per read, with user_id, stored (cut to 20
characters) and shown. Reading never rewrites the row, so a release that knows the theme shows it
again; a PUT without theme keeps the stored value, and a PUT with theme replaces it. Before,
building UserSettingsRead raised, and the answer was a 500: at sign-in, after the login had set its
cookie, so the user could not sign in. Tests: ./dev.py test api settings,
TestStoredThemeUnknownToTheApp (SET-A11-01 to SET-A11-07, in-process on a private database).
Admins manage global settings from the Global Settings tab of Settings › Administration, which
only administrators see (GlobalSettingsTab.svelte: lock-gated, with the scheduler dialogs and
CachePanel, writing through the bulk-update endpoint; see
GlobalSettingsTab).
Missing rows are seeded at every startup by the global-settings step of the lifespan
(_initialize_global_settings() in backend/app/services/platform/app_lifespan.py); the same
idempotent seeding is available from the CLI:
There is no API route for it: global settings are initialised at application start and from the CLI only.
How global values behave at runtime:
- Values are stored as strings next to their
value_type;get_setting_value()inglobal_settings_service.pyconverts them on read (int;bool, true fortrue/1/yes/on;json). An unparsableintreads as0; a missing row falls back toGLOBAL_SETTINGS_DEFAULTS. - Every read goes to the database, with no cache, so a saved value reaches all workers at once: this is why admin changes need no restart.
PATCH /api/v1/settings/global/bulk(update_global_settings()insettings_service.py) is all or nothing: a key that does not exist answers404; a key an environment variable pins answers409SETTING_LOCKED_BY_ENV, withkeyandvariableindetail(today onlyregistration_mode, pinned whileLIBREFOLIO_REGISTRATIONis set, valid or not:_PINNED_BY_ENV); a value refused by its type or by its entry inGLOBAL_SETTINGS_CONSTRAINTS(ranges, choices, formats) answers422, naming every refused key. Only then are all the values written, in one commit. The scheduler dialog also checks its own ranges before saving: 1–1440 minutes, 1–365 days, at least one time and one day.- While its variable is set, a pinned row decides nothing and cannot be written:
GET /api/v1/settings/globalstill returns the storedregistration_mode, and the mode in force is inGET /system/instance(below). The Global Settings tab shows that one, read-only, and its Reset All to Defaults leaves the field alone (Settings components).
📖 SETTINGS_REGISTRY — the single declaration point
Every known setting key is declared once in backend/app/schemas/settings.py:
@dataclass(frozen=True, slots=True)
class SettingSpec:
key: str # storage key (GlobalSetting row key or UserSettings column)
location: Literal["user", "global"] # which storage model holds it
value_type: str # "str" | "int" | "bool" | "json"
description: str
The registry exposes two namespaces mirroring the storage models:
SETTINGS_REGISTRY.user— oneSettingSpecperUserSettingscolumn (BASE_CURRENCY,LANGUAGE,THEME,AVATAR_URL);SETTINGS_REGISTRY.global_— oneSettingSpecperGlobalSettingkey, built by_global_spec(), which derivesvalue_typeanddescriptionfromGLOBAL_SETTINGS_DEFAULTSso the defaults table stays the single source for both seeding and metadata.
The global keys declared today, and where the Global Settings tab shows them (admin view):
| Key | Type | Default | In the Global Settings tab |
|---|---|---|---|
session_ttl_hours |
int | 24 |
Session → Session Duration |
registration_mode |
str | invite |
Security → Registration: open, invite or disabled (SettingConstraint(choices=…)). invite since decision 36: a new install seeds it, an existing row is kept, and an install with accounts but no row gets open from migration 005_release_1_3_0_schema (its step 5). The startup that creates the initial administrator writes invite too. Read-only while LIBREFOLIO_REGISTRATION is set: see Registration Modes |
require_email_verification |
bool | false |
Security → Require Email Verification: every account created by POST /auth/register but the first waits for an emailed link (Email Verification). It turns on only while an email with a link can go out: the switch is disabled while its saved value is off and email.links of GET /system/instance is false, and PATCH /settings/global/bulk refuses an off-to-on change with 409 EMAIL_VERIFICATION_UNAVAILABLE (GlobalSettingUnavailableError). Turning it off always works |
max_file_upload_mb |
int | 10 |
Memory → Max File Upload Size |
scheduler_enabled |
bool | true |
Update Job → Scheduler Enabled (label from settings.globalSettingNames.scheduler_enabled) |
scheduler_current_price_frequency_minutes |
int | 10 |
Schedule Configuration dialog → Refresh every |
scheduler_history_sync_times |
str | 06:00,23:00 |
Schedule Configuration dialog → Sync times |
scheduler_history_sync_days |
str | mon,tue,wed,thu,fri,sat |
Schedule Configuration dialog → Sync days |
scheduler_history_sync_horizon_days |
int | 14 |
Schedule Configuration dialog → Lookback horizon |
scheduler_timezone |
str | UTC |
Schedule Configuration dialog → Timezone |
default_currency |
str | EUR |
Defaults → Default Currency |
default_language |
str | en |
Defaults → Default Language |
default_theme |
str | auto |
Defaults → Default Theme |
The five scheduler_* keys after scheduler_enabled never appear as fields: GlobalSettingsTab.svelte
hides them (SCHEDULER_HIDDEN_KEYS) and SchedulerConfigModal.svelte writes them in one bulk call.
📌 Call-site convention
Call sites reference registry constants instead of re-declaring raw string literals:
As of 2026-09-03 there are 19 such references across the four call-site files
(settings_service.py, global_settings_service.py, scheduler/settings.py,
api/v1/settings.py). The legitimate exceptions are Alembic migrations and tests that
deliberately exercise raw keys.
Adding a new setting
- Add the key to
GLOBAL_SETTINGS_DEFAULTS(global) with value/type/description — this is what seeds fresh installs. - Add the matching constant under
SETTINGS_REGISTRY.global_via_global_spec(key). - Reference the constant at the call site. A user-facing label/hint also needs i18n keys
and, if it appears in the Global tab, a category in
GlobalSettingsTab.svelte.
💱 Base currency resolution: get_effective_base_currency
settings_service.get_effective_base_currency(session, user_id) answers "which currency does
this user's portfolio report in?" with an explicit chain:
- the per-user
UserSettings.base_currency— wins whenever a settings row exists; - the admin-level global
default_currency; "EUR"as the last-resort constant.
New UserSettings rows are seeded from the global defaults at creation
(get_or_create_user_settings), so the global default reaches users who never chose, while an
explicit user choice always wins afterwards.
Both are written only as ISO 4217 alphabetic codes: the global default_currency through the settings layer's own
check, a user's base_currency (PUT /settings/user, the welcome flow) through IsoCurrencyCode since E-19a. Before,
the user's field checked only its length, so an API client could store 978 or XYZ; such a stored value is reported
by the stored-currency check (admin guide, Command-Line Tools, «Currency Codes That Are Not
ISO Codes»).
Why this helper exists (audit 08, P0-1)
It replaced a phantom base_currency global key that was never registered anywhere:
every reader silently fell back to EUR regardless of the configured default. Any new code
that needs "the user's base currency" must call this helper — the three current consumers
are financial_math/portfolio/engine.py, portfolio_service.py, and lots_analysis_service.py.
🌍 Public instance configuration
GET /api/v1/system/instance answers, without a session, what the web app needs to know about the
instance before anyone signs in. The app reads it at startup: the (app) layout calls
instanceConfig.load() when it mounts, before the auth check, and works with a self-hosted default
until the server answers (see Instance configuration).
Its response is InstanceConfigResponse (backend/app/schemas/system.py), and today it has six fields:
| Field | Values | Source |
|---|---|---|
profile |
selfhosted, an install run by its owner, or managed |
LIBREFOLIO_PROFILE, a field of Settings, so it comes from .env or the environment like PORT. Default selfhosted; case and spaces around the value are ignored, and any other value stops the startup. Admin side: Configuration. The web app shows the Buy Me a Coffee links of the header, the Help menu, the sign-in pages and Settings › About, the update check (at an administrator's sign-in, and Check for updates in the changelog) and the server commands of Forgot Password? only once the answer says selfhosted: see Instance configuration. |
accounts |
{registration_mode, registration_locked, first_account_open, password_rules} (AccountsInstanceConfig, backend/app/schemas/auth.py): the registration mode in force, open, invite or disabled; whether LIBREFOLIO_REGISTRATION pins it; whether the instance has no account yet, so that the next registration creates the first account, an administrator, whatever the mode; and the rules every new password must meet, in order, [{code, value}] (PasswordRuleRead, value only for min_length) |
effective_registration_mode() (workstream A, registration_service.py): the variable, otherwise the registration_mode row, so the endpoint is async, with a database session. first_account_open(), in the same module: true while the users table is empty, an inactive account counted; optional in the schema, default false. password_rules_public() (password_policy.py): the same list on every instance; optional in the schema, default empty, and the app then assumes the rules of release 1.3. No count and no limit. Details: Registration Modes; why the flag may be public: The First-Account Flag; the rules: Password Rules. |
email |
{available, links} (EmailInstanceConfig, backend/app/schemas/email.py): available, whether the instance can send emails now, an SMTP server set and every LIBREFOLIO_SMTP_* variable usable; links, whether emails with a link can go out too, LIBREFOLIO_PUBLIC_URL set to an http(s) address; never the configuration itself |
email_instance_config() (workstream E, services/email/links.py), run in a worker thread since it may read the password file. Both booleans default to false, so the field is optional in the schema. Details: Email Service. |
support_url |
Where the users ask for help: an http(s) page, or mailto: and one email address; null when unset or invalid |
support_link() (workstream H, services/platform/instance_links.py), from LIBREFOLIO_SUPPORT_URL through support_url() (config/platform.py, above). Optional in the schema, default null. Its reader is the asset search's «Let us know» row: Asset Search & Link-Finder. |
legal |
{terms_url, privacy_url} (LegalInstanceConfig, backend/app/schemas/system.py): the instance's own terms of service and privacy policy, each an http(s) page or null |
terms_link() and privacy_link() (workstream A, F09, services/platform/instance_links.py), from LIBREFOLIO_TOS_URL and LIBREFOLIO_PRIVACY_URL through tos_url() and privacy_url() (config/platform.py: the rule of env_url(), no mailto:). They never raise: a value they cannot use is logged once per process, Invalid instance link with its consequence, and published as null, as an unset one is. Both default to null, so the field is optional in the schema. Its readers are the two components of the legal notice, LegalNotice and LegalLinks (Settings Components). |
client_log_level |
How much the web app writes to the browser console about failed API calls: error, the server errors, the network failures and the answers that break their schema; debug, every 4xx too. Two states, never the level itself |
client_log_level() (workstream H, H-60, backend/app/logging_config.py), from the backend's LOG_LEVEL, which LIBREFOLIO_LOG_LEVEL replaces: debug when it is DEBUG or TRACE, in any case, error otherwise. Optional in the schema, default error. Its reader is instanceConfig.load(), which hands it to setApiConsoleLevel(): see The Browser Console. |
The rule for a workstream that owns part of the public configuration:
- it adds one field to
InstanceConfigResponse, typed with a model of its own schemas; - it fills that field in
get_instance_config()(backend/app/api/v1/system/instance.py) with one call to its service; - the field holds only what is public and the same for whoever asks: nothing private, nothing that depends on the user or the session.
After ./dev.py api sync, the field appears in the frontend type InstanceConfig, inferred from the
generated client.
The legal part has two runner entries of its own: ./dev.py test services legal-links
(backend/test_scripts/test_services/test_legal_links.py: the two variables by the rule of
env_url(), published without ever raising, an invalid one logged once without its secret) and
./dev.py test api instance-legal (backend/test_scripts/test_api/test_instance_config_legal_api.py:
the field set, unset and invalid, null and still 200, the schema and the OpenAPI document, and one
anonymous read on the lane's server, which sets neither variable).
🧹 Related: cache administration
The named-cache registry (theine TTL caches used by services) and its admin endpoints under
/api/v1/settings/cache/* are documented in Cache Registry & Admin.