Skip to main content

Drop-in admin panel for FastAPI + SQLAlchemy apps

Project description

FastAPI Admin — Agent Guide

What This Project Is

A drop-in admin panel for FastAPI + SQLAlchemy apps. Register a model, get full CRUD UI, auth, permissions, and audit logging — no manual form or view definitions required.

Spec Documents

File Covers
fastapi_admin_core_spec.md The 3 core bets: auto-discovery, audit log + RBAC, modern UI. Start here.
AUTH_RBAC_SYSTEM.md Auth model extensibility (built-in / extend / BYO), session flow, RBAC permission tables and checks
FORM_WIDGET_SYSTEM.md Widget class layer → Jinja2 macro layer, form pipeline, validation, relationship widgets
PLUGIN_SYSTEM.md Every extension point: widgets, hooks, routes, auth, storage, audit sinks, dashboard, UI

Architecture in One Paragraph

On startup, Admin() inspects every registered SQLAlchemy model, maps column types to widgets, and auto-generates CRUD routes under /admin/{table}/. Each request hits an auth middleware (session cookie → AuthBackend.get_user), then a PermissionChecker that reads admin_permissions rows keyed by user.role_id. Forms are rendered via Widget.render_context() → Jinja2 macros (Tailwind + HTMX + Alpine.js). Every DB write fires SQLAlchemy session events that write to admin_audit_log. Everything is replaceable via protocols.

Key Concepts

  • RegisteredModel — central dataclass holding the model class, its ModelAdmin config, inspected columns/relationships, and resolved widgets
  • Widget — two-layer: Python class (parse + validate) + Jinja2 macro (HTML). Override either independently
  • PermissionChecker — instantiated per request; checks admin_permissions table; superusers bypass all checks
  • AuthBackend — two methods: authenticate() on login, get_user() on every request
  • AdminPlugin — bundles widgets, macros, routes, nav items, hooks into a distributable package
  • AuditLog — written via SQLAlchemy after_flush event; stores full snapshot + diff for UPDATEs

Project Structure (key paths)

fastapi_admin/
├── admin.py          # Admin class, public API, wires everything at init
├── registry.py       # AdminRegistry singleton
├── inspection.py     # SQLAlchemy model → ColumnMeta / RelationMeta
├── field_types.py    # Column type → widget name mapping
├── router.py         # Auto-route generation per registered model
├── auth/             # AuthBackend, PermissionChecker, session, dependencies
├── audit/            # AuditLog model, SQLAlchemy event listener, diff, context
├── widgets/          # Widget base class, all built-in widgets, WidgetRegistry
├── views/            # Route handler factories (list, form, delete, roles, dashboard)
├── templates/        # Jinja2: base.html, pages/, partials/, macros/
└── static/           # Tailwind CSS, HTMX, Alpine.js, Heroicons

Tech Stack

FastAPI · SQLAlchemy 2.x · Jinja2 · Tailwind CSS · HTMX · Alpine.js · itsdangerous · passlib/bcrypt . uv

What to Build (suggested order)

  1. inspection.py + field_types.py — model inspection and type→widget mapping
  2. registry.py + admin.py — registration API and ModelAdmin base
  3. auth/ — models, session, AuthBackend, PermissionChecker, dependencies
  4. audit/ — listener, diff, AuditLog model
  5. widgets/ — base class, built-in widgets, WidgetRegistry
  6. views/ + router.py — route factories, form pipeline
  7. templates/ — Jinja2 templates and macros
  8. plugins/AdminPlugin base, plugin registration

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_console-0.1.0.tar.gz (246.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_console-0.1.0-py3-none-any.whl (101.2 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_console-0.1.0.tar.gz.

File metadata

  • Download URL: fastapi_console-0.1.0.tar.gz
  • Upload date:
  • Size: 246.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.5

File hashes

Hashes for fastapi_console-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7d20248b971e68a7dc3784f8291e0ed64e38e1a7603cae4040b67229e0f9fa8d
MD5 db363a48d11f7df521f7fff253e88065
BLAKE2b-256 3116c2faf4c0a3f78aef5b14c97c7823770073a9fc534522de0a903431a29d95

See more details on using hashes here.

File details

Details for the file fastapi_console-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_console-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 604d115d2812920caae602e6f19fcbfc6afa160213fcb7a93ccfe4c00731173f
MD5 2211b2f4489ed477db70a9b5f27821ff
BLAKE2b-256 7e6d4ebdf1f47f45cd878b50da03b5684edda5a56816d5143053b4cb375e2634

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page