Routes
Complete route definitions with HTTP methods, paths, middleware chains, and access control for every API endpoint.
Routes
All Express Router modules live in backend/routes/. Each file defines the HTTP method, URL path, middleware chain, and controller handler for its domain.
Route Base Path
All routes are mounted under /api/v1/ in server.js:
app.use('/api/v1/auth', authRoutes);
app.use('/api/v1/users', userRoutes);
app.use('/api/v1/books', bookRoutes);
app.use('/api/v1/circulation', circulationRoutes);
app.use('/api/v1/fines', fineRoutes);
app.use('/api/v1/dashboard', dashboardRoutes);
app.use('/api/v1/notifications', notificationRoutes);Additionally, src/app.js mounts supplementary routes:
app.use('/api/reservations', reservationRoutes);
app.use('/api/dashboard', dashboardRoutes);
app.use('/api/notifications', notificationRoutes);
app.use('/api/config', systemConfigRoutes);
app.use('/api/audit', auditRoutes);
app.use('/api/reports', reportRoutes);1. Auth Routes
File: routes/auth.js
Includes rate limiting: 5 requests per minute per IP on setup, login, and refresh.
| Method | Path | Middleware | Handler | Description |
|---|---|---|---|---|
POST | /api/v1/auth/setup | authLimiter | authController.setup | Create initial Super Admin |
POST | /api/v1/auth/login | authLimiter | authController.login | Authenticate and get JWT + refresh token |
POST | /api/v1/auth/refresh | authLimiter | authController.refresh | Exchange refresh token for new access token |
POST | /api/v1/auth/logout | — | authController.logout | Blacklist tokens and log out |
GET | /api/v1/auth/me | authenticate | authController.getMe | Get current user profile |
Note:
setup,login, andrefreshare public endpoints (no auth required). Rate-limited to 5 requests per minute per IP.
2. User Routes
File: routes/users.js
All user routes require authentication (router.use(authenticate)). Includes rate limiting on user creation.
| Method | Path | Middleware | Handler | Description |
|---|---|---|---|---|
GET | /api/v1/users | authorize(['ROLE_ADMIN', 'ROLE_LIBRARIAN']) | userController.listUsers | List all users |
POST | /api/v1/users | authLimiter, authorize(['ROLE_ADMIN']) | userController.createUser | Create new user |
GET | /api/v1/users/me | — | userController.getMe | Get own profile |
PATCH | /api/v1/users/me | — | userController.updateMe | Update own profile |
GET | /api/v1/users/:id | authorize(['ROLE_ADMIN', 'ROLE_LIBRARIAN']) | userController.getUser | Get single user |
PATCH | /api/v1/users/:id | authorize(['ROLE_ADMIN', 'ROLE_LIBRARIAN']) | userController.updateUser | Update user |
3. Book Routes
File: routes/books.js
| Method | Path | Middleware | Handler | Description |
|---|---|---|---|---|
GET | /api/v1/books/categories | authenticate | bookController.listCategories | List all categories |
GET | /api/v1/books | authenticate | bookController.listBooks | List all books (search, filter, paginate) |
GET | /api/v1/books/:id | authenticate | bookController.getBook | Get single book with copies |
POST | /api/v1/books | authenticate, authorize(['ROLE_ADMIN', 'ROLE_LIBRARIAN']) | bookController.createBook | Create book |
PATCH | /api/v1/books/:id | authenticate, authorize(['ROLE_ADMIN', 'ROLE_LIBRARIAN']) | bookController.updateBook | Update book |
DELETE | /api/v1/books/:id | authenticate, authorize(['ROLE_ADMIN', 'ROLE_LIBRARIAN']) | bookController.deleteBook | Delete book |
POST | /api/v1/books/:id/copies | authenticate, authorize(['ROLE_ADMIN', 'ROLE_LIBRARIAN']) | bookController.addCopy | Add physical copy |
4. Circulation Routes
File: routes/circulation.js
All circulation routes require authentication (router.use(authenticate)).
| Method | Path | Middleware | Handler | Description |
|---|---|---|---|---|
POST | /api/v1/circulation/issue | authorize(['ROLE_ADMIN', 'ROLE_LIBRARIAN']) | circulationController.issueBook | Issue book to user |
POST | /api/v1/circulation/return | authorize(['ROLE_ADMIN', 'ROLE_LIBRARIAN']) | circulationController.returnBook | Process book return |
GET | /api/v1/circulation/history | — | circulationController.getHistory | Get borrowing history |
GET | /api/v1/circulation/active | authorize(['ROLE_ADMIN', 'ROLE_LIBRARIAN']) | circulationController.getActive | List active loans |
Note:
historyis available to all authenticated users but the controller filters results by role — students see only their own history.
5. Fine Routes
File: routes/fines.js
All fine routes require authentication (router.use(authenticate)).
| Method | Path | Middleware | Handler | Description |
|---|---|---|---|---|
GET | /api/v1/fines | — | fineController.listFines | List fines (role-filtered) |
POST | /api/v1/fines/:id/pay | authorize(['ROLE_ADMIN', 'ROLE_LIBRARIAN']) | fineController.payFine | Mark fine as paid |
6. Dashboard Routes
File: routes/dashboard.js
| Method | Path | Middleware | Handler | Description |
|---|---|---|---|---|
GET | /api/v1/dashboard/stats | authenticate | dashboardController.getStats | Get aggregate statistics |
GET | /api/v1/dashboard/analytics | authenticate | dashboardController.getAnalytics | Get trend data (loans, revenue) |
7. Notification Routes
File: routes/notifications.js
All notification routes require authentication (router.use(authenticate)).
| Method | Path | Middleware | Handler | Description |
|---|---|---|---|---|
GET | /api/v1/notifications | — | notificationController.getMyNotifications | Get own notifications (max 50) |
PUT | /api/v1/notifications/mark-all-read | — | notificationController.markAllAsRead | Mark all as read |
PUT | /api/v1/notifications/:id/read | — | notificationController.markAsRead | Mark single notification as read |
8. Reservation Routes
File: routes/reservations.js
All reservation routes require authentication (router.use(authenticate)).
| Method | Path | Middleware | Handler | Description |
|---|---|---|---|---|
POST | /api/v1/reservations | — | reservationController.createReservation | Create a reservation |
GET | /api/v1/reservations/me | — | reservationController.listMyReservations | List own reservations |
POST | /api/v1/reservations/:id/cancel | — | reservationController.cancelReservation | Cancel own reservation |
GET | /api/v1/reservations | authorize(['ROLE_ADMIN', 'ROLE_LIBRARIAN']) | reservationController.listAllReservations | List all reservations |
POST | /api/v1/reservations/:id/fulfill | authorize(['ROLE_ADMIN', 'ROLE_LIBRARIAN']) | reservationController.fulfillReservation | Fulfill reservation |
9. Report Routes
File: routes/reports.js
All report routes require authentication and ROLE_ADMIN or ROLE_LIBRARIAN authorization.
| Method | Path | Middleware | Handler | Description |
|---|---|---|---|---|
GET | /api/v1/reports/circulation | authorize(['ROLE_ADMIN', 'ROLE_LIBRARIAN']) | reportController.exportCirculation | Download circulation CSV |
GET | /api/v1/reports/fines | authorize(['ROLE_ADMIN', 'ROLE_LIBRARIAN']) | reportController.exportFines | Download fines CSV |
10. Audit Routes
File: routes/audit.js
All audit routes require authentication and ROLE_ADMIN authorization.
| Method | Path | Middleware | Handler | Description |
|---|---|---|---|---|
GET | /api/v1/audit | authorize(['ROLE_ADMIN']) | auditController.getAuditLogs | Get paginated audit logs |
11. System Config Routes
File: routes/systemConfig.js
All config routes require authentication and ROLE_ADMIN authorization.
| Method | Path | Middleware | Handler | Description |
|---|---|---|---|---|
GET | /api/v1/config | authorize(['ROLE_ADMIN']) | systemConfigController.getAllConfigs | List all configs |
PATCH | /api/v1/config/:id | authorize(['ROLE_ADMIN']) | systemConfigController.updateConfig | Update config value |
Access Control Summary
| Endpoint Group | Public | Student | Staff | Librarian | Admin |
|---|---|---|---|---|---|
| Auth (setup, login, refresh) | ✅ | ✅ | ✅ | ✅ | ✅ |
| Auth (me) | — | ✅ | ✅ | ✅ | ✅ |
| Users (own) | — | ✅ | ✅ | ✅ | ✅ |
| Users (all) | — | — | — | ✅ (read) | ✅ (full) |
| Books (read) | — | ✅ | ✅ | ✅ | ✅ |
| Books (write) | — | — | — | ✅ | ✅ |
| Circulation (issue/return) | — | — | — | ✅ | ✅ |
| Circulation (history) | — | ✅ (own) | ✅ (own) | ✅ (all) | ✅ (all) |
| Circulation (active) | — | — | — | ✅ | ✅ |
| Fines (read) | — | ✅ (own) | ✅ (own) | ✅ (all) | ✅ (all) |
| Fines (pay) | — | — | — | ✅ | ✅ |
| Dashboard | — | ✅ | ✅ | ✅ | ✅ |
| Notifications | — | ✅ | ✅ | ✅ | ✅ |
| Reservations (own) | — | ✅ | ✅ | ✅ | ✅ |
| Reservations (all/fulfill) | — | — | — | ✅ | ✅ |
| Reports | — | — | — | ✅ | ✅ |
| Audit Logs | — | — | — | — | ✅ |
| System Config | — | — | — | — | ✅ |