Core¶
Deployment settings, FastAPI dependencies, domain errors and their handlers.
app.core.settings
¶
Compass platform settings (deployment), not use-case configuration.
Settings
¶
Bases: BaseSettings
Process-wide Compass knobs loaded from the environment at startup.
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 |
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
56 57 58 59 60 61 62 63 64 65 66 67 | |
_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
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
_default_ontology_dir()
¶
Return src/ontology of the checkout this package lives in.
Source code in src/backend/app/core/settings.py
11 12 13 14 | |
root_env_file()
¶
Return the project-root .env file, or None when absent (e.g. under Compose).
Source code in src/backend/app/core/settings.py
17 18 19 20 21 | |
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(detail)
¶
Bases: AppError
A SPARQL query could not be executed.
Source code in src/backend/app/core/exceptions.py
11 12 13 14 15 16 17 18 | |
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
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 | |
app.core.cors
¶
CORS for widgets served from another origin.
configure_cors(app)
¶
Allow COMPASS_CORS_ORIGINS to call the API cross-origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
FastAPI
|
The FastAPI application to configure. |
required |
Source code in src/backend/app/core/cors.py
9 10 11 12 13 14 15 16 17 18 19 20 | |