rivheal-docs

RivHeal Design Principles & Coding Standards

Last updated: 2026-05-30

These principles are extracted from the codebase and represent the patterns that must be followed for consistency and correctness.


1. API Design

RESTful + Versioned

Public vs Protected

@Public()          // No auth — guests and external consumers
@UseGuards(JwtAuthGuard)  // JWT required
@Roles(SYSTEM_ROLES.DOCTOR)  // JWT + role check

Every new endpoint must explicitly choose one of these patterns. Default is protected.

Multi-tenant Context

DTOs and Validation

Swagger


2. Database

Entity Conventions

Repository Pattern

Migrations

Soft Deletes


3. Security

Authentication Flow

  1. Patient/staff registers or logs in → API issues JWT (access + refresh tokens).
  2. Keycloak SSO tokens are also accepted — dual-lookup JWT strategy.
  3. JWT secret lives in JWT_SECRET env var. Refresh secret in JWT_REFRESH_SECRET.
  4. Access token TTL: configurable via JWT_EXPIRES_IN. Refresh: JWT_REFRESH_EXPIRES_IN.

Password Storage

Input Sanitisation

Data Privacy (NDPR)

Network Security


4. Mobile App

Offline-First

Guest Sessions

Push Notifications

Real-time


5. AI/ML Principles

Graceful Degradation

Feature Flag Gating

No PII to External Models

Model Lifecycle


6. Code Style

TypeScript

Naming

Comments