How cantodelobo/open-foundry works
Purpose and Entry Points
Open Foundry is a schema-driven, storage-agnostic ontology runtime for operational digital twins. It exposes generated GraphQL, REST, FHIR R4, CDM projection, subscription, and specification endpoints through the API gateway. Main service boots are packages/api/src/server.ts, packages/engine/src/server.ts, packages/actions/src/server.ts, packages/security/src/server.ts, and packages/sync/src/server.ts; CEL evaluation is a Go gRPC sidecar at packages/cel-evaluator/main.go.
Domain-Pack Compilation and Boot
Domain packs are the domain boundary: ODL schemas, action manifests, connector definitions, and authorization models are merged at runtime, including optional external pack directories. ODL parses, validates, registers, diffs, and generates API/SDK/OpenFGA artifacts. Packs provide the concrete ontology and can declare idempotent bootstrap seeds.
• packages/odl/src/parser/index.ts
• packages/api/src/schema-loader.ts
• packages/api/src/schema-registry-boot.ts
• domain-packs/nhs-acute/pack.yaml
Ontology and Persistence Core
The engine owns object lifecycle, links, object sets, computed fields, lineage, and domain-event emission. It depends on the SPI rather than a database directly. Production storage maps tenant-scoped objects, graph links/traversal, temporal history, search, schema registry, audit, and consent to PostgreSQL 17 plus Apache AGE; memory storage is the interchangeable development/test implementation.
• packages/spi/src/index.ts
• packages/engine/src/objects/object-manager.ts
• packages/engine/src/links/link-manager.ts
• packages/storage-postgres/src/postgres-storage-provider.ts
Governed Mutation Pipeline
Objects are mutated primarily through YAML-defined actions rather than generic API writes. The action executor sequences validation, authorization, consent, CEL preconditions/effects, transactional execution, post-commit side effects, audit, and event emission; rollback-all compensation restores state on failure. Node calls the isolated CEL gRPC service, avoiding in-process expression execution.
• packages/actions/src/executor/action-executor.ts
• packages/actions/src/cel/client.ts
• packages/actions/src/sideeffects/side-effect-executor.ts
• packages/cel-evaluator/evaluator/evaluator.go
API and Query Boundary
The API package is the external request boundary and generated-query layer. It builds GraphQL resolvers and REST routes from the merged ontology, offers read-only FHIR/CDM projections, and manages WebSocket subscriptions/spec outputs. Governance applies query-complexity limits, rate limiting, and execution guards before underlying engine access.
• packages/api/src/server.ts
• packages/api/src/graphql/resolver-generator.ts
• packages/api/src/rest/route-generator.ts
• packages/api/src/governance/execution-guard.ts
Security and Eventing Boundary
OIDC authentication, OpenFGA relationship-based authorization, field-level redaction, consent checks, and immutable mutation audit form the mandatory security layer between callers and data/action execution. Events feed subscriptions and asynchronous consumers; Redpanda/Kafka and Redis are production-capable implementations with in-memory fallbacks.
• packages/security/src/auth/oidc-authenticator.ts
• packages/security/src/authz/authorization-service.ts
• packages/security/src/consent/consent-service.ts
• packages/api/src/events/redpanda-event-bus.ts
Ingestion, Operations, and Deployment
The sync service imports external JDBC/REST systems, consumes CDC, maps records to ontology objects, resolves identity/conflicts, and supports overlays. Local Compose provisions PostgreSQL+AGE, Redpanda, Redis, Debezium, Keycloak, OpenFGA, and OpenTelemetry Collector; Helm deploys the API, engine, action, security, sync, and CEL services with network/security/availability controls.
• packages/sync/src/server.ts
• packages/sync/src/cdc/cdc-consumer.ts
• packages/sync/src/mapping/record-mapper.ts
• deploy/helm/openfoundry/values.yaml
Main entry points: object-manager.ts Ontology engine · server.ts API gateway · action-executor.ts Action executor · values.yaml Helm deployment
Components 18
Domain compilation
- Domain packs · Provide ontology, actions, connectors, authorization models, and bootstrap seeds.
domain-packs/nhs-acute/pack.yaml - ODL compiler · Parses, validates, registers, diffs, and generates ontology artifacts.
packages/odl/src/parser/index.ts - Schema registry boot · Merges built-in and optional external packs at startup.
packages/api/src/schema-registry-boot.ts
Service runtime
- API gateway · External GraphQL, REST, FHIR, CDM, subscription, and specification boundary.
packages/api/src/server.ts - Generated query surface · Builds ontology-derived GraphQL and REST reads.
packages/api/src/graphql/resolver-generator.ts - Query governance · Applies complexity, rate, and execution limits.
packages/api/src/governance/execution-guard.ts - Security service · Mandatory OIDC, OpenFGA, redaction, consent, and audit layer.
packages/security/src/authz/authorization-service.ts - Action executor · Runs validation, policy, transaction, compensation, audit, and events.
packages/actions/src/executor/action-executor.ts - CEL evaluator · Isolated evaluation of action preconditions and effects.
packages/cel-evaluator/evaluator/evaluator.go - Ontology engine · Owns objects, links, sets, computed fields, lineage, and domain events.
packages/engine/src/objects/object-manager.ts
Data and events
- Storage SPI · Decouples engine capabilities from storage implementations.
packages/spi/src/index.ts - PostgreSQL + Apache AGE · Tenant objects, graph traversal, history, search, registry, audit, and consent.
packages/storage-postgres/src/postgres-storage-provider.ts - Event bus · Feeds subscriptions and asynchronous consumers with memory fallback.
packages/api/src/events/redpanda-event-bus.ts
Ingestion and operations
- Sync service · Imports JDBC/REST and CDC sources into ontology objects.
packages/sync/src/server.ts - CDC and record mapping · Maps records and resolves identity, conflicts, and overlays.
packages/sync/src/cdc/cdc-consumer.ts - External source systems
- Helm deployment · Deploys services with network, security, and availability controls.
deploy/helm/openfoundry/values.yaml
Other components
- Clients and integrations · Use generated APIs and subscriptions.
Connections 25
- Clients and integrations → API gateway: requests and subscriptions
- API gateway → Query governance: guards queries
- Query governance → Generated query surface: permits execution
- Generated query surface → Ontology engine: reads ontology
- API gateway → Security service: authenticates and authorizes
- API gateway → Action executor: submits mutations
- Domain packs → ODL compiler: schemas and manifests
- ODL compiler → Schema registry boot: compiled artifacts
- Schema registry boot → Generated query surface: merged ontology
- Schema registry boot → Ontology engine: registered schema
- Schema registry boot → Action executor: action definitions
- Action executor → Security service: policy and consent checks
- Action executor → CEL evaluator: gRPC evaluation
- Action executor → Ontology engine: transactional mutations
- Ontology engine → Storage SPI: storage operations
- Storage SPI → PostgreSQL + Apache AGE: production implementation
- Ontology engine → Event bus: domain events
- Event bus → API gateway: subscription delivery
- External source systems → Sync service: imports and CDC
- Sync service → CDC and record mapping: consumes and maps
- CDC and record mapping → Ontology engine: resolved ontology writes
- Helm deployment → API gateway: deploys
- Helm deployment → Ontology engine: deploys
- Helm deployment → Action executor: deploys
- Helm deployment → Sync service: deploys