How abeyakilesh/elgis-production works
Purpose and Runtime
This is an internal workforce and operations platform, not the generic Vite template described by the README. It combines HR attendance/payroll, sales CRM, orders/invoicing/delivery fulfillment, support tickets, live delivery tracking, and operational diagnostics.
The primary runtime is a React + TypeScript single-page application built with Vite. Browser clients use Supabase for authentication, Postgres data/RPCs, Realtime, Storage, and Edge Functions. Deployment is configured for Vercel. Entry points: src/main.tsx, src/App.tsx, src/lib/supabaseClient.ts, and vercel.json.
Application Shell, Navigation, and Access Boundary
src/App.tsx is the route composition point for the operational workspaces. src/components/layout/AppLayout.tsx provides the authenticated shell and app launcher; route boundaries are enforced in src/components/ProtectedRoute.tsx and src/components/RoleRoute.tsx.
Authentication identity is mapped to employee/role data through src/lib/useCurrentEmployee.ts and src/lib/roles.ts. The database is the authoritative authorization boundary: migrations establish RLS, scoped policies, auth helper requirements, and revoked public privileges, notably supabase/migrations/20260835000000_auth_helpers_require_active_status.sql, supabase/migrations/20260840000000_sec08_revoke_anon_table_privileges.sql, and supabase/migrations/20260846000000_sec11_narrow_remaining_policies.sql.
Workforce: Attendance and Payroll
Attendance manages punches, rosters, approvals, attendance overrides, weekly offs, and real-time updates. Its UI and domain layer are centered on src/pages/Attendance.tsx, src/lib/attendance.ts, and src/lib/useRealtimePunches.ts; schema evolution begins in supabase/migrations/20260707071648_initial_schema.sql and includes roster/approval migrations.
Payroll is a separate routed workspace for employee compensation, incentives, advances/loans, repayments, reports, and payroll runs: src/pages/payroll/PayrollLayout.tsx, src/lib/payroll.ts, and src/lib/advanceHistory.ts. Financial state transitions and correctness are pushed into database constraints/RPCs, including supabase/migrations/20260813000100_advance_loan_rpcs.sql, supabase/migrations/20260815000000_advance_approval_flow.sql, and supabase/migrations/20260850000000_cor01_server_side_finalize.sql.
Commercial, Orders, Invoices, and Deliveries
Sales is a CRM-style workspace for leads, customers, executives, pipeline, analytics, imports/exports, and an AI screen: src/pages/sales/SalesLayout.tsx, src/pages/sales/SalesPipeline.tsx, and src/lib/analytics.ts.
Orders are the commercial transaction boundary, covering creation, branch filtering, detail, invoice views, and delivery creation: src/pages/orders/OrdersLayout.tsx, src/pages/orders/OrderDetailPage.tsx, and src/lib/orders.ts. Database RPCs and migrations model transactional writes, invoice/order schema, financial buckets, and list/dashboard aggregates: supabase/migrations/20260715220000_order_transaction_rpcs.sql, supabase/migrations/20260802000000_orders_invoices_deliveries_schema.sql, and supabase/migrations/20260834000000_scale01_server_side_aggregates.sql.
Delivery fulfillment is decoupled from invoices and includes drivers, vehicles, branches, assigned orders, workflow state, and receiving: src/pages/orders/DeliveriesPage.tsx, src/lib/deliveryOrders.ts, and src/pages/ReceiveDeliveries.tsx. Core evolution appears in supabase/migrations/20260827000000_decouple_deliveries_from_invoices.sql and supabase/migrations/20260828000000_delivery_based_fulfilment.sql.
Field Operations and Support
Tracking consumes driver trips, location pings, stop reviews, messages, and return trips: src/pages/TrackingDashboard.tsx, src/lib/liveDrivers.ts, and src/lib/tripRoutes.ts. The schema and ownership controls are in supabase/migrations/20260720020000_driver_app_trips_and_versions.sql, supabase/migrations/20260720050000_driver_update_own_assigned_orders.sql, and supabase/migrations/20260720060000_trip_stop_reviews.sql.
Tickets provide a support workflow with attachments and events through src/pages/tickets/TicketsWorkspace.tsx, src/pages/tickets/NewTicket.tsx, and src/lib/tickets.ts; persistence and storage limits are established by supabase/migrations/20260718090000_tickets.sql and supabase/migrations/20260718120000_ticket_bucket_10mb.sql.
Operations, AI, and External Services
Mission Control and developer screens surface database, storage, diagnostics, live operations, and security state: src/pages/missioncontrol/MissionControlLayout.tsx, src/lib/missionControl.ts, and src/lib/diagnostics.ts. Health data can cross an Edge Function boundary at supabase/functions/vps-health/index.ts.
AI requests are intentionally proxied through Supabase rather than called directly by the client: src/lib/aiChat.ts, supabase/functions/groq-proxy/index.ts, and supabase/functions/_shared/auth.ts. Consent and audit concerns are first-class cross-cutting features via src/components/ConsentGate.tsx, src/lib/dpdpConsent.ts, and src/lib/activityLog.ts.
Main entry points: 20260846000000_sec11_narrow_remaining_policies.sql Postgres, RPCs and RLS · AppLayout.tsx Authenticated shell · supabaseClient.ts Supabase client · Attendance.tsx Attendance
Components 20
React SPA
- Vite entry
src/main.tsx - Route composition
src/App.tsx - Authenticated shell
src/components/layout/AppLayout.tsx - Route and role guards · Maps authenticated identities to employee roles before workspace access.
src/components/ProtectedRoute.tsx - Consent and activity audit
src/components/ConsentGate.tsx
Workforce
- Attendance
src/pages/Attendance.tsx - Payroll
src/pages/payroll/PayrollLayout.tsx
Commercial & Fulfillment
- Sales CRM
src/pages/sales/SalesLayout.tsx - Orders and invoices
src/pages/orders/OrdersLayout.tsx - Delivery fulfillment · Delivery workflows are decoupled from invoices.
src/pages/orders/DeliveriesPage.tsx
Field Ops & Support
- Live delivery tracking
src/pages/TrackingDashboard.tsx - Support tickets · Includes attachments and ticket events.
src/pages/tickets/TicketsWorkspace.tsx - Mission Control
src/pages/missioncontrol/MissionControlLayout.tsx
Supabase Platform
- Supabase client
src/lib/supabaseClient.ts - Auth and employee roles
src/lib/useCurrentEmployee.ts - Postgres, RPCs and RLS · Migrations enforce scoped policies, active-status helpers, and revoked public privileges.
supabase/migrations/20260846000000_sec11_narrow_remaining_policies.sql - Realtime
src/lib/useRealtimePunches.ts - Storage · Ticket attachment bucket has a 10 MB limit.
supabase/migrations/20260718120000_ticket_bucket_10mb.sql - AI proxy function · Keeps AI provider calls off browser clients.
supabase/functions/groq-proxy/index.ts - VPS health function
supabase/functions/vps-health/index.ts
Connections 31
- Vite entry → Route composition: boots
- Route composition → Authenticated shell: composes
- Authenticated shell → Route and role guards: protects routes
- Route and role guards → Auth and employee roles: resolves identity and roles
- Auth and employee roles → Postgres, RPCs and RLS: reads employee role data
- Authenticated shell → Attendance: routes to
- Authenticated shell → Payroll: routes to
- Authenticated shell → Sales CRM: routes to
- Authenticated shell → Orders and invoices: routes to
- Authenticated shell → Delivery fulfillment: routes to
- Authenticated shell → Live delivery tracking: routes to
- Authenticated shell → Support tickets: routes to
- Authenticated shell → Mission Control: routes to
- Attendance → Realtime: subscribes to punches
- Attendance → Postgres, RPCs and RLS: attendance data and approvals
- Payroll → Postgres, RPCs and RLS: payroll RPCs and constraints
- Sales CRM → Postgres, RPCs and RLS: CRM and aggregates
- Orders and invoices → Postgres, RPCs and RLS: transaction RPCs
- Orders and invoices → Delivery fulfillment: creates delivery work
- Delivery fulfillment → Postgres, RPCs and RLS: assignments and receiving
- Live delivery tracking → Realtime: consumes live trips and pings
- Live delivery tracking → Postgres, RPCs and RLS: trip ownership and stop reviews
- Support tickets → Postgres, RPCs and RLS: tickets and events
- Support tickets → Storage: uploads attachments
- Mission Control → VPS health function: checks VPS health
- Mission Control → Postgres, RPCs and RLS: inspects operations state
- Consent and activity audit → Postgres, RPCs and RLS: records consent and activity
- Supabase client → Postgres, RPCs and RLS: queries and invokes RPCs
- Supabase client → Realtime: opens subscriptions
- Supabase client → Storage: accesses objects
- AI proxy function → Postgres, RPCs and RLS: uses shared authorization