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.
2. Recommended Folder Structure
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
| Need | Put it in |
|---|---|
| Format, math, string helpers | shared/utils/ |
| Role lists, enums | shared/constants/ |
| Domain-specific business logic | shared/rules/ |
| Validation schemas (zod/yup) | shared/schemas/ |
| API base paths, environment config | shared/config/ |
Building logic once and reusing it everywhere keeps RABS maintainable, consistent, and ready for expansion across React, Node.js, and native mobile apps.