This project extends the Full Stack FastAPI Template with role-based access control (RBAC) for the Fullstack Dev Test Task.
Requires Docker Desktop (macOS, Linux, or Windows).
git clone <repository-url>
cd <project-directory>
cp compose.override.example.yml compose.override.yml
docker compose build backend
docker compose run --rm backend bash scripts/prestart.sh
docker compose up -dOpen:
| Service | URL |
|---|---|
| App (API + frontend) | http://localhost:8000 |
| API docs | http://localhost:8000/docs |
| Adminer | http://localhost:8080 |
| Mailpit | http://localhost:8025 |
| Traefik (via proxy) | http://localhost |
compose.override.yml is local-only (see compose.override.example.yml). Adjust ports there if 80 or 5432 are already in use on your machine.
| Password | Role | |
|---|---|---|
| admin@example.com | changethis | admin |
| manager@example.com | changethis | manager |
| member@example.com | changethis | member |
Credentials are configured in .env (FIRST_SUPERUSER*, MANAGER_USER*, MEMBER_USER*).
| Action | admin | manager | member |
|---|---|---|---|
| List all users | yes | yes | no |
| Create user | yes | no | no |
| View metrics | yes | yes | no |
| Update own profile | yes | yes | yes |
| Update any profile | yes | no | no |
| Global settings | yes | no | no |
Roles are stored on the User.role column (admin, manager, member) with an Alembic migration backfilling existing superusers to admin.
Backend authorization is centralized in backend/app/core/permissions.py. FastAPI dependencies in backend/app/api/deps.py expose require_permission(...) and enforce checks on route handlers (users, metrics). The API returns HTTP 403 with a clear message when access is denied.
The frontend mirrors the same permission matrix in frontend/src/lib/permissions.ts. The usePermissions() hook drives sidebar visibility, route-level UI guards, and an AccessDenied component for direct navigation to forbidden pages. The backend remains the source of truth; the UI only hides or blocks navigation for better UX.
Denied access attempts are logged at WARNING level from app.api.deps (user id, email, role, permission) for observability.
flowchart TB
subgraph client [Frontend]
Login[Login / JWT stored]
Hook[usePermissions from user.role]
Nav[Sidebar hides forbidden links]
Guard[Route guard / AccessDenied]
Login --> Hook --> Nav
Hook --> Guard
end
subgraph api [Backend API]
JWT[get_current_user validates JWT]
Perm[require_permission dependency]
Matrix[user_has_permission in permissions.py]
Route[Route handler]
JWT --> Perm --> Matrix
Matrix -->|allowed| Route
Matrix -->|denied| Log403[Log WARNING + HTTP 403]
end
Guard -->|API call| JWT
Nav -->|API call| JWT
Further reading:
- NOTES.md — scope cuts, trade-offs, follow-ups
- docs/ai-conversations/ — English copies of AI-assisted development sessions (submission requirement)
- docs/adr/001-permission-based-rbac.md
- docs/adr/002-frontend-permission-mirror.md
# Authorization-focused tests (rebuild backend image after pulling changes)
docker compose run --rm backend pytest tests/api/routes/test_authorization.py -v
# Smoke check (Python 3 on the host; stack must be up)
python3 scripts/smoke_rbac.pydocker compose run --rm backend alembic upgrade headNew migration: a1b2c3d4e5f6_add_user_role.py (adds role column).
- ⚡ FastAPI for the Python backend API.
- 🧰 SQLModel for the Python SQL database interactions (ORM).
- 🔍 Pydantic, used by FastAPI, for the data validation and settings management.
- 💾 PostgreSQL as the SQL database.
- 🚀 React for the frontend.
- 🧩 Built into the backend application and served by FastAPI on the same domain as the API.
- 💃 Using TypeScript, hooks, Vite, and other parts of a modern frontend stack.
- 🎨 Tailwind CSS and shadcn/ui for the frontend components.
- 🤖 An automatically generated frontend client.
- 🧪 Playwright for end-to-end testing.
- 🦇 Dark mode support.
- ☁️ FastAPI Cloud for deployment.
- 🐋 Docker Compose for local services and self-hosted deployment.
- 📞 Traefik as a reverse proxy with automatic HTTPS.
- 🔒 Secure password hashing by default.
- 🔑 JWT (JSON Web Token) authentication.
- 📫 Email-based password recovery.
- 📬 Mailpit for local email testing during development.
- ✅ Tests with Pytest.
- 🏭 CI (continuous integration) and CD (continuous deployment) based on GitHub Actions.
Click the Use this template button at the top of this page to create a new repository.
Backend docs: backend/README.md.
Frontend docs: frontend/README.md.
FastAPI Cloud deployment: deployment.md.
Self-hosted deployment with Docker Compose: deployment-docker-compose.md.
General development docs: development.md.
This includes the local FastAPI and Vite workflow, Docker Compose services, .env configuration, and more.
Check the file release-notes.md.
The Full Stack FastAPI Template is licensed under the terms of the MIT license.




