# krishgok/fhir-openapi-translator architecture

> Architecture diagram of the GitHub repository krishgok/fhir-openapi-translator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/krishgok/fhir-openapi-translator
- Repository: https://github.com/krishgok/fhir-openapi-translator

## Overview

fhir-openapi-translator is a TypeScript library and CLI that turns FHIR R4, R4B, or R5 definitions into OpenAPI documents. The main workflow accepts resource selections or a server CapabilityStatement, builds resource schemas and REST paths, then emits a document; users can also apply IG profiles, tune search parameters, add operations, or merge/check generated specs. The graph follows documented entry points and source-index references; unsampled implementation details are not treated as verified call relationships.

Main entry points: [`src/generate.ts`](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/generate.ts) (OpenAPI generator), [`src/definitions.ts`](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/definitions.ts) (Bundled FHIR definitions), [`src/cli.ts`](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/cli.ts) (CLI commands), [`src/backends/schemaJson.ts`](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/backends/schemaJson.ts) (JSON Schema backend)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_cli["CLI commands<br/>[cli.ts]"]
  node_library["Library API<br/>[index.ts]"]
  node_generator["OpenAPI generator<br/>[generate.ts]"]
end

subgraph group_schema["Schema generation"]
  node_definitions[("Bundled FHIR definitions<br/>[definitions.ts]")]
  node_schema_backend["JSON Schema backend<br/>[schemaJson.ts]"]
  node_structure_backend["StructureDefinition backend"]
  node_registry["Definition registry<br/>[registry.ts]"]
  node_walker["Structure walker<br/>[structureWalker.ts]"]
  node_schema_emitter["OpenAPI schema emitter<br/>[schema.ts]"]
  node_version["FHIR versions<br/>[version.ts]"]
end

subgraph group_api["API surface"]
  node_paths["FHIR REST paths<br/>[paths.ts]"]
  node_search["Search parameters<br/>[searchParams.ts]"]
  node_operations["FHIR operations<br/>[operations.ts]"]
end

subgraph group_extensions["FHIR extensions"]
  node_capability["CapabilityStatement parser<br/>[capability.ts]"]
  node_ig_package["IG package loader<br/>[package.ts]"]
  node_ig_minimize["IG definition minimizer<br/>[minimize.ts]"]
  node_profile["Profile applier<br/>[profile.ts]"]
  node_merge["Spec merge<br/>[merge.ts]"]
end

node_user(("CLI or library user"))
node_openapi["OpenAPI document"]

node_user -->|"runs"| node_cli
node_user -->|"calls"| node_library
node_cli -->|"generates"| node_generator
node_library -->|"exposes"| node_generator
node_generator -->|"returns"| node_openapi
node_generator -->|"builds registry"| node_schema_backend
node_generator -->|"builds registry"| node_structure_backend
node_generator -->|"extracts closure"| node_registry
node_generator -->|"converts schemas"| node_schema_emitter
node_schema_backend -->|"loads definitions"| node_definitions
node_schema_backend -->|"builds"| node_registry
node_structure_backend -->|"loads snapshots"| node_definitions
node_structure_backend -->|"emits schemas"| node_walker
node_walker -->|"uses definition types"| node_definitions
node_generator -->|"builds paths"| node_paths
node_paths -->|"loads parameters"| node_definitions
node_paths -->|"gets codes"| node_search
node_search -->|"loads parameters"| node_definitions
node_generator -->|"builds operation paths"| node_operations
node_operations -->|"loads operations"| node_definitions
node_cli -->|"loads capability"| node_capability
node_generator -->|"uses capabilities"| node_capability
node_cli -->|"loads IG"| node_ig_package
node_generator -->|"loads IG"| node_ig_package
node_ig_package -->|"minimizes definitions"| node_ig_minimize
node_generator -->|"applies profiles"| node_profile
node_profile -->|"emits profile schemas"| node_walker
node_cli -->|"merges or checks"| node_merge
node_generator -.->|"uses version options"| node_version

