Skip to main content

Platform Runbook

This runbook provides frequently used commands for operating the CTMS platform. Commands are organized by component with both native commands and Make-based shortcuts.

Environment Selection

Most commands support environment selection. Add ENV=production to use production configuration:

make <command> ENV=production

Quick Reference

TaskComponentCommand
Start web appWebmake dev or bun run dev
Deploy web appWebmake deploy-prod
Run data ingestionIngestermake batch
Build DBT modelsDBTmake build
Clear analytics cacheCubemake cache-bust
Check healthCubemake health

1. Web Application (hb-life-science-web)

The Next.js application serving the CTMS user interface.

Core Commands

TaskMake CommandNative Command
Install dependenciesmake setupbun install
View configurationmake status
Start development servermake devbun run dev
Build for productionmake buildbun run build
Start production servermake startbun run start
Lint codemake lintbun run lint

Vercel Deployment

TaskMake CommandNative Command
Link to Vercel projectmake vercel-linkvercel link
Deploy previewmake deployvercel
Deploy productionmake deploy-prodvercel --prod
Pull env variablesmake vercel-env-pullvercel env pull .env.local
Add env variablemake vercel-env-add KEY=name VALUE=valuevercel env add
View logsmake vercel-logsvercel logs

Optional Commands

TaskCommand
Generate entity APIsbun run generate:apis
Generate OpenAPI specbun run openapi:generate
Validate OpenAPI specbun run openapi:validate
Export Postman collectionbun run openapi:postman
Clean build artifactsmake clean

2. Data Ingester (ctms-ingester-dlthub)

DLT Hub pipeline that extracts data from Frappe API and loads into PostgreSQL.

Core Commands

TaskMake CommandNative Command
Install dependenciesmake setuppip3 install -r requirements.txt
View configurationmake status
Run all endpointsmake batchpython3 bot_frappe_api_to_db.py
Run production batchmake batch ENV=production

Optional Commands

TaskMake CommandNative Command
Run single endpointmake run ENDPOINT='/doctype/Patient'
Run Patient endpointmake run-patient
Run Study endpointmake run-study
Purge database schemasmake purgepython3 db_schema_purge.py

3. DBT Pipeline (ctms-lakehouse-dbt)

DBT project that transforms raw data through Bronze → Silver → Gold layers.

Core Commands

TaskMake CommandNative Command
Install dependenciesmake setuppip install -r requirements-dbt.txt
Install DBT packagesmake depsdbt deps
Verify connectionmake debugdbt debug
View configurationmake status
Build all modelsmake builddbt build
Run daily pipelinemake daily

Build Commands

TaskMake CommandNative Command
Load seed datamake seeddbt seed
Run models onlymake rundbt run
Run tests onlymake testdbt test
Generate docsmake docsdbt docs generate

Data Quality (Elementary)

TaskMake CommandNative Command
Build Elementary tablesmake elementarydbt run --select elementary
Generate HTML reportmake reportedr report
View report in browsermake view-reportopen edr_target/report.html

Cleanup

TaskMake CommandNative Command
Clean compiled filesmake cleanrm -rf target/

4. Semantic Cube (ctms-semantic-cube)

Cube.dev semantic layer providing analytics API.

Core Commands

TaskMake CommandNative Command
Install dependenciesmake setupnpm install
View configurationmake status
Start dev servermake devnpm run dev
View logsmake logstail -f logs/*.log

Cache Management

TaskMake CommandNative Command
Clear production cachemake cache-bustflyctl apps restart ctms-semantic-cube
Clear local cachemake cache-bust-localrm -rf .cubestore

Production Deployment

TaskMake CommandNative Command
Deploy to Fly.iomake deployflyctl deploy
Restart productionmake restartflyctl apps restart ctms-semantic-cube

Validation

TaskMake CommandNative Command
Check server healthmake healthcurl https://ctms-semantic-cube.fly.dev/readyz
Get schema metadatamake metacurl .../cubejs-api/v1/meta
Validate cube filesmake validate

Common Workflows

Daily Data Refresh (Production)

Run these commands in sequence to refresh all data:

# 1. Extract data from Frappe API
cd ctms-ingester-dlthub
make batch ENV=production

# 2. Transform data through DBT layers
cd ../ctms-lakehouse-dbt
make daily ENV=production

# 3. Clear analytics cache
cd ../ctms-semantic-cube
make cache-bust

Initial Setup (New Environment)

# 1. Setup Ingester
cd ctms-ingester-dlthub
make setup
make status

# 2. Setup DBT
cd ../ctms-lakehouse-dbt
make setup
make deps
make debug

# 3. Setup Cube
cd ../ctms-semantic-cube
make setup
make status

# 4. Start Web App
cd ../hb-life-science-web
bun install
bun run dev

Troubleshooting Data Issues

# Check ingester status
cd ctms-ingester-dlthub
make status

# Verify DBT connection
cd ../ctms-lakehouse-dbt
make debug

# Check Cube health
cd ../ctms-semantic-cube
make health ENV=production

# View Cube logs
make logs

Environment Files

Each component uses environment files for configuration:

ComponentDevelopmentProduction
Ingester.env.env.production
DBT.env.env.production
Cube.env.env.production
Web App.env.localEnvironment variables

Useful Fly.io Commands

For components deployed on Fly.io (Semantic Cube):

TaskCommand
View app statusflyctl status
View logsflyctl logs
SSH into containerflyctl ssh console
List secretsflyctl secrets list
Set secretflyctl secrets set KEY=value

Useful Vercel Commands

For components deployed on Vercel (CTMS Web App):

TaskCommand
Link projectvercel link
Deploy previewvercel
Deploy productionvercel --prod
List deploymentsvercel list
View logsvercel logs
Pull env variablesvercel env pull
Add env variablevercel env add VAR_NAME
Remove env variablevercel env rm VAR_NAME
List env variablesvercel env ls

First-Time Vercel Setup

# 1. Install Vercel CLI
npm install -g vercel

# 2. Login to Vercel
vercel login

# 3. Link your project
cd hb-life-science-web
make vercel-link

# 4. Set environment variables
make vercel-env-add KEY=NEXT_PUBLIC_SUPABASE_URL VALUE=https://...
make vercel-env-add KEY=NEXT_PUBLIC_SUPABASE_ANON_KEY VALUE=...

# 5. Deploy to production
make deploy-prod

Getting Help

Each component's Makefile includes built-in help:

cd <component-directory>
make help

This displays all available commands with descriptions.