FastAPI backend for submitting, tracking, assigning, and resolving service/complaint requests, with JWT authentication and role-based access control.
- user — submits requests, views/tracks only their own requests.
- staff — views all requests, updates status, sees the org-wide dashboard.
- admin — everything staff can do, plus creating categories and assigning requests to staff.
Role is embedded in the JWT at login, so every protected route can authorize without an extra DB lookup.
pip install -r requirements.txt
cp .env.example .env # then fill in DATABASE_URL and JWT_SECRET_KEY
uvicorn main:app --reloadTables are created automatically on startup (init_db() in database.py).
users— id, full_name, email, password (bcrypt hash), rolecategories— id, name, description (e.g. Plumbing, Electrical, IT)service_requests— id, requester_id, category_id, title, description, priority, status, assigned_to, created_at, updated_at, resolved_atrequest_status_history— append-only audit trail of every status change
Status lifecycle: pending → assigned → in_progress → resolved → closed
| Method | Path | Access | Purpose |
|---|---|---|---|
| POST | /register |
public | create an account |
| POST | /login |
public | get a JWT |
| POST | /categories |
admin | create a request category |
| GET | /categories |
any authenticated | list categories |
| POST | /requests |
any authenticated | submit a new service request |
| GET | /requests?status= |
any authenticated | list requests (own, for users; all, for staff/admin) |
| GET | /requests/{id} |
any authenticated | request detail (owner or staff/admin) |
| PATCH | /requests/{id}/status |
staff, admin | move a request through its lifecycle |
| PATCH | /requests/{id}/assign |
admin | assign a request to a staff member |
| GET | /dashboard/summary |
staff, admin | totals, status breakdown, avg. resolution time, staff workload |
| GET | /dashboard/my-requests |
any authenticated | requester's own status breakdown |
/registercurrently lets a caller set their ownrole. In production, restrict therolefield so only an existing admin can create staff/admin accounts (e.g. droprolefromUserRegisterand add a separate admin-only endpoint).- Add pagination to
GET /requestsonce volume grows. - Consider rate-limiting
/loginand/register.