Skip to main content

Shared Code Strategy (/shared Folder)

The /shared directory at the root of the RABS project acts as a universal logic layer, accessible from all frontend and backend processes.


1. Why Use a Shared Folder?

  • Centralises logic – Validation, role mapping, environment configuration, and business rules live in one place.
  • Reduces duplication – Write a rule once; consume it everywhere.
  • Ensures consistency – Guarantees identical behaviour across all platforms.
  • Enables native export – A planned build script will convert shared JS modules into JSON for native iOS/tvOS apps.

rabs/
├── shared/
│ ├── utils/ # Generic helpers (formatDate, string utils)
│ ├── constants/ # Roles, labels, enums
│ ├── rules/ # Business logic (e.g. eligibility checks)
│ ├── schemas/ # Optional: shared zod/yup schemas
│ └── config/ # Env settings, API base URLs
├── scripts/
│ └── export-shared.js # (Planned) Converts shared exports to JSON
├── native-assets/ # Output JSON for tvOS/iOS bundles
├── backend/
└── frontend-vite/

3. Usage Across Platforms

JavaScript (Backend / Frontend)

import { ROLES } from '../../shared/constants/roles.js';

Swift / Native Apps

scripts/export-shared.js will convert selected modules (e.g., roles.js) to .json and place them in native-assets/. The JSON files are then bundled into the Xcode project.


4. Key Takeaway

NeedPut it in
Format, math, string helpersshared/utils/
Role lists, enumsshared/constants/
Domain-specific business logicshared/rules/
Validation schemas (zod/yup)shared/schemas/
API base paths, environment configshared/config/

Building logic once and reusing it everywhere keeps RABS maintainable, consistent, and ready for expansion across React, Node.js, and native mobile apps.