click node_cli "https://github.com/krishgok/fhir-openapi-translator/blob/main/src/cli.ts"
click node_library "https://github.com/krishgok/fhir-openapi-translator/blob/main/src/index.ts"
click node_generator "https://github.com/krishgok/fhir-openapi-translator/blob/main/src/generate.ts"
click node_definitions "https://github.com/krishgok/fhir-openapi-translator/blob/main/src/definitions.ts"
click node_schema_backend "https://github.com/krishgok/fhir-openapi-translator/blob/main/src/backends/schemaJson.ts"
click node_structure_backend "https://github.com/krishgok/fhir-openapi-translator/blob/main/src/backends/structureDefinition.ts"
click node_registry "https://github.com/krishgok/fhir-openapi-translator/blob/main/src/ir/registry.ts"
click node_walker "https://github.com/krishgok/fhir-openapi-translator/blob/main/src/ir/structureWalker.ts"
click node_schema_emitter "https://github.com/krishgok/fhir-openapi-translator/blob/main/src/emit/schema.ts"
click node_paths "https://github.com/krishgok/fhir-openapi-translator/blob/main/src/paths.ts"
click node_search "https://github.com/krishgok/fhir-openapi-translator/blob/main/src/searchParams.ts"
click node_operations "https://github.com/krishgok/fhir-openapi-translator/blob/main/src/operations.ts"
click node_capability "https://github.com/krishgok/fhir-openapi-translator/blob/main/src/capability.ts"
click node_ig_package "https://github.com/krishgok/fhir-openapi-translator/blob/main/src/ig/package.ts"
click node_ig_minimize "https://github.com/krishgok/fhir-openapi-translator/blob/main/src/ig/minimize.ts"
click node_profile "https://github.com/krishgok/fhir-openapi-translator/blob/main/src/ig/profile.ts"
click node_merge "https://github.com/krishgok/fhir-openapi-translator/blob/main/src/merge.ts"
click node_version "https://github.com/krishgok/fhir-openapi-translator/blob/main/src/version.ts"

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_cli,node_library,node_generator,node_user toneBlue
class node_definitions,node_schema_backend,node_structure_backend,node_registry,node_walker,node_schema_emitter,node_version toneAmber
class node_paths,node_search,node_operations,node_openapi toneMint
class node_capability,node_ig_package,node_ig_minimize,node_profile,node_merge toneRose
```

## Components

### Entry points

- [CLI commands](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/cli.ts): `src/cli.ts`
- [Library API](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/index.ts): `src/index.ts`
- [OpenAPI generator](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/generate.ts): `src/generate.ts`

### Schema generation

- [Bundled FHIR definitions](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/definitions.ts): `src/definitions.ts`
- [JSON Schema backend](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/backends/schemaJson.ts): `src/backends/schemaJson.ts`
- [StructureDefinition backend](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/backends/structureDefinition.ts): `src/backends/structureDefinition.ts`
- [Definition registry](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/ir/registry.ts): `src/ir/registry.ts`
- [Structure walker](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/ir/structureWalker.ts): `src/ir/structureWalker.ts`
- [OpenAPI schema emitter](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/emit/schema.ts): `src/emit/schema.ts`
- [FHIR versions](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/version.ts): `src/version.ts`

### API surface

- [FHIR REST paths](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/paths.ts): `src/paths.ts`
- [Search parameters](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/searchParams.ts): `src/searchParams.ts`
- [FHIR operations](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/operations.ts): `src/operations.ts`

### FHIR extensions

- [CapabilityStatement parser](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/capability.ts): `src/capability.ts`
- [IG package loader](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/ig/package.ts): `src/ig/package.ts`
- [IG definition minimizer](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/ig/minimize.ts): `src/ig/minimize.ts`
- [Profile applier](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/ig/profile.ts): `src/ig/profile.ts`
- [Spec merge](https://github.com/krishgok/fhir-openapi-translator/blob/main/src/merge.ts): `src/merge.ts`

### Other components

- **CLI or library user**
- **OpenAPI document**

## Connections

- CLI or library user → CLI commands: runs (evidence: `README.md`)
- CLI or library user → Library API: calls (evidence: `README.md`)
- CLI commands → OpenAPI generator: generates (evidence: `src/cli.ts`)
- Library API → OpenAPI generator: exposes (evidence: `src/index.ts`)
- OpenAPI generator → OpenAPI document: returns (evidence: `README.md`)
- OpenAPI generator → JSON Schema backend: builds registry (evidence: `src/generate.ts`)
- OpenAPI generator → StructureDefinition backend: builds registry (evidence: `src/generate.ts`)
- OpenAPI generator → Definition registry: extracts closure (evidence: `src/generate.ts`)
- OpenAPI generator → OpenAPI schema emitter: converts schemas (evidence: `src/generate.ts`)
- JSON Schema backend → Bundled FHIR definitions: loads definitions (evidence: `src/backends/schemaJson.ts`)
- JSON Schema backend → Definition registry: builds (evidence: `src/backends/schemaJson.ts`)
- StructureDefinition backend → Bundled FHIR definitions: loads snapshots (evidence: `src/backends/structureDefinition.ts`)
- StructureDefinition backend → Structure walker: emits schemas (evidence: `src/backends/structureDefinition.ts`)
- Structure walker → Bundled FHIR definitions: uses definition types (evidence: `src/ir/structureWalker.ts`)
- OpenAPI generator → FHIR REST paths: builds paths (evidence: `src/generate.ts`)
- FHIR REST paths → Bundled FHIR definitions: loads parameters (evidence: `src/paths.ts`)
- FHIR REST paths → Search parameters: gets codes (evidence: `src/paths.ts`)
- Search parameters → Bundled FHIR definitions: loads parameters (evidence: `src/searchParams.ts`)
- OpenAPI generator → FHIR operations: builds operation paths (evidence: `src/generate.ts`)
- FHIR operations → Bundled FHIR definitions: loads operations (evidence: `src/operations.ts`)
- CLI commands → CapabilityStatement parser: loads capability (evidence: `src/cli.ts`)
- OpenAPI generator → CapabilityStatement parser: uses capabilities (evidence: `src/generate.ts`)
- CLI commands → IG package loader: loads IG (evidence: `src/cli.ts`)
- OpenAPI generator → IG package loader: loads IG (evidence: `src/generate.ts`)
- IG package loader → IG definition minimizer: minimizes definitions (evidence: `src/ig/package.ts`)
- OpenAPI generator → Profile applier: applies profiles (evidence: `src/generate.ts`)
- Profile applier → Structure walker: emits profile schemas (evidence: `src/ig/profile.ts`)
- CLI commands → Spec merge: merges or checks (evidence: `src/cli.ts`)
- OpenAPI generator → FHIR versions: uses version options
