Core¶
Platform infrastructure: deployment settings, FastAPI dependencies, and domain errors.
HTTP routes themselves are documented in the running API's OpenAPI UI (/docs).
app.core.settings
¶
Compass platform settings (deployment), not use-case configuration.
Settings
¶
Bases: BaseSettings
Process-wide Compass knobs loaded from the environment at startup.
is_development
property
¶
Whether the app is running in a development environment.
Returns:
| Type | Description |
|---|---|
bool
|
|
cors_origins
property
¶
Origins allowed to call the API cross-origin; empty for same-origin only.
Returns:
| Type | Description |
|---|---|
list[str]
|
Stripped origin strings from |
reload_token
property
¶
Token expected in the X-Reload-Token header.
Returns:
| Type | Description |
|---|---|
str
|
Configured reload secret (may be empty). |
ontology_dir
property
¶
Root directory for shared ontology files (shapes, templates).
Returns:
| Type | Description |
|---|---|
Path
|
Explicit |
use_case_dir
property
¶
Directory holding this deployment's compass.ttl and vocab.ttl.
Returns:
| Type | Description |
|---|---|
Path
|
|
_empty_ontology_dir_is_none(value)
classmethod
¶
Treat an empty string env override as unset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
object
|
Raw field value before validation. |
required |
Returns:
| Type | Description |
|---|---|
object
|
|
Source code in src/backend/app/core/settings.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
_strip_use_case(value)
classmethod
¶
Reject empty use-case names and strip whitespace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
object
|
Raw field value before validation. |
required |
Returns:
| Type | Description |
|---|---|
object
|
Stripped string, or value unchanged when not a string. |
Source code in src/backend/app/core/settings.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
_default_ontology_dir()
¶
Resolve the default ontology directory relative to this package.
Returns:
| Type | Description |
|---|---|
Path
|
|
Source code in src/backend/app/core/settings.py
11 12 13 14 15 16 17 18 19 | |
_project_root_env_file()
¶
Return the project-root .env file if it exists.
Returns:
| Type | Description |
|---|---|
Path | None
|
Path to |
Path | None
|
Docker Compose injects variables directly, so the file is optional. |
Source code in src/backend/app/core/settings.py
22 23 24 25 26 27 28 29 30 31 | |
app.core.deps
¶
Shared FastAPI dependencies.
get_settings()
¶
Provide the process-wide deployment settings.
Returns:
| Type | Description |
|---|---|
Settings
|
Singleton |
Source code in src/backend/app/core/deps.py
15 16 17 18 19 20 21 | |
get_config()
¶
Provide the use-case configuration.
Returns:
| Type | Description |
|---|---|
Config
|
Singleton |
Source code in src/backend/app/core/deps.py
24 25 26 27 28 29 30 | |
get_lang(cfg, lang='en')
¶
Validate and return the lang query parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
Annotated[Config, Depends(get_config)]
|
Use-case config (defines |
required |
lang
|
Annotated[str, Query(description='UI language code')]
|
Requested language code. |
'en'
|
Returns:
| Type | Description |
|---|---|
str
|
Validated language code. |
Raises:
| Type | Description |
|---|---|
UnsupportedLangError
|
When lang is not in |
Source code in src/backend/app/core/deps.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
app.core.exceptions
¶
Domain errors raised by the API and mapped to HTTP in handlers.
AppError(detail)
¶
Bases: Exception
Base for application errors that become a consistent JSON response.
Attributes:
| Name | Type | Description |
|---|---|---|
detail |
Human-readable error message returned to the client. |
Store detail and pass it to Exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detail
|
str
|
Error message. |
required |
Source code in src/backend/app/core/exceptions.py
11 12 13 14 15 16 17 18 | |
ReloadNotConfiguredError(detail)
¶
Bases: AppError
Reload was requested but no token is configured on the server.
Source code in src/backend/app/core/exceptions.py
11 12 13 14 15 16 17 18 | |
UnauthorizedError(detail)
¶
Bases: AppError
The caller failed an authentication check.
Source code in src/backend/app/core/exceptions.py
11 12 13 14 15 16 17 18 | |
UnsupportedLangError(detail)
¶
Bases: AppError
The lang query parameter is not in the use-case Config.
Source code in src/backend/app/core/exceptions.py
11 12 13 14 15 16 17 18 | |
ReloadError(detail)
¶
Bases: AppError
The files on disk are not usable. The store already serving is untouched.
Source code in src/backend/app/core/exceptions.py
11 12 13 14 15 16 17 18 | |
QueryError(sparql, cause)
¶
Bases: AppError
A SPARQL query could not be executed. Carries the query for the log.
Attributes:
| Name | Type | Description |
|---|---|---|
sparql |
The query text that failed. |
|
detail |
Short summary of the underlying exception. |
Attach the failing query and summarize cause.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sparql
|
str
|
Query that Oxigraph rejected. |
required |
cause
|
Exception
|
Underlying exception. |
required |
Source code in src/backend/app/core/exceptions.py
45 46 47 48 49 50 51 52 53 | |
app.core.handlers
¶
Register exception handlers that emit one JSON error shape.
register_exception_handlers(app)
¶
Attach domain-error handlers that return a uniform JSON detail body.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
FastAPI
|
FastAPI application to mutate in place. |
required |
Source code in src/backend/app/core/handlers.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
app.core.development
¶
Development-only FastAPI configuration.
configure_development(app)
¶
Add development-only middleware and routes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
FastAPI
|
The FastAPI application to configure. |
required |
Source code in src/backend/app/core/development.py
9 10 11 12 13 14 15 16 17 18 19 20 21 | |