Skip to main content

Architecture

Introduction

This document describes the Ravenxcope frontend architecture, the dependency direction between layers, the runtime initialization flow, and important design decisions that shape the codebase.


Architecture Pattern

The frontend follows a practical feature-oriented React architecture. The route tree and navigation metadata are centralized in src/app/routes.tsx, global layout lives in src/core/layout, reusable route/page scaffolding lives in src/core/page, data access is centralized in src/lib/api.ts, and feature screens live under src/modules.

Entry Pointmain.tsxApp CoreApp.tsx & RoutesApp ShellLayout & NavigationFeature ViewsModules & ScreensData & RuntimeAPI, Auth, Hooks

Layer Responsibilities

LayerMain Files / FoldersResponsibility
Entrysrc/main.tsxMount React, import global CSS, initialize i18n
Routingsrc/app/App.tsx, src/app/routes.tsx, src/app/PrivateRoutes.tsxDefine public/private routes, dashboard route metadata, navigation items, and route guard
Layoutsrc/core/layout/App shell, sidebar, header, user dropdown, language switcher, mobile drawer, footer/content frame
Page Scaffoldsrc/core/page/Route page wrapper, page header/toolbar, table cards, empty/loading states, transitions
Feature UIsrc/modules/{sensors,users,roles,organizations,analytics}Route-level pages, feature-specific partials, dialogs, and domain sub-flows
Shared UIsrc/components/ui/Button, card, dialog, table, select, sheet, tooltip, and other primitives
Data Hookssrc/hooks/useApi.tsSmall data-fetching hooks for common resource reads
API Clientsrc/lib/api.tsAxios instance, interceptors, endpoint groups, query serialization
Authsrc/lib/auth.tsCookie session helpers and permission helpers
Configsrc/config/appConfig.tsRuntime config parsing, validation, and freezing
Typessrc/types/index.tsAPI payload, entity, filter, analytics, and component types
Localizationsrc/i18n.ts, src/locales/i18next setup and message catalogs

Dependency Direction

Session GuardFeature ComponentsData Hooks (useApi)API Client (lib/api)Auth (lib/auth)Backend HTTP APIModules & Partial Views

Current dependency rules:

  • Feature components call the centralized api object rather than creating ad-hoc Axios clients.
  • apiClient attaches bearer tokens through auth.getToken().
  • appConfig is the only source of sanitized runtime configuration.
  • Shared UI primitives do not call backend APIs.
  • Types are centralized in src/types/index.ts, not colocated per feature.

Runtime Initialization

The browser boot sequence is:

  1. Bundle Loading: index.html loads the built script bundle and config.js.
  2. Setup Initialization: src/main.tsx imports src/i18n.ts, src/index.css, and App.
  3. Localization: src/i18n.ts loads English and Indonesian resources, selects language, and persists changes.
  4. App Mounting: App mounts global providers, router, and core layout components.
  5. Auth Guard: Private dashboard routes call auth.isAuthenticated() before rendering.
  6. Shell Hydration: The dashboard app shell fetches current user data and renders navigation.
  7. Feature Loading: Feature views fetch backend data through api or custom hooks.

Important Design Decisions

  1. Single centralized API object - src/lib/api.ts groups all backend calls by domain.
  2. Cookie-based session storage - Access token, user ID, and organization ID are stored through js-cookie.
  3. Runtime config over rebuilds - window.__APP_CONFIG__ allows configuration changes without rebuilding.
  4. Manual async hooks instead of React Query - The app uses useState and useEffect for data fetching.
  5. Route-level dashboard shell - /dashboard renders AppShell with a nested Outlet.
  6. Feature flags - Analytics chat UI checks both frontend flags and backend status.
  7. Flexible response handling - Components tolerate multiple response shapes during contract stabilization.

Known Architecture Debt

AreaIssueImpact
App shell compositionAppShell.tsx centralizes standard vs workspace layoutKeep as only global layout boundary
Route-level page organizationRoute pages live under modules/*/pagesContinue keeping orchestration in pages
Large feature viewsAnalytics views have substantial data orchestrationFocus on domain hooks for further extraction
Reusable page chromeRoutePage and DataTableCard are standard scaffoldsUse for new management pages
Layout consistencyList pages use shared table scaffoldsKeep future CRUD pages aligned
Route constantsROUTES and dashboardRoutes cover navigationCentralize paths in src/lib/constants.ts
State/data fetchingServer state managed manuallyDuplicated loading/error logic
API surfaceAll endpoints in one large api.tsHigh-churn file
Type organizationAll domain types in one types/index.tsHarder to navigate
Response contractsMultiple response shapes supportedPotential for contract drift
TestsNo dedicated frontend test suiteRegression risk for core flows