# datakaveri/p3dx_gov_layer architecture

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

- Interactive diagram: https://gitdiagram.com/datakaveri/p3dx_gov_layer
- Repository: https://github.com/datakaveri/p3dx_gov_layer

## Overview

P3DX Governance Layer is a REST coordination service for FL, TEE, and SMPC contracts. Clients submit a contract; the service obtains forms or policies, applies authorization and signing gates, persists contract state, and routes eligible work to an executor. Separate API branches support provider approvals, consent notifications, TEE sessions, model retrieval, and registries. The README documents the primary contract flow; the available excerpts show server wiring, persistence, signing, approvals, and TEE session sequencing, but not every handler’s internal calls.

Main entry points: [`internal/httpapi/server.go`](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/server.go) (REST Router), [`internal/httpapi/general_contract.go`](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/general_contract.go) (Contract Intake), [`internal/httpapi/tee_orchestrator.go`](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/tee_orchestrator.go) (TEE Orchestrator API), [`internal/db/contracts.go`](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/db/contracts.go) (Contract Data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["REST API"]
  node_rest["REST Router<br/>[server.go]"]
  node_model["Final Model Retrieval<br/>[model.go]"]
  node_registries["VM Registry<br/>[vm_registry.go]"]
end

subgraph group_contract["Contract Lifecycle"]
  node_intake["Contract Intake"]
  node_forms["Forms and Policies<br/>[apd.go]"]
  node_authorization["Policy Authorization<br/>[apd.go]"]
  node_generated["Contract Generation<br/>[contractgen.go]"]
  node_approval["Job Approval<br/>[job_approval.go]"]
  node_signing["Contract Signing"]
  node_keymanagement["Provider Keys<br/>[provider_keys.go]"]
end

subgraph group_fl["FL Participation"]
  node_notifications["Consent Notifications"]
  node_notificationdata[("Notification Data")]
  node_providerforms["Provider Messages<br/>[fl_forms.go]"]
end

subgraph group_tee["TEE Execution"]
  node_teeapi["TEE Orchestrator API"]
  node_teesessions["TEE Sessions<br/>[tee_session.go]"]
  node_teeprimitives["TEE Operations<br/>[tee.go]"]
  node_attestation["TEE Attestation<br/>[attestation.go]"]
end

subgraph group_platform["Platform Services"]
  node_entry["Server Entry<br/>[main.go]"]
  node_contracts[("Contract Data<br/>[contracts.go]")]
  node_database["Database Startup<br/>[db.go]"]
  node_keycloak["Keycloak Auth<br/>[keycloak.go]"]
end

node_clients(("Clients"))
node_postgres[("PostgreSQL")]
node_executors["FL / TEE / SMPC Executors"]
node_apd["APD"]

node_clients -->|"submit requests"| node_rest
node_entry -->|"initializes database"| node_database
node_entry -->|"starts server"| node_rest
node_rest -->|"routes contract"| node_intake
node_intake -->|"fetches forms or policies"| node_forms
node_intake -->|"authorizes request"| node_authorization
node_intake -->|"stores contract"| node_contracts
node_intake -->|"routes by technique"| node_executors
node_forms -->|"fetches datasets"| node_apd
node_approval -->|"audits approvals"| node_contracts
node_signing -->|"loads contract"| node_contracts
node_signing -->|"notifies providers"| node_notificationdata
node_rest -->|"routes notifications"| node_notifications
node_notifications -->|"manages consent"| node_notificationdata
node_rest -->|"routes provider forms"| node_providerforms
node_rest -->|"routes key operations"| node_keymanagement
node_rest -->|"mounts TEE routes"| node_teeapi
node_rest -->|"mounts session routes"| node_teesessions
node_teesessions -->|"drives TEE sequence"| node_teeapi
node_teeapi -.->|"runs TEE operations"| node_teeprimitives
node_teeapi -.->|"verifies attestation"| node_attestation
node_rest -.->|"routes model requests"| node_model
node_rest -.->|"routes registry requests"| node_registries
node_database -->|"opens and migrates"| node_postgres
node_keycloak -.->|"authenticates integration"| node_apd
node_generated -->|"builds contract data"| node_contracts

click node_entry "https://github.com/datakaveri/p3dx_gov_layer/blob/main/cmd/server/main.go"
click node_rest "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/server.go"
click node_intake "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/general_contract.go"
click node_forms "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/services/apd.go"
click node_authorization "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/services/apd.go"
click node_generated "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/services/contractgen.go"
click node_approval "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/job_approval.go"
click node_signing "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/contract_signing.go"
click node_contracts "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/db/contracts.go"
click node_notifications "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/fl_notifications.go"
click node_notificationdata "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/db/fl_notifications.go"
click node_providerforms "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/fl_forms.go"
click node_keymanagement "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/provider_keys.go"
click node_teeapi "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/tee_orchestrator.go"
click node_teesessions "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/tee_session.go"
click node_teeprimitives "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/services/tee.go"
click node_attestation "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/services/attestation.go"
click node_model "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/model.go"
click node_registries "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/vm_registry.go"
click node_database "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/db/db.go"
click node_keycloak "https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/keycloak/keycloak.go"

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_rest,node_model,node_registries,node_clients toneBlue
class node_intake,node_forms,node_authorization,node_generated,node_approval,node_signing,node_keymanagement,node_postgres toneAmber
class node_notifications,node_notificationdata,node_providerforms toneMint
class node_teeapi,node_teesessions,node_teeprimitives,node_attestation toneRose
class node_entry,node_contracts,node_database,node_keycloak,node_executors,node_apd toneIndigo
```

## Components

### REST API

- [REST Router](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/server.go): `internal/httpapi/server.go`
- [Final Model Retrieval](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/model.go): `internal/httpapi/model.go`
- [VM Registry](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/vm_registry.go): `internal/httpapi/vm_registry.go`

### Contract Lifecycle

- [Contract Intake](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/general_contract.go): `internal/httpapi/general_contract.go`
- [Forms and Policies](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/services/apd.go): `internal/services/apd.go`
- [Policy Authorization](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/services/apd.go): `internal/services/apd.go`
- [Contract Generation](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/services/contractgen.go): `internal/services/contractgen.go`
- [Job Approval](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/job_approval.go): `internal/httpapi/job_approval.go`
- [Contract Signing](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/contract_signing.go): `internal/httpapi/contract_signing.go`
- [Provider Keys](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/provider_keys.go): `internal/httpapi/provider_keys.go`

### FL Participation

- [Consent Notifications](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/fl_notifications.go): `internal/httpapi/fl_notifications.go`
- [Notification Data](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/db/fl_notifications.go): `internal/db/fl_notifications.go`
- [Provider Messages](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/fl_forms.go): `internal/httpapi/fl_forms.go`

### TEE Execution

- [TEE Orchestrator API](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/tee_orchestrator.go): `internal/httpapi/tee_orchestrator.go`
- [TEE Sessions](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/httpapi/tee_session.go): `internal/httpapi/tee_session.go`
- [TEE Operations](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/services/tee.go): `internal/services/tee.go`
- [TEE Attestation](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/services/attestation.go): `internal/services/attestation.go`

### Platform Services

- [Server Entry](https://github.com/datakaveri/p3dx_gov_layer/blob/main/cmd/server/main.go): `cmd/server/main.go`
- [Contract Data](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/db/contracts.go): `internal/db/contracts.go`
- [Database Startup](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/db/db.go): `internal/db/db.go`
- [Keycloak Auth](https://github.com/datakaveri/p3dx_gov_layer/blob/main/internal/keycloak/keycloak.go): `internal/keycloak/keycloak.go`

### Other components

- **Clients**
- **PostgreSQL**
- **FL / TEE / SMPC Executors**
- **APD**

## Connections

- Clients → REST Router: submit requests
- Server Entry → Database Startup: initializes database (evidence: `cmd/server/main.go`)
- Server Entry → REST Router: starts server (evidence: `cmd/server/main.go`)
- REST Router → Contract Intake: routes contract (evidence: `internal/httpapi/server.go`)
- Contract Intake → Forms and Policies: fetches forms or policies
- Contract Intake → Policy Authorization: authorizes request
- Contract Intake → Contract Data: stores contract
- Contract Intake → FL / TEE / SMPC Executors: routes by technique
- Forms and Policies → APD: fetches datasets
- Job Approval → Contract Data: audits approvals (evidence: `internal/httpapi/job_approval.go`)
- Contract Signing → Contract Data: loads contract (evidence: `internal/httpapi/contract_signing.go`)
- Contract Signing → Notification Data: notifies providers (evidence: `internal/httpapi/contract_signing.go`)
- REST Router → Consent Notifications: routes notifications (evidence: `internal/httpapi/server.go`)
- Consent Notifications → Notification Data: manages consent (evidence: `internal/httpapi/fl_notifications.go`)
- REST Router → Provider Messages: routes provider forms (evidence: `internal/httpapi/server.go`)
- REST Router → Provider Keys: routes key operations (evidence: `internal/httpapi/server.go`)
- REST Router → TEE Orchestrator API: mounts TEE routes (evidence: `internal/httpapi/tee_orchestrator.go`)
- REST Router → TEE Sessions: mounts session routes (evidence: `internal/httpapi/tee_session.go`)
- TEE Sessions → TEE Orchestrator API: drives TEE sequence (evidence: `internal/httpapi/tee_session.go`)
- TEE Orchestrator API → TEE Operations: runs TEE operations
- TEE Orchestrator API → TEE Attestation: verifies attestation
- REST Router → Final Model Retrieval: routes model requests
- REST Router → VM Registry: routes registry requests
- Database Startup → PostgreSQL: opens and migrates (evidence: `internal/db/db.go`)
- Keycloak Auth → APD: authenticates integration
- Contract Generation → Contract Data: builds contract data (evidence: `internal/services/contractgen.go`)
