Skip to main content

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โ€‹

RuleStandard
Indentation2 spaces
Variable Declarationconst / let (never var)
FunctionsPrefer arrow functions () => {}
SemicolonsAlways required ;
ImportsGroup: 1) built-in 2) external 3) internal
File Extensions.js, .mjs, .cjs as appropriate

Swift (iOS / watchOS / tvOS)โ€‹

RuleStandard
Indentation4 spaces (Apple default)
NamingcamelCase for vars/functions, PascalCase for types/structs
SwiftUIUse explicit property wrappers (@State, @Binding, etc.)
SeparationKeep 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)โ€‹

  1. Naming

    • Functions are verbs (allocateTransportJob), classes are nouns (VehicleAllocator).
    • Avoid abbreviations unless industry-standard (e.g., NDIS).
  2. 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.
  3. Configuration & Secrets

    • All secrets in Vault or .env.local; never commit plaintext.
    • Use 12-Factor CONFIG_ environment variables for runtime behaviour.
  4. Security

    • Lint for common vulnerabilities (npm audit, swiftlint, bandit).
    • Sanitize all user input; validate against shared schema definitions.
  5. 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.
  6. 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.

๐Ÿ’ฌ 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โ€‹

TagPurpose
@memoryMemory store consulted before decision (e.g., internalmonologue).
@contextSpecific context bucket providing lessons learned (e.g., cb_transport).
@selfwriteWhether the agent writes a private reflection after execution.
@mindmap-refNamed data paths in the mindmap this logic depends on.
@modelLLM used in the decision pipeline (e.g., gpt-4o).
@form-sourceUI 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:

  1. Use the correct file extension and language syntax highlighting.
  2. Place new files in the appropriate folder according to the structure above.
  3. Include a header comment:
    // generated by Reggie :: purpose: <describe task>
  4. Avoid hard-coding values that should be config-driven.
  5. Reference supporting data files using relative paths.
  6. Run npm test / swift test locally (or CI) before committing.

๐Ÿ”— Additional Docsโ€‹