Development Guide
Workspace Layout
Section titled “Workspace Layout”crates/octofhir-core: core types (ResourceEnvelope/meta, FhirVersion/DateTime, errors)crates/octofhir-db-postgres: PostgreSQL storage, query filters, transactionscrates/octofhir-search: query parsing/validation, enginecrates/octofhir-api: OperationOutcome, CapabilityStatement, Bundle helperscrates/octofhir-server: HTTP server (Axum), routes, middleware, config, observabilitycrates/octofhir-jsc: JavaScriptCore runtime for bot automationcrates/octofhir-auth: OAuth 2.0 / SMART on FHIR authentication
Prerequisites
Section titled “Prerequisites”On macOS, JavaScriptCore is available as a system framework. No additional dependencies are required.
# Install Rustcurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install just (command runner)brew install justLinux (Ubuntu/Debian)
Section titled “Linux (Ubuntu/Debian)”On Linux, you need to install JavaScriptCore development libraries for bot automation:
# Install Rustcurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install build dependenciessudo apt-get updatesudo apt-get install -y \ build-essential \ pkg-config \ libssl-dev \ libjavascriptcoregtk-4.1-dev
# Install just (command runner)cargo install justLinux (Fedora/RHEL)
Section titled “Linux (Fedora/RHEL)”# Install Rustcurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install build dependenciessudo dnf install -y \ gcc \ pkg-config \ openssl-devel \ webkit2gtk4.1-devel
# Install just (command runner)cargo install justCommon Tasks
Section titled “Common Tasks”just build # cargo buildjust test # cargo test --all --all-featuresjust lint # cargo clippy -- -D warningsjust fmt # cargo fmt --alljust dev # cargo watch -x run (auto-reload on changes)Building from Source
Section titled “Building from Source”Debug Build (Recommended for Development)
Section titled “Debug Build (Recommended for Development)”# Start dependencies (PostgreSQL, Redis)docker compose up -d
# Build and runcargo runRelease Build
Section titled “Release Build”# Build release binary (takes 5-10 minutes)cargo build --release
# Run release binary./target/release/octofhir-serverDocker Build
Section titled “Docker Build”# Build Docker imagedocker build -t octofhir-server .
# Run containerdocker run -p 8888:8888 octofhir-serverBot Automation (JSC)
Section titled “Bot Automation (JSC)”OctoFHIR uses JavaScriptCore for executing JavaScript bots. The JSC runtime provides:
- ES2020+ support: Full modern JavaScript syntax
- Native APIs:
console,http.fetch(),fhir.*CRUD operations - Thread-safe pool: Multiple JSC contexts for concurrent execution
- JIT compilation: Fast execution with JSC’s multi-tier compiler
Platform Support
Section titled “Platform Support”| Platform | JSC Source | Notes |
|---|---|---|
| macOS | System framework | No additional dependencies |
| Linux (Debian/Ubuntu) | libjavascriptcoregtk-4.1-dev | Via apt-get |
| Linux (Fedora/RHEL) | webkit2gtk4.1-devel | Via dnf |
| Docker | Debian bookworm | Included in Dockerfile |
Bot Example
Section titled “Bot Example”// Bot triggered on Patient creationif (event.type === 'created' && event.resource.resourceType === 'Patient') { const patient = event.resource;
// Create a welcome task const task = fhir.create({ resourceType: 'Task', status: 'requested', intent: 'order', description: `Welcome patient: ${patient.name?.[0]?.family}`, for: { reference: `Patient/${patient.id}` } });
console.log('Created task:', task.id); return { taskId: task.id };}Testing
Section titled “Testing”- Unit tests inside crates
- Integration tests in
crates/octofhir-server/testscover HTTP flows - Bot tests:
bun run scripts/test-bots.ts
Contributing
Section titled “Contributing”- Keep PRs small and focused; follow Conventional Commits
- Fix all clippy warnings; run
just lint