Skip to content

API Guide

See the OpenAPI specification for the detailed contract of each endpoint.


Endpoint Summary

All routes use the /api/v1 prefix. Authentication via Authorization: Bearer <JWT> + X-Device-Id header.

Health & Meta

MethodRouteRolesDescription
GET/api/v1/healthPublicService health check
GET/.well-known/security.txtPublicRFC 9116

Authentication

MethodRouteRolesDescription
POST/api/v1/auth/loginPublicLogin (email + password) — rate limit: 5/min
POST/api/v1/auth/refreshPublicRenew access token — rate limit: 10/min
POST/api/v1/auth/revokeAuthenticatedRevoke current session
POST/api/v1/session/validateAuthenticatedValidate active session

Students

MethodRouteRolesDescription
GET/api/v1/studentsAuthenticatedList students (paginated, search)
POST/api/v1/studentsADMIN, CADASTROCreate student
PATCH/api/v1/students/:studentIdADMIN, CADASTROUpdate student
POST/api/v1/students/:studentId/deleteADMINSoft-delete student (justification required)

Attendance

MethodRouteRolesDescription
POST/api/v1/attendance/eventsCHAMADOR, ADMINMark a student present

Classes

MethodRouteRolesDescription
GET/api/v1/classesAuthenticatedList classes
POST/api/v1/classesADMINCreate class
PATCH/api/v1/classes/:classIdADMINUpdate class
POST/api/v1/classes/:classId/deleteADMINSoft-delete class

Nuclei

MethodRouteRolesDescription
GET/api/v1/nucleiAuthenticatedList nuclei
POST/api/v1/nucleiADMINCreate nucleus
PATCH/api/v1/nuclei/:nucleusIdADMINUpdate nucleus
POST/api/v1/nuclei/:nucleusId/deleteADMINSoft-delete nucleus

Users

MethodRouteRolesDescription
GET/api/v1/usersADMINList users
POST/api/v1/usersADMINCreate user
PATCH/api/v1/users/:userIdADMINUpdate user
POST/api/v1/users/:userId/reset-passwordADMINReset password
POST/api/v1/users/:userId/deactivateADMINDeactivate user

Roles

MethodRouteRolesDescription
GET/api/v1/rolesADMINList roles
POST/api/v1/rolesADMINCreate custom role
PATCH/api/v1/roles/:roleNameADMINUpdate role
DELETE/api/v1/roles/:roleNameADMINDelete role (non-system)

Sync

MethodRouteRolesDescription
POST/api/v1/sync/eventsCHAMADOR, ADMIN, CADASTROBatch wrapper — processes multiple events
POST/api/v1/sync/eventAuthenticatedProcesses 1 event atomically via D1.batch()

Dev

MethodRouteRolesDescription
POST/_seedDemo data seed (development only)

Required Headers (Authenticated Requests)

HeaderValue
AuthorizationBearer <accessToken>
X-Device-IdUUID v4 identifying the device
Idempotency-KeyUUID v4 (all mutations: POST, PATCH)

Error Format

All errors follow the envelope:

json
{
  "error": "ERROR_CODE",
  "message": "Human-readable description",
  "details": {}
}
StatusCodeMeaning
400VALIDATION_FAILEDInvalid body or missing required header
401UNAUTHORIZEDToken missing, invalid, or expired
401COMPROMISED_SESSIONRefresh token reused (possible theft)
403FORBIDDEN_ROLERole not allowed for the endpoint
404NOT_FOUNDRoute not found
409IDEMPOTENCY_KEY_REUSED_WITH_DIFFERENT_PAYLOADIdempotency key reused with a different payload
500CONFIG_ERRORServer configuration error

Source: router.ts + workers/CONTEXT.md

Distributed under MIT License.