# kyathamkarthik/klyro-backend architecture

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

- Interactive diagram: https://gitdiagram.com/kyathamkarthik/klyro-backend
- Repository: https://github.com/kyathamkarthik/klyro-backend

## Overview

Klyro is an SAP Integration Suite monitoring and autonomous-recovery service. Tenant setup and API requests enter through FastAPI; a background agent polls connected tenants, classifies failed logs, obtains AI diagnoses, applies recovery policy, and may retry, queue approval, or escalate. It records audits and usage, while separate endpoints expose log retrieval, diagnosis, and manual retriggering. The shown sources establish these control paths; no README was provided, so undocumented capabilities and unshown integrations are omitted.

Main entry points: [`automation_worker.py`](https://github.com/kyathamkarthik/klyro-backend/blob/main/automation_worker.py) (Autonomous Agent), [`main.py`](https://github.com/kyathamkarthik/klyro-backend/blob/main/main.py) (FastAPI Engine), [`sap_connector.py`](https://github.com/kyathamkarthik/klyro-backend/blob/main/sap_connector.py) (SAP Connector), [`llm_service.py`](https://github.com/kyathamkarthik/klyro-backend/blob/main/llm_service.py) (AI Diagnosis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and Tenants"]
  node_api["FastAPI Engine<br/>[main.py]"]
  node_schemas["Request Schemas<br/>[schemas.py]"]
end

subgraph group_recovery["Recovery Workflow"]
  node_worker["Autonomous Agent"]
  node_classifier["Failure Classifier"]
  node_diagnosis["AI Diagnosis<br/>[llm_service.py]"]
  node_security["PII Masking<br/>[security_utils.py]"]
end

subgraph group_integrations["Integrations"]
  node_sap["SAP Connector<br/>[sap_connector.py]"]
  node_supabase[("Supabase")]
end

subgraph group_governance["Policy and Billing"]
  node_policy["Recovery Policy<br/>[policy_engine.py]"]
  node_billing["Credit Calculation<br/>[billing_service.py]"]
end

node_user(("API Client"))
node_sapservice["SAP Integration Suite"]
node_models["LLM Providers"]

node_user -->|"calls API"| node_api
node_api -->|"validates requests"| node_schemas
node_api -->|"starts agent"| node_worker
node_api -->|"tests and fetches"| node_sap
node_api -->|"retrigger request"| node_sap
node_api -->|"requests diagnosis"| node_diagnosis
node_api -->|"stores credentials"| node_supabase
node_worker -->|"reads tenant registry"| node_api
node_worker -->|"fetches logs and payloads"| node_sap
node_worker -->|"classifies failures"| node_classifier
node_worker -->|"requests diagnosis"| node_diagnosis
node_worker -->|"evaluates recovery"| node_policy
node_worker -->|"retries messages"| node_sap
node_worker -->|"queues and audits"| node_supabase
node_worker -->|"calculates credits"| node_billing
node_policy -->|"uses categories"| node_classifier
node_diagnosis -->|"masks inputs"| node_security
node_diagnosis -->|"invokes model"| node_models
node_sap -->|"calls SAP APIs"| node_sapservice

click node_api "https://github.com/kyathamkarthik/klyro-backend/blob/main/main.py"
click node_schemas "https://github.com/kyathamkarthik/klyro-backend/blob/main/schemas.py"
click node_worker "https://github.com/kyathamkarthik/klyro-backend/blob/main/automation_worker.py"
click node_classifier "https://github.com/kyathamkarthik/klyro-backend/blob/main/classifier_service.py"
click node_diagnosis "https://github.com/kyathamkarthik/klyro-backend/blob/main/llm_service.py"
click node_security "https://github.com/kyathamkarthik/klyro-backend/blob/main/security_utils.py"
click node_policy "https://github.com/kyathamkarthik/klyro-backend/blob/main/policy_engine.py"
click node_billing "https://github.com/kyathamkarthik/klyro-backend/blob/main/billing_service.py"
click node_sap "https://github.com/kyathamkarthik/klyro-backend/blob/main/sap_connector.py"

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_api,node_schemas,node_user toneBlue
class node_worker,node_classifier,node_diagnosis,node_security toneAmber
class node_sap,node_supabase toneMint
class node_policy,node_billing toneRose
class node_sapservice,node_models toneIndigo
```

## Components

### API and Tenants

- [FastAPI Engine](https://github.com/kyathamkarthik/klyro-backend/blob/main/main.py): `main.py`
- [Request Schemas](https://github.com/kyathamkarthik/klyro-backend/blob/main/schemas.py): `schemas.py`

### Recovery Workflow

- [Autonomous Agent](https://github.com/kyathamkarthik/klyro-backend/blob/main/automation_worker.py): `automation_worker.py`
- [Failure Classifier](https://github.com/kyathamkarthik/klyro-backend/blob/main/classifier_service.py): `classifier_service.py`
- [AI Diagnosis](https://github.com/kyathamkarthik/klyro-backend/blob/main/llm_service.py): `llm_service.py`
- [PII Masking](https://github.com/kyathamkarthik/klyro-backend/blob/main/security_utils.py): `security_utils.py`

### Integrations

- [SAP Connector](https://github.com/kyathamkarthik/klyro-backend/blob/main/sap_connector.py): `sap_connector.py`
- **Supabase**

### Policy and Billing

- [Recovery Policy](https://github.com/kyathamkarthik/klyro-backend/blob/main/policy_engine.py): `policy_engine.py`
- [Credit Calculation](https://github.com/kyathamkarthik/klyro-backend/blob/main/billing_service.py): `billing_service.py`

### Other components

- **API Client**
- **SAP Integration Suite**
- **LLM Providers**

## Connections

- API Client → FastAPI Engine: calls API (evidence: `main.py`)
- FastAPI Engine → Request Schemas: validates requests (evidence: `main.py`)
- FastAPI Engine → Autonomous Agent: starts agent (evidence: `main.py`)
- FastAPI Engine → SAP Connector: tests and fetches (evidence: `main.py`)
- FastAPI Engine → SAP Connector: retrigger request (evidence: `main.py`)
- FastAPI Engine → AI Diagnosis: requests diagnosis (evidence: `main.py`)
- FastAPI Engine → Supabase: stores credentials (evidence: `main.py`)
- Autonomous Agent → FastAPI Engine: reads tenant registry (evidence: `automation_worker.py`)
- Autonomous Agent → SAP Connector: fetches logs and payloads (evidence: `automation_worker.py`)
- Autonomous Agent → Failure Classifier: classifies failures (evidence: `automation_worker.py`)
- Autonomous Agent → AI Diagnosis: requests diagnosis (evidence: `automation_worker.py`)
- Autonomous Agent → Recovery Policy: evaluates recovery (evidence: `automation_worker.py`)
- Autonomous Agent → SAP Connector: retries messages (evidence: `automation_worker.py`)
- Autonomous Agent → Supabase: queues and audits (evidence: `automation_worker.py`)
- Autonomous Agent → Credit Calculation: calculates credits (evidence: `automation_worker.py`)
- Recovery Policy → Failure Classifier: uses categories (evidence: `policy_engine.py`)
- AI Diagnosis → PII Masking: masks inputs (evidence: `llm_service.py`)
- AI Diagnosis → LLM Providers: invokes model (evidence: `llm_service.py`)
- SAP Connector → SAP Integration Suite: calls SAP APIs (evidence: `sap_connector.py`)
