# krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud architecture

> Architecture diagram of the GitHub repository krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud
- Repository: https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud

## Overview

#### Purpose and Runtime
Salesforce-native metadata intelligence application for Health Cloud-style orgs. It indexes selected org metadata, derives usage relationships, and produces grounded search, impact, security, release-readiness, documentation, and optimization outputs. Runtime is Apex on Salesforce with Lightning Web Components, Salesforce custom objects/metadata, Tooling API callouts, and Queueable async jobs. SFDX project entry is `sfdx-project.json`.

#### User and API Entry Points
The primary UI is the multi-tab LWC at `force-app/main/default/lwc/aiMetadataCopilotWorkspace/aiMetadataCopilotWorkspace.js`. It invokes `@AuraEnabled` endpoints in `force-app/main/default/classes/AiMetadataCopilotController.cls`, which delegates structured domain requests through `force-app/main/default/classes/AiAgentActionService.cls`. `MetadataNaturalLanguageAction.cls` is an invocable entry point for Agentforce/Flow-style natural-language resolution.

#### Metadata Refresh, Index, and Snapshot Pipeline
`MetadataExtractionOrchestrator.cls` coordinates refresh: query Tooling API, extract supported Apex/Flow/CustomField components, normalize them, index them, derive relationships, and snapshot results.
- Tooling boundary: `force-app/main/default/classes/MetadataToolingApiClient.cls` calls the same-org Salesforce Tooling API through the externally configured `SalesforceTooling` Named Credential.
- Catalog: `MetadataIndexerService.cls` upserts `force-app/main/default/objects/Metadata_Item__c/Metadata_Item__c.object-meta.xml`.
- Relationship graph source: `MetadataUsageAnalyzerService.cls` persists edges in `force-app/main/default/objects/Metadata_Usage__c/Metadata_Usage__c.object-meta.xml`.
- Historical state: `MetadataSnapshotService.cls` writes snapshots and component versions under `Metadata_Snapshot__c` and `Metadata_Component_Version__c`.

#### Search, Resolution, and Impact Graph
Search operates on persisted index and usage evidence rather than live metadata queries. `MetadataSearchService.cls` filters direct relationships; `NaturalLanguageResolutionService.cls` resolves API names, labels, objects, and fields before service execution. Impact starts from the same evidence but traverses both inbound/outbound edges with depth and cycle protection in `DependencyGraphService.cls`; `MetadataImpactAnalysisService.cls` calculates and persists assessments. Coverage is intentionally constrained to indexed metadata types.

#### Security Governance Pipeline
`SecurityAuditOrchestrator.cls` parses requested scope, classifies sensitive fields, aggregates exposure checks, and persists an audit run plus findings. Its policy boundary is configurable sensitive-field metadata, represented by `force-app/main/default/objects/Sensitive_Field_Rule__mdt/Sensitive_Field_Rule__mdt.object-meta.xml` and example records in `force-app/main/default/customMetadata/`. Specialized services cover field access, permission sets, profiles, and sharing. Results are durable records in `Security_Audit_Run__c` and `Security_Finding__c`; `SecurityAuditQueueable.cls` supports asynchronous execution.

#### Deployment Intelligence and Advisory Outputs
Deployment functionality is comparison-only, never a Salesforce deployment executor. `EnvironmentSnapshotService.cls` captures named environment-comparison snapshots; `MetadataCompareService.cls` computes added/removed/changed components by key and checksum. `DeploymentRiskAssessmentService.cls` converts deltas to readiness score, severity, findings, rollback checklist, and regression-test guidance, persisted under `Deployment_Assessment__c` and `Deployment_Finding__c`. `DeploymentCompareQueueable.cls` isolates potentially long-running comparisons.

#### Other Generated Analyses and Operational Controls
Documentation and optimization consume the same indexed metadata rather than bypassing the catalog: `MetadataDocumentationService.cls` creates documentation requests, while scanner classes feed `Optimization_Finding__c`. Async refresh and scan paths use `MetadataRefreshQueueable.cls` and `OptimizationScanQueueable.cls`. Custom metadata configures enabled agent actions and environment references, notably `Agent_Action_Config__mdt` and `Environment_Connection__mdt`; users require `force-app/main/default/permissionsets/AI_Metadata_Copilot_User.permissionset-meta.xml`.

