RABS Coding Standards & Project Structure
This document defines the code conventions, folder structure, and project-wide standards for all source code in the RABS system. It is designed for both human developers and intelligent agents (like Reggie) to ensure consistency, clarity, and long-term maintainability.
๐ง Purposeโ
- Establish coding style consistency across the entire codebase.
- Help AI agents generate and edit code that aligns with human standards.
- Document the folder structure so tools and contributors know where things go.
- Reduce ambiguity in cross-platform development (web, iOS, tvOS, backend).
๐ General Folder Structureโ
The RABS project is modular and supports multi-platform development.
/rabs
โโโ backend/ # Express API and service logic
โโโ middleware/ # Shared server-side logic across endpoints
โโโ frontend-vite/ # React web interface using Vite
โโโ frontend-next/ # Next.js experimental frontend
โโโ swift-ios/ # Native iOS app
โโโ swift-tvos/ # Native Apple TV companion app
โโโ swift-watchos/ # Native Apple Watch interface
โโโ shared/ # Universal logic, constants, and rules
โโโ scripts/ # Automation scripts and CLI utilities
โโโ docs/ # Central documentation hub
โโโ data/ # Static datasets / mock data
โโโ tests/ # Universal test suite and CI entry-point
โโโ README.md # Global project overview
๐งฑ General Coding Styleโ
JavaScript / Node.jsโ
| Rule | Standard |
|---|---|
| Indentation | 2 spaces |
| Variable Declaration | const / let (never var) |
| Functions | Prefer arrow functions () => {} |
| Semicolons | Always required ; |
| Imports | Group: 1) built-in 2) external 3) internal |
| File Extensions | .js, .mjs, .cjs as appropriate |
Swift (iOS / watchOS / tvOS)โ
| Rule | Standard |
|---|---|
| Indentation | 4 spaces (Apple default) |
| Naming | camelCase for vars/functions, PascalCase for types/structs |
| SwiftUI | Use explicit property wrappers (@State, @Binding, etc.) |
| Separation | Keep UI and business logic in separate files |
JSON / YAML / Configโ
- Indentation: 2 spaces
- Keys: lowercase or kebab-case (
my-key) - Environment-specific values belong in
.env.*files, never hard-coded.
Language-Agnostic Best Practices (from codeRULES.md)โ
-
Naming
- Functions are verbs (
allocateTransportJob), classes are nouns (VehicleAllocator). - Avoid abbreviations unless industry-standard (e.g.,
NDIS).
- Functions are verbs (
-
Error Handling
- Never swallow errors. Use structured error objects with
code,message,details. - Log at the edge of the system (
middleware/errorHandler.js), return meaningful HTTP codes.
- Never swallow errors. Use structured error objects with
-
Configuration & Secrets
- All secrets in Vault or
.env.local; never commit plaintext. - Use 12-Factor
CONFIG_environment variables for runtime behaviour.
- All secrets in Vault or
-
Security
- Lint for common vulnerabilities (
npm audit,swiftlint,bandit). - Sanitize all user input; validate against shared schema definitions.
- Lint for common vulnerabilities (
-
Testing & CI
- Minimum 80 % branch coverage; PRs failing coverage threshold cannot merge.
- Fast unit tests live in
/tests/unit, slower integration tests in/tests/int. - GitHub Actions workflow runs lint โ test โ build โ deploy-preview.
-
Git Workflow
- Conventional Commit messages (
feat:,fix:,docs:โฆ). - Feature branches follow
username/feature-slug. - PR must reference an issue and include a checklist: tests, docs, migration notes.
- Conventional Commit messages (
๐ฌ Code Commenting Guidelinesโ
File-Level Commentsโ
Each file begins with a block describing its purpose. For files sanitized for public view, prepend // {K} to any comment you want preserved.
// File: userRouter.js
// Description: Express routes for managing user profiles and auth
// {K} Routes are grouped by feature folder for maintainability
const express = require('express');
const router = express.Router();
Function-Level Comments & RABS Tagsโ
Tags give cognitive and operational context to Reggie and developers.
// ========= [v1 API] /transport/allocate =========
// @methods: POST
// @route: /api/v1/transport/allocate
// @description:
// Assigns staff and vehicle to a booking, considering preferences & anomalies.
// @memory: internalmonologue
// @context: cb_transport
// @selfwrite: true
// @mindmap-ref: transport_context_bucket, transport_bookings
// @model: gpt-4o
// @form-source: /roster/dispatch
// ===============================================
function allocateTransportJob(req, res) {
// ...
}
Tag Glossaryโ
| Tag | Purpose |
|---|---|
@memory | Memory store consulted before decision (e.g., internalmonologue). |
@context | Specific context bucket providing lessons learned (e.g., cb_transport). |
@selfwrite | Whether the agent writes a private reflection after execution. |
@mindmap-ref | Named data paths in the mindmap this logic depends on. |
@model | LLM used in the decision pipeline (e.g., gpt-4o). |
@form-source | UI or API endpoint that originated the request. |
โ AI Agent Coding Behavioursโ
When an AI code assistant (Reggie, Copilot, etc.) generates or edits code it must:
- Use the correct file extension and language syntax highlighting.
- Place new files in the appropriate folder according to the structure above.
- Include a header comment:
// generated by Reggie :: purpose: <describe task> - Avoid hard-coding values that should be config-driven.
- Reference supporting data files using relative paths.
- Run
npm test/swift testlocally (or CI) before committing.
๐ Additional Docsโ
- Documentation Style Guide
- Project Charter & Vision
- Extended Code Rules