# cantodelobo/open-foundry architecture

> Architecture diagram of the GitHub repository cantodelobo/open-foundry, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cantodelobo/open-foundry
- Repository: https://github.com/cantodelobo/open-foundry

## Overview

#### 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: [`packages/engine/src/objects/object-manager.ts`](https://github.com/cantodelobo/open-foundry/blob/main/packages/engine/src/objects/object-manager.ts) (Ontology engine), [`packages/api/src/server.ts`](https://github.com/cantodelobo/open-foundry/blob/main/packages/api/src/server.ts) (API gateway), [`packages/actions/src/executor/action-executor.ts`](https://github.com/cantodelobo/open-foundry/blob/main/packages/actions/src/executor/action-executor.ts) (Action executor), [`deploy/helm/openfoundry/values.yaml`](https://github.com/cantodelobo/open-foundry/blob/main/deploy/helm/openfoundry/values.yaml) (Helm deployment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_domain["Domain compilation"]
  node_packs["Domain packs<br/>ODL schemas and manifests<br/>[pack.yaml]"]
  node_odl["ODL compiler<br/>schema compiler<br/>[index.ts]"]
  node_schema_boot["Schema registry boot<br/>runtime pack loader"]
end

subgraph group_runtime["Service runtime"]
  node_api{{"API gateway<br/>API service<br/>[server.ts]"}}
  node_api_generation["Generated query surface<br/>resolver and route generation"]
  node_query_governance["Query governance<br/>execution guard<br/>[execution-guard.ts]"]
  node_security["Security service<br/>authn, authz, consent"]
  node_actions["Action executor<br/>governed mutation pipeline<br/>[action-executor.ts]"]
  node_cel{{"CEL evaluator<br/>Go gRPC sidecar<br/>[evaluator.go]"}}
  node_engine["Ontology engine<br/>object and graph runtime<br/>[object-manager.ts]"]
end

subgraph group_data["Data and events"]
  node_spi["Storage SPI<br/>storage abstraction<br/>[index.ts]"]
  node_postgres[("PostgreSQL + Apache AGE<br/>production storage provider")]
  node_events["Event bus<br/>Redpanda/Kafka adapter"]
end

subgraph group_ingestion["Ingestion and operations"]
  node_sync["Sync service<br/>external ingestion service<br/>[server.ts]"]
  node_cdc["CDC and record mapping<br/>ingestion pipeline<br/>[cdc-consumer.ts]"]
  node_external_sources(("External source systems<br/>JDBC, REST, CDC sources"))
  node_deployment["Helm deployment<br/>production deployment<br/>[values.yaml]"]
end

node_callers(("Clients and integrations<br/>external callers"))

node_callers -->|"requests and subscriptions"| node_api
node_api -->|"guards queries"| node_query_governance
node_query_governance -->|"permits execution"| node_api_generation
node_api_generation -->|"reads ontology"| node_engine
node_api -->|"authenticates and authorizes"| node_security
node_api -->|"submits mutations"| node_actions
node_packs -->|"schemas and manifests"| node_odl
node_odl -->|"compiled artifacts"| node_schema_boot
node_schema_boot -->|"merged ontology"| node_api_generation
node_schema_boot -->|"registered schema"| node_engine
node_schema_boot -->|"action definitions"| node_actions
node_actions -->|"policy and consent checks"| node_security
node_actions -->|"gRPC evaluation"| node_cel
node_actions -->|"transactional mutations"| node_engine
node_engine -->|"storage operations"| node_spi
node_spi -->|"production implementation"| node_postgres
node_engine -->|"domain events"| node_events
node_events -->|"subscription delivery"| node_api
node_external_sources -->|"imports and CDC"| node_sync
node_sync -->|"consumes and maps"| node_cdc
node_cdc -->|"resolved ontology writes"| node_engine
node_deployment -.->|"deploys"| node_api
node_deployment -.->|"deploys"| node_engine
node_deployment -.->|"deploys"| node_actions
node_deployment -.->|"deploys"| node_sync

