How gopikrishnan20/cirs works
Purpose and entry points
Campus Infrastructure Issue Redressal System is a role-based PWA for the Student → Faculty Advisor → Academic Advisor → Maintenance workflow. The React client starts at frontend/src/main.tsx and routes from frontend/src/App.tsx; the Fastify API starts through backend/api/src/index.ts and backend/api/src/server.ts. Node 20+ hosts all workspaces.
Shared domain contract
shared/ prevents frontend/backend drift on roles, categories, schemas, and ticket lifecycle rules. Both applications import shared/src/index.ts; the state machine and valid transitions reside in shared/src/ticket-status.ts, with permissions/roles in shared/src/roles.ts and request/domain validation in shared/src/schemas.ts. UI visibility may use this contract, but the API remains authoritative.
Client application and role workspaces
The Vite React PWA provides public authentication, student reporting/tracking, approval queues, maintenance worklists, administration, and analytics. Authentication/session ownership is centralized in frontend/src/auth/AuthProvider.tsx; browser API integration and Supabase access are bounded by frontend/src/lib/api.ts and frontend/src/lib/supabase.ts. Role-specific screens are organized under frontend/src/routes/student/, frontend/src/routes/fa/, frontend/src/routes/hod/, frontend/src/routes/lab/, and frontend/src/routes/admin/.
API boundary, identity, and authorization
Fastify exposes the application’s trusted server boundary. Routes are assembled in backend/api/src/routes/index.ts, with ticket operations in backend/api/src/routes/tickets.ts and administrative operations in backend/api/src/routes/admin/index.ts. JWT verification and actor derivation happen in backend/api/src/auth/verify-token.ts and backend/api/src/auth/actor.ts; backend/api/src/plugins/authenticate.ts applies request authentication. The API uses Supabase service credentials and re-derives per-ticket relationships rather than trusting frontend role claims.
Ticket lifecycle and operational services
Tickets flow from submission through assigned approval/maintenance stages and eventually closure or reopening. Core orchestration/query logic is in backend/api/src/services/tickets.ts and backend/api/src/services/ticket-queries.ts; route-level operations are rendered consistently through backend/api/src/lib/ticket-view.ts. Attachments/photos are handled by backend/api/src/services/photos.ts and backend/api/src/routes/photos.ts. CSV imports/exports and reports cross explicit server boundaries via backend/api/src/routes/admin/imports.ts, backend/api/src/routes/exports.ts, and backend/api/src/services/pdf-report.ts.
Supabase persistence and integrity model
Supabase supplies Postgres, Auth, Storage, and RLS. Incremental schema ownership is under backend/supabase/migrations/, especially ticket/event rules in 20260804000500_tickets.sql and 20260804000600_ticket_triggers.sql, identity in 20260804000200_identity.sql, and policy enforcement in 20260804000900_rls.sql. ticket_events is the immutable status-history source of truth; database triggers derive tickets.status and reject direct divergence. Notifications/audit and analytics are persisted through 20260804000700_notifications_audit.sql and 20260804001000_analytics_views.sql.
Notifications, jobs, and external integrations
The API creates in-app notifications and optional email/web-push delivery through backend/api/src/services/notify.ts, backend/api/src/services/mailer.ts, and backend/api/src/services/push.ts. backend/api/src/services/jobs.ts runs cron-based digests in the API process, so it is single-instance safe only. Resend is optional for email; missing credentials log rendered messages. VAPID-backed push is optional, while Supabase Storage supports uploaded ticket photos.
Main entry points: services/tickets.ts Ticket orchestration · index.ts Route assembly · main.tsx PWA entry and routing · routes/tickets.ts Ticket and photo routes
Components 20
React PWA
- PWA entry and routing
frontend/src/main.tsx - Session provider · Centralizes browser session ownership.
frontend/src/auth/AuthProvider.tsx - Role workspaces · Student, advisor, maintenance, administration, and analytics screens.
- Browser API client
frontend/src/lib/api.ts - Browser Supabase client
frontend/src/lib/supabase.ts
Fastify API
- API bootstrap
backend/api/src/index.ts - Route assembly
backend/api/src/routes/index.ts - Authentication and actor · Verifies JWTs and derives actors rather than trusting client role claims.
backend/api/src/auth/verify-token.ts - Ticket and photo routes
backend/api/src/routes/tickets.ts - Ticket orchestration · Applies lifecycle operations and authorization-aware ticket logic.
backend/api/src/services/tickets.ts - Ticket queries and views · Builds ticket queries and consistent route-level ticket views.
backend/api/src/services/ticket-queries.ts - Admin import, export, reports · Crosses explicit server boundaries for CSV and PDF output.
backend/api/src/routes/admin/imports.ts - Notifications and digests · Creates notifications and runs single-instance in-process cron digests.
backend/api/src/services/notify.ts
Supabase
- Auth and identity
backend/supabase/migrations/20260804000200_identity.sql - Tickets and event history · Immutable ticket_events drive ticket status through database rules.
backend/supabase/migrations/20260804000500_tickets.sql - Triggers and RLS · Triggers prevent status divergence; RLS enforces access policies.
backend/supabase/migrations/20260804000600_ticket_triggers.sql - Ticket photo storage
- Notifications, audit, analytics
backend/supabase/migrations/20260804000700_notifications_audit.sql
Delivery Integrations
- Email and web push · Resend email and VAPID push are optional.
backend/api/src/services/mailer.ts
Other components
- Shared domain contract · Roles, schemas, and ticket lifecycle rules shared by both runtimes.
shared/src/index.ts
Connections 22
- PWA entry and routing → Session provider: initializes
- PWA entry and routing → Role workspaces: routes to
- Session provider → Browser Supabase client: uses session
- Role workspaces → Browser API client: calls
- PWA entry and routing → Shared domain contract: imports contract
- Browser API client → API bootstrap: HTTPS requests
- API bootstrap → Route assembly: registers
- Route assembly → Authentication and actor: authenticates
- Route assembly → Ticket and photo routes: mounts
- Ticket and photo routes → Ticket orchestration: executes operations
- Ticket orchestration → Ticket queries and views: reads and renders
- Ticket orchestration → Shared domain contract: enforces lifecycle
- Authentication and actor → Auth and identity: verifies identity
- Ticket orchestration → Tickets and event history: writes events
- Ticket queries and views → Tickets and event history: queries
- Tickets and event history → Triggers and RLS: governed by
- Ticket and photo routes → Ticket photo storage: uploads photos
- Route assembly → Admin import, export, reports: mounts admin I/O
- Ticket orchestration → Notifications and digests: emits notifications
- Notifications and digests → Notifications, audit, analytics: persists notifications
- Notifications and digests → Email and web push: delivers optionally
- Admin import, export, reports → Notifications, audit, analytics: reads reports