Main entry points: [`force-app/main/default/classes/AiAgentActionService.cls`](https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/classes/AiAgentActionService.cls) (Agent Action Service), [`force-app/main/default/objects/Metadata_Item__c/Metadata_Item__c.object-meta.xml`](https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/objects/Metadata_Item__c/Metadata_Item__c.object-meta.xml) (Metadata Catalog), [`force-app/main/default/objects/Metadata_Usage__c/Metadata_Usage__c.object-meta.xml`](https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/objects/Metadata_Usage__c/Metadata_Usage__c.object-meta.xml) (Usage Graph), [`force-app/main/default/classes/AiMetadataCopilotController.cls`](https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/classes/AiMetadataCopilotController.cls) (Copilot Controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry Points"]
  node_workspace["Copilot Workspace<br/>LWC UI"]
  node_controller["Copilot Controller<br/>Apex API"]
  node_actions["Agent Action Service<br/>domain facade"]
  node_nl_invocable["Natural Language Action<br/>invocable Apex"]
  node_access_config["Action, Environment &amp; Access Config"]
end

subgraph group_refresh["Metadata Index Pipeline"]
  node_refresh_orchestrator["Extraction Orchestrator<br/>refresh orchestration"]
  node_tooling_api{{"Tooling API Client<br/>Salesforce API boundary"}}
  node_catalog[("Metadata Catalog<br/>custom object")]
  node_usage[("Usage Graph<br/>custom object")]
  node_snapshots[("Metadata History<br/>snapshot storage")]
  node_refresh_jobs["Refresh Jobs<br/>Queueable Apex"]
end

subgraph group_analysis["Analysis Services"]
  node_resolution["NL Resolution<br/>resolution service"]
  node_search["Metadata Search<br/>search service"]
  node_impact["Impact Analysis<br/>graph analysis"]
  node_advisory["Documentation &amp; Optimization<br/>generated analysis"]
end

subgraph group_security["Security Governance"]
  node_security_audit["Security Audit<br/>audit orchestration"]
  node_sensitive_rules[("Sensitive Field Rules<br/>custom metadata")]
  node_security_results[("Security Audit Results<br/>durable records")]
end

subgraph group_deployment["Deployment Intelligence"]
  node_deployment_compare["Environment Comparison<br/>comparison pipeline"]
  node_risk_assessment["Deployment Risk Assessment<br/>readiness analysis"]
  node_deployment_results[("Deployment Assessment Results<br/>durable records")]
  node_deployment_jobs["Comparison Jobs<br/>Queueable Apex"]
end

node_workspace -->|"Aura calls"| node_controller
node_controller -->|"delegates requests"| node_actions
node_nl_invocable -->|"natural-language requests"| node_actions
node_actions -->|"resolve inputs"| node_resolution
node_actions -->|"search"| node_search
node_actions -->|"analyze impact"| node_impact
node_actions -->|"run audit"| node_security_audit
node_actions -->|"compare environments"| node_deployment_compare
node_refresh_jobs -->|"runs refresh"| node_refresh_orchestrator
node_refresh_orchestrator -->|"extract metadata"| node_tooling_api
node_refresh_orchestrator -->|"normalize and index"| node_catalog
node_refresh_orchestrator -->|"derive relationships"| node_usage
node_refresh_orchestrator -->|"write history"| node_snapshots
node_search -->|"query indexed items"| node_catalog
node_search -->|"direct relationships"| node_usage
node_impact -->|"traverse graph"| node_usage
node_advisory -->|"consume index"| node_catalog
node_security_audit -->|"apply policy"| node_sensitive_rules
node_security_audit -->|"persist findings"| node_security_results
node_deployment_jobs -->|"run comparison"| node_deployment_compare
node_deployment_compare -->|"component deltas"| node_risk_assessment
node_risk_assessment -->|"persist assessment"| node_deployment_results
node_access_config -.->|"governs actions and access"| node_actions

click node_workspace "https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/lwc/aiMetadataCopilotWorkspace/aiMetadataCopilotWorkspace.js"
click node_controller "https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/classes/AiMetadataCopilotController.cls"
click node_actions "https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/classes/AiAgentActionService.cls"
click node_tooling_api "https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/classes/MetadataToolingApiClient.cls"
click node_catalog "https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/objects/Metadata_Item__c/Metadata_Item__c.object-meta.xml"
click node_usage "https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/objects/Metadata_Usage__c/Metadata_Usage__c.object-meta.xml"
click node_sensitive_rules "https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/objects/Sensitive_Field_Rule__mdt/Sensitive_Field_Rule__mdt.object-meta.xml"
click node_access_config "https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/permissionsets/AI_Metadata_Copilot_User.permissionset-meta.xml"

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_workspace,node_controller,node_actions,node_nl_invocable,node_access_config toneBlue
class node_refresh_orchestrator,node_tooling_api,node_catalog,node_usage,node_snapshots,node_refresh_jobs toneAmber
class node_resolution,node_search,node_impact,node_advisory toneMint
class node_security_audit,node_sensitive_rules,node_security_results toneRose
class node_deployment_compare,node_risk_assessment,node_deployment_results,node_deployment_jobs toneIndigo
```

## Components

### Entry Points

- [Copilot Workspace](https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/lwc/aiMetadataCopilotWorkspace/aiMetadataCopilotWorkspace.js): LWC UI · Multi-tab metadata intelligence workspace. · `force-app/main/default/lwc/aiMetadataCopilotWorkspace/aiMetadataCopilotWorkspace.js`
- [Copilot Controller](https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/classes/AiMetadataCopilotController.cls): Apex API · `force-app/main/default/classes/AiMetadataCopilotController.cls`
- [Agent Action Service](https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/classes/AiAgentActionService.cls): domain facade · `force-app/main/default/classes/AiAgentActionService.cls`
- **Natural Language Action**: invocable Apex · Agentforce and Flow entry point.
- [Action, Environment & Access Config](https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/permissionsets/AI_Metadata_Copilot_User.permissionset-meta.xml): custom metadata and permission set · Controls enabled actions, environment references, and user access. · `force-app/main/default/permissionsets/AI_Metadata_Copilot_User.permissionset-meta.xml`

### Metadata Index Pipeline

- **Extraction Orchestrator**: refresh orchestration · Coordinates extraction, normalization, indexing, relationships, and snapshots.
- [Tooling API Client](https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/classes/MetadataToolingApiClient.cls): Salesforce API boundary · Calls same-org Tooling API through the SalesforceTooling Named Credential. · `force-app/main/default/classes/MetadataToolingApiClient.cls`
- [Metadata Catalog](https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/objects/Metadata_Item__c/Metadata_Item__c.object-meta.xml): custom object · Persisted normalized component index. · `force-app/main/default/objects/Metadata_Item__c/Metadata_Item__c.object-meta.xml`
- [Usage Graph](https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/objects/Metadata_Usage__c/Metadata_Usage__c.object-meta.xml): custom object · Persisted metadata usage edges. · `force-app/main/default/objects/Metadata_Usage__c/Metadata_Usage__c.object-meta.xml`
- **Metadata History**: snapshot storage · Snapshots and component versions.
- **Refresh Jobs**: Queueable Apex · Asynchronous refresh execution.

### Analysis Services

- **NL Resolution**: resolution service · Resolves names, labels, objects, and fields before execution.
- **Metadata Search**: search service · Searches persisted catalog and direct usage evidence.
- **Impact Analysis**: graph analysis · Traverses inbound and outbound usage with depth and cycle protection.
- **Documentation & Optimization**: generated analysis · Generates documentation requests and optimization findings from the catalog.

### Security Governance

- **Security Audit**: audit orchestration · Evaluates sensitive-field exposure and persists audit findings.
- [Sensitive Field Rules](https://github.com/krishnendubose-github/ai-metadata-copilot-salesforce-health-cloud/blob/main/force-app/main/default/objects/Sensitive_Field_Rule__mdt/Sensitive_Field_Rule__mdt.object-meta.xml): custom metadata · Configurable sensitive-field policy. · `force-app/main/default/objects/Sensitive_Field_Rule__mdt/Sensitive_Field_Rule__mdt.object-meta.xml`
- **Security Audit Results**: durable records · Audit runs and findings.

### Deployment Intelligence

- **Environment Comparison**: comparison pipeline · Captures environment snapshots and computes component deltas.
- **Deployment Risk Assessment**: readiness analysis · Produces readiness, findings, rollback checklist, and test guidance.
- **Deployment Assessment Results**: durable records · Comparison-only assessment and findings; never deploys.
- **Comparison Jobs**: Queueable Apex · Isolates long-running comparisons.

## Connections

- Copilot Workspace → Copilot Controller: Aura calls
- Copilot Controller → Agent Action Service: delegates requests
- Natural Language Action → Agent Action Service: natural-language requests
- Agent Action Service → NL Resolution: resolve inputs
- Agent Action Service → Metadata Search: search
- Agent Action Service → Impact Analysis: analyze impact
- Agent Action Service → Security Audit: run audit
- Agent Action Service → Environment Comparison: compare environments
- Refresh Jobs → Extraction Orchestrator: runs refresh
- Extraction Orchestrator → Tooling API Client: extract metadata
- Extraction Orchestrator → Metadata Catalog: normalize and index
- Extraction Orchestrator → Usage Graph: derive relationships
- Extraction Orchestrator → Metadata History: write history
- Metadata Search → Metadata Catalog: query indexed items
- Metadata Search → Usage Graph: direct relationships
- Impact Analysis → Usage Graph: traverse graph
- Documentation & Optimization → Metadata Catalog: consume index
- Security Audit → Sensitive Field Rules: apply policy
- Security Audit → Security Audit Results: persist findings
- Comparison Jobs → Environment Comparison: run comparison
- Environment Comparison → Deployment Risk Assessment: component deltas
- Deployment Risk Assessment → Deployment Assessment Results: persist assessment
- Action, Environment & Access Config → Agent Action Service: governs actions and access
