How samratpro/fastadmin works
1. FastAdmin is split into two deployable runtimes: a Python backend in api/ and a standalone Next.js admin UI in admin/. The repository also includes documentation, deployment helpers, and a public-app template, but those are support materials rather than the core runtime.
2. The backend is a FastAPI application entrypointed from api/main.py. It is organized Django-style into feature apps under api/apps/*, and those apps are auto-discovered at startup rather than wired together through a monolithic central module.
3. Each backend feature app owns its own boundary: models.py for domain data and routers.py for HTTP endpoints. The current included domains are auth, blog, seo, settings, backup, and admin, which makes the backend modular and easy to extend with new app folders.
4. Shared backend infrastructure lives in api/core/ and api/common/. This includes configuration, database setup, security, dependency injection, registry logic for admin model registration, and the lightweight ORM layer used by application models.
5. The data layer is SQLite-first. The repository includes Alembic for migrations, but the README makes clear that new tables can be created automatically while schema changes to existing tables still require explicit migration or SQL steps. This matters for diagramming because the system is not relying on a fully managed ORM migration workflow alone.
6. Authentication is backend-driven and cookie-based. The API exposes login, logout, refresh, password reset, email verification, and me endpoints, and it stores JWTs in httpOnly cookies (accessToken and refreshToken). Swagger/OpenAPI docs are also available, but they are protected for superuser access.
7. The admin UI is a separate Next.js app using the App Router. Its main runtime surfaces are login and the dashboard area, with pages for models, individual model views, SEO, backup, and settings. This is the internal staff interface, not the public site.
8. The admin frontend talks to the API through a dedicated client layer in admin/src/lib/api.ts and uses client-side auth state in admin/src/store/authStore.ts. Route protection is handled in the UI via ProtectedRoute, so the browser experience depends on the backend session cookies plus frontend route guards.
9. The dashboard UI is model-centric. Components such as ActionBar, DualListBox, EditorField, FiltersSidebar, and Fieldset indicate that the admin is designed around CRUD, filtering, ordering, and content editing rather than generic page composition. There is also a small Next.js upload route in admin/src/app/api/upload/route.ts, which suggests some file handling happens inside the admin app boundary before or alongside API calls.
10. Extensibility is a first-class architectural concern. Backend models are meant to be registered into the admin system with @register_admin, and the api/apps/admin/ plus api/core/registry.py pieces are the mechanism that turns backend models into admin-manageable resources.
11. Operationally, the repo is container-ready and CI-backed. There are Dockerfiles for both runtimes, a root docker-compose.yml, and a GitHub Actions workflow for validation. Node version files and npm config exist at the root and in admin/, showing that the frontend is treated as its own build target.
12. The tutorials/ folder is part of the architecture story: it documents how to add apps, manage auth, run migrations, configure email, back up data, integrate SEO, and connect a separate public frontend. A reference public Next.js auth app lives under tutorials/templates/public-auth-nextjs, reinforcing the intended shape: public app and admin app both consume the same backend API, but remain separate frontends.
Main entry points: main.py API entry · api.ts API client · page.tsx Dashboard · auth Auth app
Components 25
Backend runtime
FastAPI backend, feature apps, and shared server-side infrastructure.
- API entry · Backend startup and app wiring for the Python API runtime.
api/main.py - Core infra · Shared backend configuration, database setup, and dependency wiring.
api/core - Admin registry · Maps backend models into admin-manageable resources.
api/core/registry.py - Security · Backend security primitives used by authentication and session handling.
api/core/security.py - ORM layer · Lightweight ORM used by application models.
api/common/orm.py - Auth app · Login, logout, refresh, password reset, verification, and profile endpoints plus auth models.
api/apps/auth - Blog app · Content feature boundary with its own models and routes.
api/apps/blog - SEO app · SEO-related models and routes managed as a modular backend feature.
api/apps/seo - Settings app · Site configuration and settings models and routes.
api/apps/settings - Backup app · Backup-related backend endpoints and integration points.
api/apps/backup - Admin API · Backend admin endpoints that expose model registration and management capabilities.
api/apps/admin/routers.py - User CLI · Command-line helper for creating users and admin accounts.
api/cli/create_user.py
Admin runtime
Standalone Next.js admin interface and its client-side state and API boundary.
- UI shell · Top-level admin application shell and routing container.
admin/src/app/layout.tsx - Login · Admin sign-in surface for session-based access.
admin/src/app/login/page.tsx - Dashboard · Main staff workspace that anchors the admin area.
admin/src/app/dashboard/page.tsx - Models · Model browser and per-model views for managing backend resources.
admin/src/app/dashboard/models/page.tsx - SEO panel · Admin UI for SEO configuration and content controls.
admin/src/app/dashboard/seo/page.tsx - Settings panel · Admin UI for site settings and operational configuration.
admin/src/app/dashboard/settings/page.tsx - Backup panel · Admin UI for backup operations and status.
admin/src/app/dashboard/backup/page.tsx - Upload route · Small Next.js upload handler inside the admin boundary.
admin/src/app/api/upload/route.ts - API client · Dedicated browser-to-backend client used by the admin UI.
admin/src/lib/api.ts - Auth store · Client-side authentication state and session awareness.
admin/src/store/authStore.ts - Route guard · UI-level route protection layered on top of backend cookies.
admin/src/components/ProtectedRoute.tsx
Support & delivery
Documentation, public template, and container/CI assets that support the main runtimes.
- Docs · Architecture, setup, migration, deployment, and feature guides.
tutorials/README.md - Public template · Reference public frontend template that consumes the same backend API.
tutorials/templates/public-auth-nextjs/src/app/login/page.tsx
Connections 34
- API entry → Core infra: boot · Backend startup loads shared configuration, database, and dependencies.
- API entry → Admin registry: discover · Auto-discovers feature apps and registers admin resources.
- API entry → Auth app: mount · Wires the auth feature into the application.
- API entry → Blog app: mount · Wires the blog feature into the application.
- API entry → SEO app: mount · Wires the SEO feature into the application.
- API entry → Settings app: mount · Wires the settings feature into the application.
- API entry → Backup app: mount · Wires the backup feature into the application.
- API entry → Admin API: mount · Exposes admin-specific backend endpoints.
- Auth app → Security: uses · Authentication depends on backend security primitives.
- Auth app → ORM layer: models · Auth models are built on the shared ORM layer.
- Blog app → ORM layer: models · Blog data uses the shared ORM layer.
- SEO app → ORM layer: models · SEO data uses the shared ORM layer.
- Settings app → ORM layer: models · Settings data uses the shared ORM layer.
- Admin registry → Admin API: publishes · Registry makes backend models visible to admin management.
- Admin API → Auth app: manages · Admin endpoints operate on registered backend resources.
- User CLI → Core infra: shares · CLI helpers reuse backend configuration and persistence setup.
- UI shell → Login: routes · App shell contains the login surface.
- UI shell → Dashboard: routes · App shell contains the authenticated dashboard area.
- Dashboard → Models: navigates · Dashboard exposes model-centric management views.
- Dashboard → SEO panel: navigates · Dashboard exposes SEO controls.
- Dashboard → Settings panel: navigates · Dashboard exposes site settings controls.
- Dashboard → Backup panel: navigates · Dashboard exposes backup controls.
- Route guard → Auth store: checks · Route protection reads client auth state.
- Auth store → API client: syncs · Auth state is hydrated through the API client.
- Models → API client: calls · Model pages fetch and mutate data through the client layer.
- SEO panel → API client: calls · SEO page uses the dedicated API client.
- Settings panel → API client: calls · Settings page uses the dedicated API client.
- Backup panel → API client: calls · Backup page uses the dedicated API client.
- Upload route → API client: bridges · Upload handler sits beside the client-backed admin workflows.
- API client → API entry: requests · Admin UI talks to the FastAPI backend over the shared session boundary.
- Docs → API entry: explains · Documentation covers backend structure and runtime behavior.
- Docs → UI shell: explains · Documentation covers the admin UI and its workflows.
- Docs → Public template: templates · Docs include the separate public frontend template.
- Public template → API entry: consumes · Reference public app consumes the same backend API.