Development Guide
Introduction
This guide describes how to safely add or modify frontend features in the Ravenxcope frontend.
Before Changing Code
- Identify the route and feature folder involved.
- Check whether the workflow already has an API method in
src/lib/api.ts. - Check whether shared types already exist in
src/types/index.ts. - Check whether the UI action needs permission gating.
- Check whether text should be localized in
src/locales/en.jsonandsrc/locales/id.json. - Check whether the feature needs runtime configuration.
Adding an API Endpoint
- Add or update TypeScript types in
src/types/index.ts. - Add the endpoint method to the relevant group in
src/lib/api.ts. - Use the shared
apiClientunless the endpoint specifically needsfetchstreaming. - Keep the backend path relative to
API_BASE. - Return a typed
Promise<AxiosResponse<ApiResponse<T>>>where possible. - Use
buildRepeatedQueryParams()for array query params that backend expects as repeated keys.
Avoid creating new Axios instances in feature components.
Adding a Route
- Create the route-level component in
src/modules/<domain>/pages. - Put feature-specific sections in
src/modules/<domain>/partials. - Put modal flows in
src/modules/<domain>/dialogs. - Import the page in
src/app/routes.tsx. - Add a public route or nested dashboard route definition.
- If it belongs in the sidebar, set
showInNav,navLabelKey, andiconon the dashboard route. - If other modules need the path, add/update
ROUTESinsrc/lib/constants.ts.
Adding a Feature Screen
Follow existing feature screen patterns:
- Use shared UI primitives from
src/components/ui. - Wrap dashboard route content in
RoutePage. - Use
DataTableCardfor management list/table pages. - Use
Card,Table,Dialog,Badge,Skeleton, andButtonconsistently. - Keep create/edit forms in dialogs when matching user, role, and sensor flows.
- Use local state flags to trigger refetches when following current hooks.
- Show user feedback through existing alert/toast helpers.
Adding Data Fetching
For common resource reads, add or extend hooks in src/hooks/useApi.ts.
Current hook conventions:
- Use
useStatefordata,loading, anderror. - Use
useEffectfor request lifecycle. - Check
auth.isAuthenticated()when data is private. - Use
AbortControllerto avoid setting state after unmount. - Return empty fallback arrays for list-style hooks.
- Expose
refetchonly where callers need it.
For feature-specific one-off requests, calling api directly inside the component is acceptable when it matches surrounding code.
Adding Permission-Gated Actions
- Add the permission slug to
PERMISSIONSinsrc/lib/constants.tsif it does not already exist. - Use
useUserPermissions()in the screen. - Hide the action when
hasPermission(slug)is false. - Keep destructive actions behind confirmation.
- Do not rely on frontend checks for security; backend authorization must still enforce the rule.
Adding Forms
Current forms use controlled state and manual submit handlers.
Recommended pattern:
- Initialize form state with all required fields.
- Load select options in
useEffectwhen needed. - Validate simple required/cross-field rules before calling the API.
- Disable form controls while submitting.
- Convert UI field names to backend payload names in one place.
- Use
showSuccess,showError, ortoastfor feedback. - Close the dialog or navigate only after a successful response.
Adding Localized Text
- Add English keys to
src/locales/en.json. - Add Indonesian keys to
src/locales/id.json. - Use
const { t } = useTranslation()in the component. - Avoid introducing new hard-coded user-facing strings in screens that already use i18n.
If a screen is currently hard-coded, localize touched text when reasonable, but avoid broad unrelated rewrites.
Updating Runtime Configuration
When adding a new runtime flag:
- Extend
AppRuntimeConfigandAppConfiginsrc/config/appConfig.ts. - Parse and validate the value in
getRuntimeConfig(). - Add it to
.env.example. - Add it to
docker-entrypoint.sh. - Document it in the Configuration and Deployment Runbook.
- Ensure invalid values fail closed or fall back safely.
Manual Verification Checklist
For UI changes:
- Run TypeScript/build if behavior changed:
yarn build
- Run lint if code changed:
yarn lint
- Test login and
/dashboardroute protection. - Test the changed route directly and after browser refresh.
- Test success and failure paths for API mutations.
- Test permission-hidden states when relevant.
- Test mobile layout for sidebar, tables, dialogs, or sheets.
For documentation-only changes, verify file names and path references. A frontend build is not required.
Documentation Updates
Update the documentation when:
- A route is added, removed, or renamed.
- A runtime config key changes.
- API endpoint groups or payload contracts change.
- Auth/session behavior changes.
- Feature behavior changes in sensors, analytics, users, roles, or organizations.
- Deployment behavior changes in Docker, Nginx, or config injection.