minimost (App Factory)
minimost
Flask application factory for the MiniMost chat platform.
This module is the primary entry point for the MiniMost application. It exposes
create_app(), which constructs a fully-configured flask.Flask
instance ready to serve HTTP requests.
Typical usage in development:
from minimost import create_app
app = create_app()
app.run(host="127.0.0.1", port=5000)
Typical usage with a WSGI server such as Gunicorn:
gunicorn "minimost:create_app()" --config gunicorn.conf.py
Module-level attributes
- _APP_VERSIONstr
The package version string, resolved once at import time by
_read_version(). Available in every Jinja2 template as{{ app_version }}.
- minimost._read_version() str[source]
Return the installed package version string.
The version is resolved in two stages:
importlib.metadata — works when the package has been installed via
pip install(editable or otherwise).pyproject.toml parsing — fallback for environments where the package metadata is not available (e.g. running directly from the source tree without installing).
If both stages fail the string
"unknown"is returned so the application always has a displayable value.- Returns:
The version string, for example
"0.1.0", or"unknown"if the version cannot be determined.- Return type:
- minimost._max_upload_size_mb() int[source]
Return the configured max upload size in MB (default 25).
- minimost._max_avatar_size_mb() int[source]
Return the configured max avatar size in MB (default 5).
- minimost._stun_port() int[source]
Return the configured STUN UDP port (default 3478).
The bundled STUN server lets LAN WebRTC peers gather a real-IP server-reflexive candidate, avoiding the mDNS
.localhost-candidate resolution that otherwise breaks calls on LANs without avahi/Bonjour.
- minimost.create_app()[source]
Create and configure the MiniMost Flask application.
This is the canonical application factory used by every execution path — the CLI entry point (
minimost.__main__), the Gunicorn WSGI configuration, and any test suite that imports the package.The factory performs the following steps in order:
Instantiate a
flask.Flaskapplication object.Provision the secret key — read from
secret.keyin the project root, generating a fresh 64-character hex token if the file does not exist. The secret key is required for Flask’s signed session cookies.Set upload limit to 16 MiB via
MAX_CONTENT_LENGTH. Requests that exceed this size are rejected by Flask before the route handler runs.Inject the version into every Jinja2 template context via a context processor, making
{{ app_version }}available in all templates.Register blueprints —
auth_bp,chat_bp, andpresence_bp.
The
auth.dbandpresence.dbdatabases are also initialised as a side effect of importingminimost.databaseandminimost.presenceat module load time.- Returns:
A configured
flask.Flaskapplication instance.- Return type:
Example:
app = create_app() with app.test_client() as client: response = client.get("/login") assert response.status_code == 200
- minimost._start_cleanup_scheduler(interval_hours: int = 24, days: int = 30, message_days: int = 770) None[source]
Start a daemon thread that periodically purges old upload files.
Runs
minimost.clean.delete_files_older_than()once shortly after startup and then every interval_hours hours. The thread is a daemon so it exits automatically when the server process shuts down — no teardown required.The retention period is read from the
"image_retention_days"key insettings.jsonat each run, so changes to the file take effect on the next scheduled cleanup without restarting the server. If the key is absent or the file cannot be read, days is used as the fallback.Multiple Gunicorn workers each start their own thread; concurrent runs are safe because
delete_files_older_than()toleratesFileNotFoundErroron files already removed by another worker.- Parameters:
interval_hours – Hours between cleanup runs. Defaults to
24.days – Fallback retention period in days if
settings.jsondoes not specify"image_retention_days". Defaults to30.