Contributing to ClinicFlow
Contributing to ClinicFlow
Section titled “Contributing to ClinicFlow”Prerequisites
Section titled “Prerequisites”- Node.js 22+
- npm
- A Supabase project (or access to the shared dev project)
- Redis (local via Docker, Railway plugin, or hosted provider)
See Local Development for setup instructions.
Branch Strategy
Section titled “Branch Strategy”| Branch | Purpose | Base |
|---|---|---|
main |
Production. Auto-deploys to Railway. Never commit directly. | — |
dev |
Optional staging for pre-prod validation before merge. | main |
feat/<name> |
New features. PR into main. |
main |
fix/<name> |
Bug fixes. PR into main. |
main |
chore/<name> |
Maintenance, no behaviour change. PR into main. |
main |
docs/<name> |
Documentation-only changes. PR into main. |
main |
Rules:
- Branch from
main, notdev. - Delete branch after PR merges.
- Annotated tags mark releases:
git tag -a vX.Y.Z -m "..."thengit push origin vX.Y.Z.
Commit Convention
Section titled “Commit Convention”Conventional Commits format:
feat(chatbot): add FAQ keyword matching fallbackfix(auth): handle expired JWT on /me endpointchore(deps): bump @anthropic-ai/sdk to 0.101.0docs(api): document PATCH /users/me endpointtest(whatsapp): add concurrency lock test casesSubject line: max 72 chars, imperative mood, no period.
Body (optional): explain why, not what.
Before Opening a PR
Section titled “Before Opening a PR”- Tests pass:
cd backend && npm test(458 tests, ~22s) - TypeScript valid:
cd backend && npm run typecheck+cd frontend && npm run typecheck - Lint clean:
cd frontend && npm run lint→ 0 errors - No
console.logleft in production code (uselogger.*fromsrc/utils/logger.js) - No secrets or credentials in committed files
PR Description Template
Section titled “PR Description Template”## WhatOne-sentence summary of the change.
## WhyWhy this change is needed.
## Test plan- [ ] Manual step 1- [ ] Manual step 2Review SLA: 2 business days. Tag @ErnestNuma for urgent reviews.
Code Style
Section titled “Code Style”Backend
Section titled “Backend”- Runtime: Node.js 22+, ES modules (
import/export). Runs.tsfiles via Node native type-stripping (Node ≥22.18). - TypeScript: Incremental migration in progress (
allowJsduring transition). New files should use.tswhen touching migrated areas;.jsis still accepted. - Type-check: Always run
tsc --noEmit(bothbackendandfrontend). - Error handling:
try/catchin route handlers, always return JSON{ error: "..." }. - Logging: Use
logger.info/error/warnfromsrc/utils/logger.js— neverconsole.log. - Multi-tenancy: Every DB query must filter by
req.user.clinicId— no exceptions. - Secrets: Never log, never return in responses. Mask tokens with
...****.
Frontend
Section titled “Frontend”- Styling: Tailwind CSS is preferred for new components. Brand green
#059669is thebrandtoken intailwind.config.js. Inline styles being migrated; match existing patterns when touching legacy code. - Fonts:
DM Sansfor body,Bricolage Grotesquefor headings/display. - Icons:
lucide-react— don’t add other icon libraries. - State: TanStack Query for server state,
useState/useContextfor UI state. - No new dependencies without discussion — keep the bundle lean.
- Match surrounding code style even if you’d do it differently.
- Don’t “improve” adjacent code that isn’t broken — surgical changes only.
- Remove imports/variables made unused by your changes.
Testing
Section titled “Testing”Backend (Vitest)
Section titled “Backend (Vitest)”cd backendnpm test # run once (458 tests)npm run test:watch # watch modenpm run test:cover # with coverageTest files live in src/__tests__/. New backend features should have tests. Match the existing pattern in __tests__/helpers/testDb.js for DB setup.
Frontend (Vitest)
Section titled “Frontend (Vitest)”cd frontendnpm testDatabase Changes
Section titled “Database Changes”Schema changes go through Supabase migrations:
- Edit
backend/src/db/schema.sql - Apply locally:
npm run migrate - Document the change in Database Schema
Environment Variables
Section titled “Environment Variables”Never hardcode values that belong in environment variables. Add new vars to:
backend/.env.example(with placeholder value)frontend/.env.example(VITE_-prefixed)- Environment Variables doc
Questions?
Section titled “Questions?”Open a GitHub issue or reach out at ernest@clinicflow.lat.