How divyansh-cyber/zero-latency-cwc-26 works
1. System shape
CivicNexus is a two-tier hackathon POC: a Node/Express backend with MongoDB/Mongoose persistence, and a React/Vite frontend. The backend is the source of truth for auth, geo-scope enforcement, issue/poll/meeting state, and admin actions; the frontend is mostly a scoped presentation layer.
2. Composition root
backend/src/server.js is the entry point that wires middleware, routes, services, and scheduled jobs. It is the place where the API, isolation guard, and periodic background tasks come together.
3. Core architectural boundary: geo-isolation
The defining boundary is geographic scope. Users receive JWT geo-claims at login, and middleware/spaceGuard.js enforces which locality/colony/city resources they can access. This is the main security and data-partitioning control across the app.
4. Identity and onboarding
Auth lives in routes/auth.js and middleware/duoAuth.js. The implementation simulates Cisco Duo rather than doing a live OIDC flow, but it still produces a JWT that carries role and geography. Admin approval/rejection is handled separately in routes/admin.js, which gates registration into the usable user base.
5. Domain model
The backend stores five main entities in src/models: User, GeoHierarchy, Issue, Poll, and Meeting. GeoHierarchy provides the nested civic structure used by all scope checks, while the other models represent the operational objects users interact with.
6. Scoped feature routes
The API is split by feature into routes/issues.js, routes/polls.js, routes/meetings.js, routes/spaces.js, routes/dashboard.js, and routes/admin.js. Each route layer is responsible for one user-facing subsystem and relies on shared scope utilities to filter data before it leaves the server.
7. Scope helpers as policy layer
The utils/ modules (issueAccess.js, pollScope.js, meetingScope.js, dashboardScope.js) are the reusable policy layer. They determine what a given user can see or act on, and they keep the route handlers thin by centralizing “who can view what” logic.
8. Issue lifecycle and escalation
Issues are more than simple tickets: they carry SLA state and can escalate vertically from locality to colony to city. services/escalation.js and services/registrationEscalation.js implement that upward propagation, while utils/issueAccess.js ensures a user only sees issues at or below their legitimate scope unless escalation has made them public at a higher tier.
9. Polls and automated closing
Polls are created and voted on through the polls route, but closure is automated by services/pollCloser.js. This is a distinct background-processing lane: user actions mutate poll state, then a scheduled service finalizes it after the configured window.
10. Meetings and discussions
Town halls/meetings are represented in Mongo and served through routes/meetings.js. Discussions are mediated by Webex integration in services/webexService.js, with the frontend also offering a Webex widget or REST fallback. This makes Webex the communications boundary, but the app still functions in mock mode if tokens are absent.
11. Analytics and dashboards
services/splunkService.js powers the dashboard/analytics side, with mock Mongo-backed behavior when Splunk credentials are not present. routes/dashboard.js consumes this service to show role-scoped engagement statistics rather than raw cross-city data.
12. Frontend structure
The React app is organized by user journey: auth pages, Dashboard, SpacePortal, issue tracking/detail, admin, and an isolation demo. Shared state is carried through AuthContext and SpaceContext; useSpace.js and useWebex.js are the main hooks tying UI state to backend scope and comms features.
13. Client-server interaction
The frontend talks to the backend through src/utils/api.js, and vite.config.js supports local development proxying. This matters because auth appears to rely on cookie/session behavior from the backend, so the empty VITE_API_URL setup preserves same-origin proxy semantics during dev.
14. Operational tooling
Local infrastructure is intentionally simple: MongoDB runs in Docker via docker-compose.yml or a direct container, and scripts/seed-demo-data.js populates the civic hierarchy plus demo accounts. The fast-forward scripts exist to force SLA and poll state transitions for demos and tests.
15. Quality and verification
The backend has targeted tests for middleware, routes, services, and scope utilities, which reflects where the real complexity lives: access control and state transitions. For an architecture diagram, the important testing boundary is that route behavior is validated through scope-aware service layers, not just isolated UI behavior.
Main entry points: server.js Server · auth.js Auth · issues.js Issues · polls.js Polls
Components 29
Backend
Express API, policy, domain models, and background services.
- Server · Bootstraps middleware, routes, services, and scheduled jobs.
civicnexus/backend/src/server.js - Auth · Registration and login flow with JWT issuance and approval gates.
civicnexus/backend/src/routes/auth.js - Admin · Approval, rejection, and admin actions for onboarding and moderation.
civicnexus/backend/src/routes/admin.js - Space Guard · Enforces geographic scope and resource isolation from JWT claims.
civicnexus/backend/src/middleware/spaceGuard.js - Geo Hierarchy · Nested civic structure used for locality, colony, and city scoping.
civicnexus/backend/src/models/GeoHierarchy.js - Issues · Issue creation, retrieval, and escalation-aware updates.
civicnexus/backend/src/routes/issues.js - Polls · Poll creation, voting, and lifecycle endpoints.
civicnexus/backend/src/routes/polls.js - Meetings · Town hall and discussion endpoints for civic meetings.
civicnexus/backend/src/routes/meetings.js - Dashboard · Role-scoped analytics and engagement views.
civicnexus/backend/src/routes/dashboard.js - Spaces · Space and hierarchy lookup endpoints for scoped navigation.
civicnexus/backend/src/routes/spaces.js - Issue Policy · Centralized visibility and access rules for issues.
civicnexus/backend/src/utils/issueAccess.js - Poll Policy · Scoped poll visibility and participation rules.
civicnexus/backend/src/utils/pollScope.js - Meeting Policy · Scoped meeting visibility rules.
civicnexus/backend/src/utils/meetingScope.js - Dashboard Policy · Role-based dashboard filtering and aggregation rules.
civicnexus/backend/src/utils/dashboardScope.js - Escalation · Propagates issues upward across locality, colony, and city tiers.
civicnexus/backend/src/services/escalation.js - Poll Closer · Background finalizer that closes polls after the voting window.
civicnexus/backend/src/services/pollCloser.js - Webex · Discussion and meeting integration with mock fallback behavior.
civicnexus/backend/src/services/webexService.js - Splunk · Analytics backend with mock Mongo-backed fallback when credentials are absent.
civicnexus/backend/src/services/splunkService.js
Frontend
React/Vite presentation layer and scoped client state.
- Auth Context · Carries login and approval state across the React app.
civicnexus/frontend/src/contexts/AuthContext.jsx - Space Context · Holds selected geographic scope for the UI.
civicnexus/frontend/src/contexts/SpaceContext.jsx - Dashboard · Role-scoped civic overview and metrics page.
civicnexus/frontend/src/pages/Dashboard.jsx - Space Portal · Scoped navigation hub for locality and colony views.
civicnexus/frontend/src/pages/SpacePortal.jsx - Issues UI · Issue tracker, detail, and raise flows.
civicnexus/frontend/src/pages/IssueTracker.jsx - Admin Page · Frontend surface for user approval and admin actions.
civicnexus/frontend/src/pages/AdminPage.jsx - App Shell · Top-level client routing and shared application composition.
civicnexus/frontend/src/App.jsx - API Client · Shared backend request layer used by the React app.
civicnexus/frontend/src/utils/api.js
Ops
Seed, demo, and runtime support scripts.
- Seed Data · Populates civic hierarchy and demo accounts.
civicnexus/scripts/seed-demo-data.js - Poll Fast-Forward · Forces poll state transitions for demos and tests.
civicnexus/scripts/fast-forward-polls.js - SLA Fast-Forward · Advances issue SLA state for demos and tests.
civicnexus/scripts/fast-forward-sla.js
Connections 28
- Server → Auth: mounts · Registers auth endpoints on the API.
- Server → Admin: mounts · Registers admin endpoints.
- Server → Issues: mounts · Registers issue endpoints.
- Server → Polls: mounts · Registers poll endpoints.
- Server → Meetings: mounts · Registers meeting endpoints.
- Server → Dashboard: mounts · Registers analytics endpoints.
- Server → Spaces: mounts · Registers space lookup endpoints.
- Server → Space Guard: applies · Applies geo-isolation to protected routes.
- Auth → Geo Hierarchy: reads · Uses civic hierarchy data for claims and onboarding.
- Auth → Auth Context: issues JWT · Produces login state consumed by the client.
- Admin → Auth: approves · Completes registration into the usable user base.
- Issues → Issue Policy: filters by scope · Limits issue visibility and actions.
- Issues → Escalation: escalates · Propagates issues upward across civic tiers.
- Polls → Poll Policy: filters by scope · Controls who can see or vote on polls.
- Polls → Poll Closer: schedules · Delegates timed poll closure to background processing.
- Meetings → Meeting Policy: filters by scope · Restricts meeting visibility to the user's locality.
- Meetings → Webex: integrates · Connects civic meetings to Webex discussion infrastructure.
- Dashboard → Dashboard Policy: filters by scope · Shapes analytics by user role and geography.
- Dashboard → Splunk: queries · Pulls engagement metrics from analytics service.
- Space Portal → Space Context: consumes · Uses the selected geo scope for navigation and rendering.
- Dashboard → API Client: calls · Fetches scoped dashboard data from the backend.
- Issues UI → API Client: calls · Reads and writes issue data through the shared client.
- Admin Page → API Client: calls · Sends admin review actions through the shared client.
- App Shell → Auth Context: wraps · Provides authentication state to the UI.
- App Shell → Space Context: wraps · Provides scope state to the UI.
- Seed Data → Geo Hierarchy: seeds · Creates the civic hierarchy used for isolation and demo data.
- Poll Fast-Forward → Poll Closer: drives · Forces poll transitions for demos and tests.
- SLA Fast-Forward → Escalation: drives · Advances issue SLA state for demos and tests.