How sunbird-spark/sunbird-spark-portal works
1. Overall shape
- This is a two-app monorepo: frontend/ is a React 19 SPA, and backend/ is an Express 5 API server.
- In production, the backend also serves the built frontend bundle; in development, Vite runs the UI and proxies API/content routes to the backend.
2. Primary runtime boundary
- The frontend is a client-side application with route-level pages, shared components, hooks, and client services.
- The backend is the system boundary for authentication, session management, upstream proxying, and persistence access.
3. Frontend presentation layer
- UI is organized by route domains such as home, collection, workspace, reports, profile, signup, onboarding, and user management.
- Shared building blocks live under components/, while page orchestration lives under pages/.
- The app uses React Router, TanStack Query for server state, Tailwind for styling, and i18next for localization.
4. Frontend data access and business logic
- API communication is centralized in src/api/, src/services/, and src/lib/http-client/.
- Hooks under src/hooks/ encapsulate feature-specific state and data loading, while src/rbac/ gates routes and components by role.
- This separation keeps pages thin: pages compose hooks/services and render feature components.
5. Content and player subsystem
- A major frontend subsystem is content rendering and authoring: PDF, video, ePub, and QUML players, plus collection/content editors.
- These depend on Sunbird web components and require static assets copied into public/assets/ during install.
- The player/editor layers sit behind page components and feature services, not directly in the routing layer.
6. Authentication and session model
- Browser users authenticate through the backend using OIDC/Keycloak and Google OAuth.
- The frontend stores auth state in AuthContext and uses ProtectedRoute, PermissionGate, and OnboardingGuard to enforce access.
- Backend sessions are used for browser flows; mobile flows are token-based and bypass server sessions.
7. Backend request pipeline
- Express routes are split by domain under src/routes/, then mapped to controllers, which call services.
- Cross-cutting middleware handles auth, conditional session handling, validation, and request shaping before handlers run.
- This creates a clear chain: route → middleware → controller → service → database/proxy/external auth provider.
8. Backend persistence and state
- Persistent storage is split by concern: YugabyteDB/pg for general relational data and session storage, plus Cassandra-compatible access for forms and review comments.
- Session storage can be in-memory or Yugabyte-backed depending on configuration.
- The backend also maintains typed environment configuration in src/config/env.ts, making deployment settings part of the architecture boundary.
9. Backend integrations and upstream proxying
- Several backend routes act as reverse proxies to upstream Sunbird services via http-proxy-middleware.
- Proxies exist for Kong, Knowlg middleware, user-related services, and other content/plugin paths.
- This means the backend is not just an API host; it is also an aggregation and routing layer for external platform services.
10. Auth special cases for mobile
- Mobile support is a distinct backend subsystem under /mobile: native Keycloak login, Google sign-in, and token refresh.
- These endpoints return tokens directly and do not rely on browser session cookies.
- The frontend also supports mobile WebView flows for signup and password reset, passing language and redirect context through query/session state.
11. Telemetry, reporting, and observability
- The frontend includes telemetry providers/components and content/player telemetry context builders.
- Reporting pages and services are a separate slice, with charts, tables, and export helpers on the UI side.
- On the backend, telemetry, user, tenant, organization, and forms services provide the data and integrations those workflows depend on.
12. Internationalization and locale flow
- i18n is a first-class cross-cutting concern in the frontend, with locale files for English, French, Portuguese, and Arabic.
- Arabic adds RTL handling via a direction provider and CSS overrides.
- Language choice is persisted in browser storage and also coordinated with Keycloak/mobile flows so login and recovery pages match the selected locale.
13. Build, packaging, and deployment
- The repo uses separate frontend and backend toolchains, both TypeScript-based and both tested with Vitest.
- A multi-stage Dockerfile builds the frontend, compiles the backend, and produces a production image that runs the server and serves static assets.
- GitHub Actions handle PR validation and image publishing, so the architecture is intended for repeatable cloud deployment.
14. What to show in a diagram
- Diagram the browser SPA as the main user entry point, with the backend as the central orchestration/API node.
- Show backend fan-out to Keycloak/Google, YugabyteDB/Cassandra, and upstream Sunbird services via proxies.
- Show the frontend split into routing, feature components, hooks/services, auth/RBAC, and content-player/editor subsystems, with shared static assets supporting the players/editors.
Main entry points: pages Pages · app.ts Express API · middlewares Middleware & Controllers · players Content System
Components 22
Frontend SPA
React client app with routes, feature UI, state, and player/editor subsystems.
- Browser App · Primary user entry into the portal SPA.
frontend/src/main.tsx - Routes · Route map and page-level composition for the SPA.
frontend/src/AppRoutes.tsx - Pages · Domain pages for home, collection, workspace, reports, profile, signup, onboarding, and admin flows.
frontend/src/pages - Shared UI · Reusable presentation components and layout primitives.
frontend/src/components - Auth & RBAC · Client auth state plus route/component guards for protection and onboarding.
frontend/src/auth - API Layer · Central HTTP client, API modules, and feature services for server communication.
frontend/src/api - Feature Hooks · Feature-specific data loading and state orchestration.
frontend/src/hooks - Content System · PDF, video, ePub, QUML players and collection/content editors.
frontend/src/components/players - Telemetry UI · Telemetry providers and context builders used by content and analytics workflows.
frontend/src/components/telemetry - Locale Layer · Language loading, direction handling, and locale persistence.
frontend/src/configs/i18n.ts
Backend API
Express server for auth, routing, persistence, and upstream proxying.
- Express API · Backend application boundary for browser session flows, token flows, and orchestration.
backend/src/app.ts - Domain Routes · API route modules grouped by domain and flow.
backend/src/routes - Middleware & Controllers · Auth, session, validation, and controller handling before services run.
backend/src/middlewares - Backend Services · Core services for users, tenants, telemetry, forms, reviews, mobile auth, and Google/Kong auth.
backend/src/services - Persistence · Yugabyte/pg session and relational storage plus Cassandra-compatible form/review data.
backend/src/databases - Upstream Proxy · Proxy layer for Kong, Knowlg middleware, user services, and content/plugin paths.
backend/src/proxies - Env Config · Typed deployment and runtime configuration for the backend.
backend/src/config/env.ts
External Systems
Identity providers, databases, and Sunbird upstream services.
- Keycloak · OIDC auth provider for browser and mobile login flows.
- Google OAuth · Google sign-in provider used by browser and mobile authentication.
- YugabyteDB · Primary relational and session-backed storage.
- Cassandra API · Cassandra-compatible persistence used for forms and review comments.
- Sunbird Services · External platform services reached through backend proxies.
Connections 23
- Browser App → Routes: loads · Bootstraps the SPA and resolves routes.
- Routes → Pages: renders · Routes compose page-level screens.
- Pages → Shared UI: uses · Pages compose shared UI and layout primitives.
- Pages → Feature Hooks: orchestrates · Pages rely on hooks for feature state and data loading.
- Feature Hooks → API Layer: calls · Hooks delegate network work to the central API layer.
- Pages → Auth & RBAC: guards · Protected and onboarding flows enforce access control.
- Pages → Content System: embeds · Content, workspace, and collection pages embed players and editors.
- Content System → Shared UI: composes · Players and editors depend on shared UI components.
- Content System → Telemetry UI: reports · Player/editor interactions feed telemetry context.
- Pages → Locale Layer: localizes · Pages and components render through locale and direction state.
- Browser App → Express API: api calls · Client requests target the backend for auth and data.
- Express API → Domain Routes: dispatches · Express requests enter domain route modules.
- Domain Routes → Middleware & Controllers: passes through · Routes are protected and shaped by middleware and controllers.
- Middleware & Controllers → Backend Services: invokes · Controllers call domain services after middleware processing.
- Backend Services → Persistence: reads/writes · Services persist and query application state.
- Express API → Upstream Proxy: forwards · Selected routes are reverse-proxied to upstream platform services.
- Express API → Env Config: configures · Typed environment settings define runtime behavior.
- Middleware & Controllers → Keycloak: authenticates · OIDC and session-based browser auth integrates with Keycloak.
- Middleware & Controllers → Google OAuth: oauth · Google sign-in and related flows use Google OAuth.
- Persistence → YugabyteDB: relational · General data and session storage use Yugabyte-backed Postgres.
- Persistence → Cassandra API: wide-column · Forms and review comments use Cassandra-compatible access.
- Upstream Proxy → Sunbird Services: routes to · Backend proxies fan out to Sunbird platform services.
- API Layer → Express API: requests · Frontend service modules communicate with backend endpoints.