Skip to main content

ui-foundation-backend

The auth and security layer shared by the FastAPI + SQLModel backends of apps built on ui-foundation: the half of every app's backend that apps never change on purpose. Import package foundation_backend. Released with @tristan2828/ui-foundation, under the same version number, from the same commit.

What's in it

Module What it is
config The settings it reads from the environment (database, cookies and sessions, sign-in limits, TOTP, error reporting, AI chats' OAuth, the seeded account) and database_connect_args()
db The async engine and the get_session dependency
models User, Session, LoginFailure, RecoveryCode, PendingLogin, OAuthClient, OAuthCode, OAuthGrant (table names users, sessions, …)
schemas CamelModel, Page, the sign-in and error-envelope schemas
security, totp, login_limits, rate_window Password and token hashing, the TOTP step, failed sign-in limits, an in-memory rate window
errors, error_reporting, openapi_responses Error bodies pinned to the contract, report_error, the shared responses= fragments
deploy_checks, spa What APP_ENV=production refuses to start with; the SPA mount with its client-route fallback
routers.auth router (login, the TOTP step, logout, me) and register_router (POST /auth/register), with get_current_user
routers.environment, routers.client_errors, routers.oauth GET /environment, POST /client-errors, AI chats' OAuth sign-in (off unless MCP_ENABLED)
scripts.set_password, scripts.enable_totp, scripts.disable_totp Run as python -m foundation_backend.scripts.<name> <email> from the app's backend/
testing.signed_in session_cookie, to sign a test client in for real
migrations/ Reference copies of the Alembic revisions that create these tables; never run from here (migrations/README.md)

An app keeps everything else: its entities, models, routers and migrations, and, in the template, MCP's tools, scheduled jobs and Web Push.

How an app uses it

backend/pyproject.toml pins it to the release the app is on, the same version as its @tristan2828/ui-foundation:

dependencies = [
  "ui-foundation-backend==4.25.0",
  ...
]

The app's own modules re-export it, so from app.models import User keeps working (the template's app/config.py, db.py, models.py, schemas.py, openapi_responses.py, security.py, errors.py, spa.py do this), and its main.py includes the routers it offers:

from foundation_backend.routers import auth, client_errors, environment, oauth

app.include_router(auth.router, prefix="/api")
app.include_router(auth.register_router, prefix="/api")  # only if people make their own accounts
app.include_router(client_errors.router, prefix="/api")
app.include_router(environment.router, prefix="/api")
app.include_router(oauth.router)  # only with AI chats (MCP)

register_router is separate on purpose. An app where accounts are made by whoever runs it leaves it out, with /auth/register out of its openapi.yaml (the path is x-optional) and LoginRoute registerPath={null}. Including router alone serves sign-in with no way to make an account through the API.

A setting the package reads is changed at runtime (a test's monkeypatch) on foundation_backend.config or on the module that imported it, never on the app's re-export, which is a copy.

Upgrading: bump the pin with the npm package, run the migrations the changelog names for that release, then npm run verify:backend (docs/consuming.md).

In this repo

template/backend/ depends on ui-foundation-backend unpinned. Install both editable in one pip call, so the dependency resolves to this folder and never to PyPI:

cd template/backend
python -m venv .venv
.venv/Scripts/python -m pip install -e ../../packages/backend-foundation -e ".[dev]"   # .venv/bin/python elsewhere

template/backend/scripts/dev.sh and the cloud session hook do this. Installing template/backend on its own would pull the published version (or fail before the first release), and its tests would run against code that isn't this commit's.

npm run verify:backend (repo root) runs this package's gate, scripts/verify.sh (mypy strict, then pytest over SQLite against tests/minimal_app.py, an app made of the package alone), then the template's. On its own: cd packages/backend-foundation && pytest.

Releasing

.github/workflows/release.yml builds it (build-py, with the release's version written into pyproject.toml) and publishes it to PyPI by trusted publishing (publish-py), beside the npm package, before tagging. The committed version in pyproject.toml is a floor, like packages/ui-foundation/package.json's; keep the two the same.

Metadata

Release files for ui-foundation-backend 4.25.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ui-foundation-backend 4.25.0
File Size Uploaded Provenance
ui_foundation_backend-4.25.0.tar.gz 50.2 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ui-foundation-backend 4.25.0
File Interpreter ABI Platform
ui_foundation_backend-4.25.0-py3-none-any.whl Python 3 none any Details

Total release size: 99.9 kB

Release files / ui_foundation_backend-4.25.0.tar.gz

Download URL ui_foundation_backend-4.25.0.tar.gz
Size 50.2 kB
Tags Source
SHA-256 checksum
How to use checksums
560f1f3f7370ac950d59912025baa3d283a7cd79f5668a71042f55d07303aa24
BLAKE2b-256 checksum
How to use checksums
e48e04c4ca9e6d3492dbac131f9086e188a9c00595429c3f709b4814f2d84079
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Release files / ui_foundation_backend-4.25.0-py3-none-any.whl

Download URL ui_foundation_backend-4.25.0-py3-none-any.whl
Size 49.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb7e76adb3ee539809ad23960ed47d972e63132e35f6cc354ae2f19aebe033c3
BLAKE2b-256 checksum
How to use checksums
3e92ecc47a764036549777c903b72bf345d8d021bf1163f9d2a392bfc09c0301
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Security for ui-foundation-backend 4.25.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ui_foundation_backend-4.25.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

4.25.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page