click node_api "https://github.com/cantodelobo/open-foundry/blob/main/packages/api/src/server.ts"
click node_api_generation "https://github.com/cantodelobo/open-foundry/blob/main/packages/api/src/graphql/resolver-generator.ts"
click node_query_governance "https://github.com/cantodelobo/open-foundry/blob/main/packages/api/src/governance/execution-guard.ts"
click node_packs "https://github.com/cantodelobo/open-foundry/blob/main/domain-packs/nhs-acute/pack.yaml"
click node_odl "https://github.com/cantodelobo/open-foundry/blob/main/packages/odl/src/parser/index.ts"
click node_schema_boot "https://github.com/cantodelobo/open-foundry/blob/main/packages/api/src/schema-registry-boot.ts"
click node_security "https://github.com/cantodelobo/open-foundry/blob/main/packages/security/src/authz/authorization-service.ts"
click node_actions "https://github.com/cantodelobo/open-foundry/blob/main/packages/actions/src/executor/action-executor.ts"
click node_cel "https://github.com/cantodelobo/open-foundry/blob/main/packages/cel-evaluator/evaluator/evaluator.go"
click node_engine "https://github.com/cantodelobo/open-foundry/blob/main/packages/engine/src/objects/object-manager.ts"
click node_spi "https://github.com/cantodelobo/open-foundry/blob/main/packages/spi/src/index.ts"
click node_postgres "https://github.com/cantodelobo/open-foundry/blob/main/packages/storage-postgres/src/postgres-storage-provider.ts"
click node_events "https://github.com/cantodelobo/open-foundry/blob/main/packages/api/src/events/redpanda-event-bus.ts"
click node_sync "https://github.com/cantodelobo/open-foundry/blob/main/packages/sync/src/server.ts"
click node_cdc "https://github.com/cantodelobo/open-foundry/blob/main/packages/sync/src/cdc/cdc-consumer.ts"
click node_deployment "https://github.com/cantodelobo/open-foundry/blob/main/deploy/helm/openfoundry/values.yaml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_packs,node_odl,node_schema_boot toneBlue
class node_api,node_api_generation,node_query_governance,node_security,node_actions,node_cel,node_engine toneAmber
class node_spi,node_postgres,node_events toneMint
class node_sync,node_cdc,node_external_sources,node_deployment toneRose
class node_callers toneNeutral
```

## Components

### Domain compilation

- [Domain packs](https://github.com/cantodelobo/open-foundry/blob/main/domain-packs/nhs-acute/pack.yaml): ODL schemas and manifests · Provide ontology, actions, connectors, authorization models, and bootstrap seeds. · `domain-packs/nhs-acute/pack.yaml`
- [ODL compiler](https://github.com/cantodelobo/open-foundry/blob/main/packages/odl/src/parser/index.ts): schema compiler · Parses, validates, registers, diffs, and generates ontology artifacts. · `packages/odl/src/parser/index.ts`
- [Schema registry boot](https://github.com/cantodelobo/open-foundry/blob/main/packages/api/src/schema-registry-boot.ts): runtime pack loader · Merges built-in and optional external packs at startup. · `packages/api/src/schema-registry-boot.ts`

### Service runtime

- [API gateway](https://github.com/cantodelobo/open-foundry/blob/main/packages/api/src/server.ts): API service · External GraphQL, REST, FHIR, CDM, subscription, and specification boundary. · `packages/api/src/server.ts`
- [Generated query surface](https://github.com/cantodelobo/open-foundry/blob/main/packages/api/src/graphql/resolver-generator.ts): resolver and route generation · Builds ontology-derived GraphQL and REST reads. · `packages/api/src/graphql/resolver-generator.ts`
- [Query governance](https://github.com/cantodelobo/open-foundry/blob/main/packages/api/src/governance/execution-guard.ts): execution guard · Applies complexity, rate, and execution limits. · `packages/api/src/governance/execution-guard.ts`
- [Security service](https://github.com/cantodelobo/open-foundry/blob/main/packages/security/src/authz/authorization-service.ts): authn, authz, consent · Mandatory OIDC, OpenFGA, redaction, consent, and audit layer. · `packages/security/src/authz/authorization-service.ts`
- [Action executor](https://github.com/cantodelobo/open-foundry/blob/main/packages/actions/src/executor/action-executor.ts): governed mutation pipeline · Runs validation, policy, transaction, compensation, audit, and events. · `packages/actions/src/executor/action-executor.ts`
- [CEL evaluator](https://github.com/cantodelobo/open-foundry/blob/main/packages/cel-evaluator/evaluator/evaluator.go): Go gRPC sidecar · Isolated evaluation of action preconditions and effects. · `packages/cel-evaluator/evaluator/evaluator.go`
- [Ontology engine](https://github.com/cantodelobo/open-foundry/blob/main/packages/engine/src/objects/object-manager.ts): object and graph runtime · Owns objects, links, sets, computed fields, lineage, and domain events. · `packages/engine/src/objects/object-manager.ts`

### Data and events

- [Storage SPI](https://github.com/cantodelobo/open-foundry/blob/main/packages/spi/src/index.ts): storage abstraction · Decouples engine capabilities from storage implementations. · `packages/spi/src/index.ts`
- [PostgreSQL + Apache AGE](https://github.com/cantodelobo/open-foundry/blob/main/packages/storage-postgres/src/postgres-storage-provider.ts): production storage provider · Tenant objects, graph traversal, history, search, registry, audit, and consent. · `packages/storage-postgres/src/postgres-storage-provider.ts`
- [Event bus](https://github.com/cantodelobo/open-foundry/blob/main/packages/api/src/events/redpanda-event-bus.ts): Redpanda/Kafka adapter · Feeds subscriptions and asynchronous consumers with memory fallback. · `packages/api/src/events/redpanda-event-bus.ts`

### Ingestion and operations

- [Sync service](https://github.com/cantodelobo/open-foundry/blob/main/packages/sync/src/server.ts): external ingestion service · Imports JDBC/REST and CDC sources into ontology objects. · `packages/sync/src/server.ts`
- [CDC and record mapping](https://github.com/cantodelobo/open-foundry/blob/main/packages/sync/src/cdc/cdc-consumer.ts): ingestion pipeline · Maps records and resolves identity, conflicts, and overlays. · `packages/sync/src/cdc/cdc-consumer.ts`
- **External source systems**: JDBC, REST, CDC sources
- [Helm deployment](https://github.com/cantodelobo/open-foundry/blob/main/deploy/helm/openfoundry/values.yaml): production deployment · Deploys services with network, security, and availability controls. · `deploy/helm/openfoundry/values.yaml`

### Other components

- **Clients and integrations**: external callers · Use generated APIs and subscriptions.

## Connections

- 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
