# zama-ai/fhevm architecture

> Architecture diagram of the GitHub repository zama-ai/fhevm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zama-ai/fhevm
- Repository: https://github.com/zama-ai/fhevm

## Overview

FHEVM is a full-stack framework for confidential smart contracts: developers express privacy logic in Solidity, encrypted state and symbolic FHE operations remain on the host chain, and asynchronous encrypted computation is offloaded to the coprocessor. Gateway and host contracts coordinate the on-chain/off-chain boundary; KMS handles key management. The graph also shows host-listener event ingestion and its history/dependency internals. README statements support the product-level flow; source-index references support the listener links. Other unsampled subsystem interactions are omitted.

Main entry points: [`coprocessor/fhevm-engine/host-listener/src/database/ingest.rs`](https://github.com/zama-ai/fhevm/blob/main/coprocessor/fhevm-engine/host-listener/src/database/ingest.rs) (Host Listener), [`coprocessor/fhevm-engine`](https://github.com/zama-ai/fhevm/tree/main/coprocessor/fhevm-engine) (FHE Coprocessor), [`host-contracts`](https://github.com/zama-ai/fhevm/tree/main/host-contracts) (Host Contracts), [`library-solidity`](https://github.com/zama-ai/fhevm/tree/main/library-solidity) (FHE Solidity)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_contracts["Contract Layer"]
  node_solidity["FHE Solidity"]
  node_hostcontracts["Host Contracts"]
  node_gatewaycontracts["Gateway Contracts"]
end

subgraph group_compute["FHE Compute"]
  node_coprocessor["FHE Coprocessor"]
  node_tfheworker["TFHE Worker<br/>[tfhe_worker.rs]"]
  node_scheduler["Operation Scheduler<br/>[scheduler.rs]"]
end

subgraph group_chainservices["Chain Services"]
  node_hostlistener["Host Listener<br/>[ingest.rs]"]
  node_eventoperands["Event Operand Parsing<br/>[event_operands.rs]"]
  node_dependencychains["Dependency Chains"]
  node_historyverify["History Verification"]
  node_relayer["Relayer<br/>[server.rs]"]
end

subgraph group_security["Key Security"]
  node_kms["KMS Connector<br/>[kms_worker.rs]"]
end

subgraph group_client["Developer Tools"]
  node_sdk["JavaScript SDK<br/>[coreFhevmClient.ts]"]
  node_frozencontext["Version Context"]
end

node_developer(("dApp Developer"))
node_hostchain[("Host Chain")]

node_developer -->|"writes contracts"| node_solidity
node_solidity -->|"expresses FHE logic"| node_hostcontracts
node_hostcontracts -->|"executes symbolically"| node_hostchain
node_hostchain -->|"offloads computation"| node_coprocessor
node_coprocessor -->|"performs FHE"| node_tfheworker
node_tfheworker -->|"schedules operations"| node_scheduler
node_hostcontracts -->|"uses gateway"| node_gatewaycontracts
node_gatewaycontracts -->|"bridges components"| node_coprocessor
node_hostchain -->|"emits events"| node_hostlistener
node_hostlistener -->|"parses operands"| node_eventoperands
node_hostlistener -->|"updates dependencies"| node_dependencychains
node_hostlistener -->|"verifies finalized history"| node_historyverify
node_hostchain -->|"sends transactions"| node_relayer
node_kms -->|"manages keys"| node_coprocessor
node_developer -->|"uses SDK"| node_sdk
node_sdk -->|"resolves versions"| node_frozencontext

click node_solidity "https://github.com/zama-ai/fhevm/tree/main/library-solidity"
click node_hostcontracts "https://github.com/zama-ai/fhevm/tree/main/host-contracts"
click node_gatewaycontracts "https://github.com/zama-ai/fhevm/tree/main/gateway-contracts"
click node_coprocessor "https://github.com/zama-ai/fhevm/tree/main/coprocessor/fhevm-engine"
click node_tfheworker "https://github.com/zama-ai/fhevm/blob/main/coprocessor/fhevm-engine/tfhe-worker/src/tfhe_worker.rs"
click node_scheduler "https://github.com/zama-ai/fhevm/blob/main/coprocessor/fhevm-engine/scheduler/src/dfg/scheduler.rs"
click node_hostlistener "https://github.com/zama-ai/fhevm/blob/main/coprocessor/fhevm-engine/host-listener/src/database/ingest.rs"
click node_eventoperands "https://github.com/zama-ai/fhevm/blob/main/coprocessor/fhevm-engine/host-listener/src/database/event_operands.rs"
click node_dependencychains "https://github.com/zama-ai/fhevm/blob/main/coprocessor/fhevm-engine/host-listener/src/database/dependence_chains.rs"
click node_historyverify "https://github.com/zama-ai/fhevm/blob/main/coprocessor/fhevm-engine/host-listener/src/database/history_verification.rs"
click node_relayer "https://github.com/zama-ai/fhevm/blob/main/relayer/src/http/server.rs"
click node_kms "https://github.com/zama-ai/fhevm/blob/main/kms-connector/crates/kms-worker/src/core/kms_worker.rs"
click node_sdk "https://github.com/zama-ai/fhevm/blob/main/sdk/js-sdk/src/core/types/coreFhevmClient.ts"
click node_frozencontext "https://github.com/zama-ai/fhevm/blob/main/sdk/js-sdk/src/core/frozenContext/fhevmClientFrozenContext-p.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_solidity,node_hostcontracts,node_gatewaycontracts toneBlue
class node_coprocessor,node_tfheworker,node_scheduler,node_hostchain toneAmber
class node_hostlistener,node_eventoperands,node_dependencychains,node_historyverify,node_relayer toneMint
class node_kms toneRose
class node_sdk,node_frozencontext,node_developer toneIndigo
```

## Components

### Contract Layer

- [FHE Solidity](https://github.com/zama-ai/fhevm/tree/main/library-solidity): `library-solidity`
- [Host Contracts](https://github.com/zama-ai/fhevm/tree/main/host-contracts): `host-contracts`
- [Gateway Contracts](https://github.com/zama-ai/fhevm/tree/main/gateway-contracts): `gateway-contracts`

### FHE Compute

- [FHE Coprocessor](https://github.com/zama-ai/fhevm/tree/main/coprocessor/fhevm-engine): `coprocessor/fhevm-engine`
- [TFHE Worker](https://github.com/zama-ai/fhevm/blob/main/coprocessor/fhevm-engine/tfhe-worker/src/tfhe_worker.rs): `coprocessor/fhevm-engine/tfhe-worker/src/tfhe_worker.rs`
- [Operation Scheduler](https://github.com/zama-ai/fhevm/blob/main/coprocessor/fhevm-engine/scheduler/src/dfg/scheduler.rs): `coprocessor/fhevm-engine/scheduler/src/dfg/scheduler.rs`

### Chain Services

- [Host Listener](https://github.com/zama-ai/fhevm/blob/main/coprocessor/fhevm-engine/host-listener/src/database/ingest.rs): `coprocessor/fhevm-engine/host-listener/src/database/ingest.rs`
- [Event Operand Parsing](https://github.com/zama-ai/fhevm/blob/main/coprocessor/fhevm-engine/host-listener/src/database/event_operands.rs): `coprocessor/fhevm-engine/host-listener/src/database/event_operands.rs`
- [Dependency Chains](https://github.com/zama-ai/fhevm/blob/main/coprocessor/fhevm-engine/host-listener/src/database/dependence_chains.rs): `coprocessor/fhevm-engine/host-listener/src/database/dependence_chains.rs`
- [History Verification](https://github.com/zama-ai/fhevm/blob/main/coprocessor/fhevm-engine/host-listener/src/database/history_verification.rs): `coprocessor/fhevm-engine/host-listener/src/database/history_verification.rs`
- [Relayer](https://github.com/zama-ai/fhevm/blob/main/relayer/src/http/server.rs): `relayer/src/http/server.rs`

### Key Security

- [KMS Connector](https://github.com/zama-ai/fhevm/blob/main/kms-connector/crates/kms-worker/src/core/kms_worker.rs): `kms-connector/crates/kms-worker/src/core/kms_worker.rs`

### Developer Tools

- [JavaScript SDK](https://github.com/zama-ai/fhevm/blob/main/sdk/js-sdk/src/core/types/coreFhevmClient.ts): `sdk/js-sdk/src/core/types/coreFhevmClient.ts`
- [Version Context](https://github.com/zama-ai/fhevm/blob/main/sdk/js-sdk/src/core/frozenContext/fhevmClientFrozenContext-p.ts): `sdk/js-sdk/src/core/frozenContext/fhevmClientFrozenContext-p.ts`

### Other components

- **dApp Developer**
- **Host Chain**

## Connections

- dApp Developer → FHE Solidity: writes contracts (evidence: `README.md`)
- FHE Solidity → Host Contracts: expresses FHE logic (evidence: `README.md`)
- Host Contracts → Host Chain: executes symbolically (evidence: `README.md`)
- Host Chain → FHE Coprocessor: offloads computation (evidence: `README.md`)
- FHE Coprocessor → TFHE Worker: performs FHE
- TFHE Worker → Operation Scheduler: schedules operations
- Host Contracts → Gateway Contracts: uses gateway (evidence: `README.md`)
- Gateway Contracts → FHE Coprocessor: bridges components (evidence: `README.md`)
- Host Chain → Host Listener: emits events
- Host Listener → Event Operand Parsing: parses operands (evidence: `coprocessor/fhevm-engine/host-listener/src/database/ingest.rs`)
- Host Listener → Dependency Chains: updates dependencies (evidence: `coprocessor/fhevm-engine/host-listener/src/database/ingest.rs`)
- Host Listener → History Verification: verifies finalized history (evidence: `coprocessor/fhevm-engine/host-listener/src/database/ingest.rs`)
- Host Chain → Relayer: sends transactions
- KMS Connector → FHE Coprocessor: manages keys (evidence: `README.md`)
- dApp Developer → JavaScript SDK: uses SDK
- JavaScript SDK → Version Context: resolves versions (evidence: `sdk/js-sdk/src/core/frozenContext/fhevmClientFrozenContext-p.ts`)
