examples/

directory
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2026 License: Apache-2.0

README

Examples

Runnable example applications for different ways to use HAIStack.

For narrative guides and the full package index, see the documentation hub and composition patterns.

Each example is a small standalone main package that can be run from the repository root with go run.

Available examples

manual-sqlite

Direct package composition with:

  • pkg/sqlite
  • pkg/registry
  • pkg/fhirpath
  • pkg/search
  • pkg/core

Creates a local SQLite-backed stack, writes a couple of Patient resources, runs a FHIR search, and prints the results.

go run ./examples/manual-sqlite
runtime-http

Runtime-managed composition with:

  • pkg/runtime
  • pkg/http

Builds a runtime, starts a managed HTTP server, creates a demo Patient, queries the FHIR REST endpoints over HTTP, prints the responses, and shuts down.

go run ./examples/runtime-http
edge-postgres

Edge/server deployment with:

  • pkg/runtime
  • pkg/postgres
  • managed HTTP
  • embedded search on Postgres

Uses TEST_POSTGRES_DSN when set, otherwise starts a disposable Postgres container through testcontainers.

go run ./examples/edge-postgres
cloud-postgres

Cloud deployment shape with:

  • pkg/runtime
  • pkg/postgres
  • external adapter seams for blob/search/warehouse

This demonstrates the cloud-postgres-plus-external-services runtime mode. Like the edge example, it uses TEST_POSTGRES_DSN or a disposable Postgres container.

go run ./examples/cloud-postgres
sync-two-nodes

Offline-first replication with:

  • two local SQLite nodes
  • pkg/sync
  • an in-process example hub

Writes a resource on node A, pushes to the hub, pulls to node B, and verifies the resource is available on node B.

go run ./examples/sync-two-nodes
smart-authz

SMART 2.2 scope enforcement and authorization policy demo:

  • pkg/smart scope CRUDS + filter enforcement
  • pkg/http bearer + policy checker wiring
  • patient compartment vs unrestricted principals
go run ./examples/smart-authz
smart-oauth

Production-shaped SMART OAuth + FHIR demo:

  • oauthstore.ApplySQLiteStores + oauth.NewServer (JSON payload tables)
  • HTML consent with CSRF, EHR launch resolver, and end-user identity
  • PKCE auth-code flow and FHIR read via issued bearer token

For zero-config local serving with the same stack, use haistack serve (see cmd/haistack/README.md).

go run ./examples/smart-oauth
ai-harness

Agent harness on top of governed AI tools:

  • pkg/ai Harness.Chat with scripted ChatModel (no external LLM)
  • sessions, propose_write_plan, host CommitWritePlan, blocked direct writes
go run ./examples/ai-harness
ai-harness-chat-approval

Policy-gated Chat write: turn ends with PendingApprovals; host approves token and resumes via ExecuteHarnessTool (direct write tools enabled).

go run ./examples/ai-harness-chat-approval
ai-harness-host-approval

Policy-gated host commit: CommitWritePlan returns approval-required; host retries with CommitWriteOptions.ApprovalToken.

go run ./examples/ai-harness-host-approval

Shared wiring lives in examples/internal/aiharnessdemo. See pkg/ai/HARNESS.md for the full harness design checklist.

ai-authz

Governed AI access with:

  • pkg/auth
  • pkg/ai
  • pkg/core
  • pkg/search

Builds a local stack, creates demo data, then executes AI read and search tools through an auth-backed policy adapter.

go run ./examples/ai-authz

Notes

  • The examples use temporary SQLite databases and clean them up automatically.
  • The SQLite-only examples do not require Docker or Postgres.
  • The Postgres deployment examples require either Docker or TEST_POSTGRES_DSN.
  • The runtime example loads the local modules/core module from this repository.
  • Research-grade FHIR → AI provenance (stub model, synthetic data) lives in research/ai-pipeline (make research-ai-pipeline).

Directories

Path Synopsis
Command ai-harness demonstrates Harness.Chat, propose_write_plan, and host CommitWritePlan.
Command ai-harness demonstrates Harness.Chat, propose_write_plan, and host CommitWritePlan.
Command ai-harness-chat-approval demonstrates Chat policy approval and ExecuteHarnessTool resume.
Command ai-harness-chat-approval demonstrates Chat policy approval and ExecuteHarnessTool resume.
Command ai-harness-host-approval demonstrates policy approval on host CommitWritePlan.
Command ai-harness-host-approval demonstrates policy approval on host CommitWritePlan.
internal
aiharnessdemo
Package aiharnessdemo shares wiring for pkg/ai harness examples.
Package aiharnessdemo shares wiring for pkg/ai harness examples.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL