# b-mohid/ondc-tax-split-engine architecture

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

- Interactive diagram: https://gitdiagram.com/b-mohid/ondc-tax-split-engine
- Repository: https://github.com/b-mohid/ondc-tax-split-engine

## Overview

The ONDC Tax Split Engine accepts `on_confirm` requests and coordinates validation, dependency resolution, tax calculation, payouts, ledgering, and compliance queuing. Its FastAPI API is the main entry point; an orchestrator owns the processing actions, including compensation after payout failures. The README documents the end-to-end stages and fallback behavior; sampled source confirms key calls and storage behavior. Some internal wiring is unsampled, so the graph omits uncertain links rather than inferring them.

Main entry points: [`app/services/orchestrator.py`](https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/services/orchestrator.py) (Processing orchestrator), [`app/api/main.py`](https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/api/main.py) (FastAPI endpoints), [`app/compliance/service.py`](https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/compliance/service.py) (Compliance outbox), [`app/infrastructure/database.py`](https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/infrastructure/database.py) (SQLite database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Request entry"]
  node_api["FastAPI endpoints<br/>[main.py]"]
end

subgraph group_processing["Settlement processing"]
  node_orchestrator["Processing orchestrator<br/>[orchestrator.py]"]
  node_ingestion["Payload ingestion<br/>[service.py]"]
  node_idempotency[("Idempotency store<br/>[idempotency.py]")]
  node_resolver["Dependency resolver<br/>[resolver.py]"]
  node_tax["Tax engine<br/>[engine.py]"]
  node_split["Split execution<br/>[engine.py]"]
end

subgraph group_financial["Financial records"]
  node_ledger["Settlement ledger<br/>[service.py]"]
  node_compliance["Compliance outbox<br/>[service.py]"]
  node_database[("SQLite database<br/>[database.py]")]
end

subgraph group_domain["Domain and integrations"]
  node_gstn_client["GSTN client<br/>[gstn_client.py]"]
  node_payout_provider["Payout provider<br/>[provider.py]"]
  node_models["Domain models<br/>[models.py]"]
end

node_ondc(("ONDC sender"))
node_api_client(("API client"))
node_gstn_service["GSTN service"]
node_payout_network["Payout network"]

node_ondc -->|"submits event"| node_api
node_api_client -->|"calls endpoints"| node_api
node_api -->|"processes request"| node_orchestrator
node_api -->|"reads entries"| node_ledger
node_api -->|"reads queue"| node_compliance
node_api -->|"reads records"| node_idempotency
node_orchestrator -->|"validates payload"| node_ingestion
node_ingestion -->|"checks and stores"| node_idempotency
node_orchestrator -->|"resolves graph"| node_resolver
node_orchestrator -->|"computes taxes"| node_tax
node_tax -->|"looks up rates"| node_gstn_client
node_gstn_client -.->|"requests rates"| node_gstn_service
node_orchestrator -->|"executes splits"| node_split
node_split -->|"executes or reverses"| node_payout_provider
node_payout_provider -.->|"sends payouts"| node_payout_network
node_orchestrator -->|"writes settlement"| node_ledger
node_orchestrator -->|"enqueues filings"| node_compliance
node_ledger -->|"persists entries"| node_database
node_compliance -->|"stores outbox rows"| node_database
node_database -->|"initializes schema"| node_compliance

click node_api "https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/api/main.py"
click node_orchestrator "https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/services/orchestrator.py"
click node_ingestion "https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/ingestion/service.py"
click node_idempotency "https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/infrastructure/idempotency.py"
click node_resolver "https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/graph/resolver.py"
click node_tax "https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/tax/engine.py"
click node_gstn_client "https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/services/gstn_client.py"
click node_split "https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/split/engine.py"
click node_payout_provider "https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/settlement/provider.py"
click node_ledger "https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/compliance/service.py"
click node_compliance "https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/compliance/service.py"
click node_database "https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/infrastructure/database.py"
click node_models "https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/domain/models.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_api_client toneBlue
class node_orchestrator,node_ingestion,node_idempotency,node_resolver,node_tax,node_split toneAmber
class node_ledger,node_compliance,node_database toneMint
class node_gstn_client,node_payout_provider,node_models toneRose
class node_ondc,node_gstn_service,node_payout_network toneIndigo
```

## Components

### Request entry

- [FastAPI endpoints](https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/api/main.py): `app/api/main.py`

### Settlement processing

- [Processing orchestrator](https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/services/orchestrator.py): `app/services/orchestrator.py`
- [Payload ingestion](https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/ingestion/service.py): `app/ingestion/service.py`
- [Idempotency store](https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/infrastructure/idempotency.py): `app/infrastructure/idempotency.py`
- [Dependency resolver](https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/graph/resolver.py): `app/graph/resolver.py`
- [Tax engine](https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/tax/engine.py): `app/tax/engine.py`
- [Split execution](https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/split/engine.py): `app/split/engine.py`

### Financial records

- [Settlement ledger](https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/compliance/service.py): `app/compliance/service.py`
- [Compliance outbox](https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/compliance/service.py): `app/compliance/service.py`
- [SQLite database](https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/infrastructure/database.py): `app/infrastructure/database.py`

### Domain and integrations

- [GSTN client](https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/services/gstn_client.py): `app/services/gstn_client.py`
- [Payout provider](https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/settlement/provider.py): `app/settlement/provider.py`
- [Domain models](https://github.com/b-mohid/ondc-tax-split-engine/blob/main/app/domain/models.py): `app/domain/models.py`

### Other components

- **ONDC sender**
- **API client**
- **GSTN service**
- **Payout network**

## Connections

- ONDC sender → FastAPI endpoints: submits event (evidence: `README.md`)
- API client → FastAPI endpoints: calls endpoints (evidence: `README.md`)
- FastAPI endpoints → Processing orchestrator: processes request (evidence: `app/api/main.py`)
- FastAPI endpoints → Settlement ledger: reads entries (evidence: `app/api/main.py`)
- FastAPI endpoints → Compliance outbox: reads queue (evidence: `app/api/main.py`)
- FastAPI endpoints → Idempotency store: reads records (evidence: `app/api/main.py`)
- Processing orchestrator → Payload ingestion: validates payload (evidence: `app/services/orchestrator.py`)
- Payload ingestion → Idempotency store: checks and stores (evidence: `app/ingestion/service.py`)
- Processing orchestrator → Dependency resolver: resolves graph (evidence: `README.md`)
- Processing orchestrator → Tax engine: computes taxes (evidence: `app/services/orchestrator.py`)
- Tax engine → GSTN client: looks up rates (evidence: `app/tax/engine.py`)
- GSTN client → GSTN service: requests rates (evidence: `app/services/gstn_client.py`)
- Processing orchestrator → Split execution: executes splits (evidence: `app/services/orchestrator.py`)
- Split execution → Payout provider: executes or reverses (evidence: `app/split/engine.py`)
- Payout provider → Payout network: sends payouts (evidence: `README.md`)
- Processing orchestrator → Settlement ledger: writes settlement (evidence: `app/services/orchestrator.py`)
- Processing orchestrator → Compliance outbox: enqueues filings (evidence: `app/services/orchestrator.py`)
- Settlement ledger → SQLite database: persists entries (evidence: `app/compliance/service.py`)
- Compliance outbox → SQLite database: stores outbox rows (evidence: `app/compliance/service.py`)
- SQLite database → Compliance outbox: initializes schema (evidence: `app/infrastructure/database.py`)
