Function routes

Source
pub fn routes(app_state: AppState) -> Router<AppState>
Expand description

Builds the complete application router for all HTTP endpoints.

The returned router has AppState as its state type and mounts all core API routes under their respective base paths.

§Route Structure:

  • /health → Health check endpoint (no authentication required).
  • /auth → Authentication endpoints (login, refresh, etc.).
  • /users → User management (restricted to admins via require_admin middleware).
  • /users/{user_id}/avatar → Publicly accessible avatar retrieval.
  • /modules → Module CRUD, personnel management, and assignments (requires authentication).
  • /me → User-specific endpoints (announcements, tickets, assignments, etc.)
  • /test → Development/test-only routes (mounted only if env != production).

The /test route group is mounted here instead of in main to:

  1. Keep main focused on server startup logic only.
  2. Avoid changing the Router type after construction, which can cause trait bound issues.
  3. Ensure that all route registration logic is centralized in one place.