Standard patterns for all FastAPI endpoints. Apply these conventions when implementing any list, detail, or mutation endpoint.
http://localhost:8000/api # development
https://api.example.com/api # production (future)
All endpoints except /api/auth/login, /api/auth/signup, and /api/auth/refresh require a valid access_token httpOnly cookie. See security.md.
The backend derives institution_id and role from the JWT — clients must never send these as request parameters.
All list endpoints use offset-based pagination.
GET /api/students?page=1&limit=20
GET /api/attendance?page=2&limit=50&sort=date&order=desc
| Parameter | Default | Max | Description |
|---|---|---|---|
page |
1 |
— | Page number (1-indexed) |
limit |
20 |
100 |
Items per page |
sort |
entity default | — | Sort field (optional, v1) |
order |
desc |
— | asc or desc (optional, v1) |
{
"data": [ ... ],
"meta": {
"page": 1,
"limit": 20,
"total": 247,
"total_pages": 13
}
}| Endpoint | Default sort |
|---|---|
GET /api/students |
created_at desc |
GET /api/faculty |
created_at desc |
GET /api/parents |
created_at desc |
GET /api/attendance |
date desc |
GET /api/performance |
semester desc |
GET /api/analytics/departments |
name asc |
GET /api/at-risk |
risk_probability desc |
GET /api/reports |
created_at desc |
All errors follow a consistent format:
{
"detail": "Human-readable error message",
"code": "ERROR_CODE"
}| Code | Usage |
|---|---|
400 |
Validation error, malformed request |
401 |
Missing or invalid auth token |
403 |
Authenticated but not authorized for this resource |
404 |
Resource not found (within tenant scope) |
409 |
Conflict (e.g. duplicate roll number within institution) |
422 |
Pydantic validation failure (FastAPI default) |
429 |
Rate limit exceeded |
500 |
Unhandled server error |
| Code | Meaning |
|---|---|
AUTH_INVALID_CREDENTIALS |
Wrong email/roll number or password |
AUTH_ACCOUNT_DISABLED |
is_login_enabled = false |
AUTH_TOKEN_EXPIRED |
Access token expired; use refresh endpoint |
TENANT_FORBIDDEN |
Resource belongs to a different institution |
ROLE_FORBIDDEN |
User role cannot access this endpoint |
DUPLICATE_ROLL_NUMBER |
Roll number already exists in this institution |
DUPLICATE_EMAIL |
Email already exists in this institution |
- Every list and detail query includes
WHERE institution_id = :current_institution_id AND deleted_at IS NULL - The
institution_idis extracted from the JWT by the auth dependency — never from request params - Returning
404(not403) when a resource exists but belongs to another tenant prevents information leakage
Detail endpoints return the resource directly (no data wrapper):
{
"id": "uuid",
"roll_number": "20231CSE0260",
"name": "Kishore S V",
...
}| Operation | Status | Body |
|---|---|---|
| Create | 201 Created |
Created resource |
| Update | 200 OK |
Updated resource |
| Delete (soft) | 204 No Content |
Empty |
| Bulk create | 201 Created |
{ "created": N, "data": [...] } |