Developer guide¶
Layout¶
Path |
What |
|---|---|
|
Config, logging, secrets, catalog, backup engine, events, services |
|
Repository format and storage backends |
|
Microsoft Graph client and certificate auth |
|
Module SDK ( |
|
SQLAlchemy models, sessions, packaged Alembic migrations |
|
Job runner and Procrastinate tasks (incl. scheduler tick) |
|
FastAPI routes; also serves the built web UI |
|
Passwords, TOTP, sessions, break-glass and Entra sign-in |
|
The |
|
Web UI: React + TypeScript ( |
|
Browser smoke test (also takes screenshots) |
|
One image: builds the UI (Node), installs the backend |
|
Compose stack, Caddyfile, |
|
This site (Sphinx + MyST) |
The API reference is generated from the source docstrings.
Set up¶
cd backend
python3.13 -m venv .venv
.venv/bin/pip install -e '.[dev]'
Quality gates¶
CI runs all of these; run them before committing:
.venv/bin/ruff check src tests && .venv/bin/ruff format --check src tests
.venv/bin/mypy src # strict mode
.venv/bin/interrogate src # 100% docstrings on public code
.venv/bin/pytest -q
Docstrings use the Google style (Args:, Returns:, Raises:), enforced by
ruff’s pydocstyle rules.
Web UI¶
cd frontend
npm ci
npm run dev # http://localhost:5173, proxies /api to S365B_DEV_API (default https://localhost:8443)
npm run build # type-check + production build into dist/
npm test # unit tests (vitest)
Conventions:
Platform first. Native
<dialog>for modals,popoverfor toasts,<input type="checkbox" switch>for switches,:user-invalidfor field errors,light-dark()colour tokens. Polyfills load only where a feature is missing (src/lib/polyfills.ts).No inline scripts or styles in markup. The API serves the UI with a strict Content-Security-Policy (
script-src 'self'; style-src 'self'); runtime values such as brand colours are set as CSS custom properties.Branding arrives from
GET /api/v1/brandingbefore the first render (src/lib/theme.ts). Text on brand colours uses CSScontrast-color()with a computed fallback (src/lib/color.ts).Forms: visible labels, hints above inputs, errors linked through
data-error(src/lib/formA11y.tskeepsaria-invalidandaria-describedbyin step).API calls go through
src/lib/api.ts, which sends the CSRF header.Text goes through
t()(see below); dates and numbers throughIntlformatters created withlocale().
Translations¶
Every user-visible string is a message: an id and its English text, both literals, in ICU MessageFormat.
import { t, tx } from "../i18n";
t("jobs.queued", "{job} queued.", { job: job.name });
t("alerts.items", "{n, plural, one {# item} other {# items}}", { n });
tx("jobs.noRepo.admin", "Backups need somewhere to go. <link>Set up backup storage</link> first.", {
link: (c) => <Link to="/settings/storage">{c}</Link>,
});
Write whole sentences with placeholders. Never build a sentence from pieces or add an English plural
s: word order and plurals differ.Text from Microsoft 365 or the server is data, not a message. Mark server-provided UI text (such as module descriptions) with
data-source="server"until the server sends message codes.npm run i18nextracts the messages intosrc/locales/en.json(the build, dev server and tests run it first; CI fails if the committed file is out of date). It also writes the pseudo-languageen-XA: open the UI with?lang=en-XAand anything not accented and in brackets was missed.Every other catalog (
es.json,fr.json) must have exactly the English ids, the same<tags>, and no placeholders English lacks:src/locales/catalog.test.tschecks this, so a new string needs its translations in the same change. Use ’ rather than', which ICU treats as an escape. French uses a no-break space before:and a narrow one before; ? !.To add a language: add its catalog, its entry in
LANGUAGESandload()insrc/i18n/index.ts, add it toBETA_LANGUAGESuntil a native speaker has reviewed it, and todefault_languageinbackend/src/s365b/core/branding.py. Follow Microsoft’s terminology for that language (the Microsoft Terminology collection), so the words match the Microsoft 365 admin centre people already know.
Browser smoke test¶
npm run e2e drives Chrome through first-run setup, enrolment, sign-in and
every page, checks every page in the pseudo-language for untranslated text,
and saves screenshots to frontend/e2e/shots/ (including French ones, for
checking layout with longer text). It needs an API
serving the built UI against an empty database:
export S365B_DATABASE_URL=postgresql+psycopg://… # disposable database
export S365B_MASTER_KEY_FILE=/tmp/s365b-master-key # s365b generate-master-key > …
export S365B_WEB_DIR=$PWD/frontend/dist S365B_BASE_URL=http://localhost:8765
backend/.venv/bin/s365b migrate
backend/.venv/bin/s365b api --host 127.0.0.1 --port 8765 &
(cd frontend && npm run build && npm run e2e)
Third-party software¶
The About page lists the open-source software Mail Safehouse ships with.
The server lists its own Python packages from what is installed
(s365b.core.third_party). The web app’s packages and the containers come
from frontend/src/generated/third-party.json; after changing the web
app’s dependencies (or LICENSE/NOTICE), run
python3 scripts/third_party.py
It also writes frontend/public/third-party-licenses.txt (the full licence
texts of the bundled packages) and copies LICENSE and NOTICE beside the
web app. A frontend test fails while these are out of date.
Tests that need PostgreSQL¶
Tests marked postgres (catalog, engine, jobs, API) run only when
S365B_TEST_DATABASE_URL points to a disposable database: the schema is
dropped and recreated for every test.
docker run -d --name s365b-testdb -e POSTGRES_USER=s365b -e POSTGRES_PASSWORD=test \
-e POSTGRES_DB=s365b -p 127.0.0.1:55432:5432 docker.io/library/postgres:17
export S365B_TEST_DATABASE_URL=postgresql+psycopg://s365b:test@127.0.0.1:55432/s365b
.venv/bin/pytest -q
Database changes¶
Edit s365b/db/models.py, then generate a migration against a database at
the current head:
S365B_DATABASE_URL=... .venv/bin/python -c \
"from s365b.db.migrate import autogenerate; autogenerate('describe the change')"
Review the generated file in s365b/db/migrations/versions/ (Alembic does
not drop enum types in downgrades, for example). CI fails if the models and
migrations disagree.
Writing a module¶
Create
s365b/modules/<id>/with a subclass ofs365b.modules.sdk.BackupModule.Register it in
pyproject.toml:[project.entry-points."s365b.modules"] entra = "s365b.modules.entra:EntraModule"
In
backup(), yieldItemVersionrecords and aCheckpointafter each unit of work (a folder, a delta page). The engine commits at checkpoints and resumes from the last one after a failure.Call
assert_module_contract(YourModule)froms365b.modules.testingin your tests, and testbackup()against recorded Graph responses withrespx.Add a page for the module to the docs.
Backup permissions must be read-only; the contract check enforces it.