# neptune-glitch/razorpay-agent architecture

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

- Interactive diagram: https://gitdiagram.com/neptune-glitch/razorpay-agent
- Repository: https://github.com/neptune-glitch/razorpay-agent

## Overview

The sampled runtime implements a Streamlit AI upsell and cross-sell demo: an operator selects a customer for an AI reorder decision or scans all customers for a discount campaign, then views an audit trail. Purchase-history prediction informs both paths; the agent can choose an order or no action, while campaign matches can generate discounted orders. Order creation applies guardrails and records outcomes. The supplied README describes a different fraud-risk product and a different file layout, so its capabilities are not mapped here. Evidence is limited to the supplied excerpts and source index.

Main entry points: [`campaign.py`](https://github.com/neptune-glitch/razorpay-agent/blob/main/campaign.py) (Campaign scan), [`db.py`](https://github.com/neptune-glitch/razorpay-agent/blob/main/db.py) (Database access), [`app.py`](https://github.com/neptune-glitch/razorpay-agent/blob/main/app.py) (Streamlit app), [`agent.py`](https://github.com/neptune-glitch/razorpay-agent/blob/main/agent.py) (Upsell agent)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Operator interface"]
  node_app["Streamlit app<br/>[app.py]"]
end

subgraph group_decision["Purchase decisions"]
  node_agent["Upsell agent<br/>[agent.py]"]
  node_predictor["Reorder predictor<br/>[predictor.py]"]
  node_campaign["Campaign scan<br/>[campaign.py]"]
end

subgraph group_commerce["Order execution"]
  node_order["Order client<br/>[razorpay_client.py]"]
end

subgraph group_data["Persistence"]
  node_db_access["Database access<br/>[db.py]"]
  node_postgres[("PostgreSQL")]
end

node_operator(("Operator"))
node_gemini{{"Gemini API"}}
node_razorpay{{"Razorpay"}}

node_operator -->|"uses"| node_app
node_app -->|"runs agent"| node_agent
node_app -->|"runs scan"| node_campaign
node_app -->|"lists customers"| node_campaign
node_app -->|"reads logs"| node_db_access
node_agent -->|"gets prediction"| node_predictor
node_agent -->|"lists customers"| node_campaign
node_agent -->|"requests decision"| node_gemini
node_agent -->|"creates order"| node_order
node_campaign -->|"lists customers"| node_db_access
node_campaign -->|"gets predictions"| node_predictor
node_campaign -->|"creates orders"| node_order
node_campaign -->|"logs campaign"| node_db_access
node_predictor -->|"reads purchases"| node_db_access
node_order -->|"creates order"| node_razorpay
node_order -->|"logs outcome"| node_db_access
node_db_access -->|"queries and writes"| node_postgres

click node_app "https://github.com/neptune-glitch/razorpay-agent/blob/main/app.py"
click node_agent "https://github.com/neptune-glitch/razorpay-agent/blob/main/agent.py"
click node_predictor "https://github.com/neptune-glitch/razorpay-agent/blob/main/predictor.py"
click node_campaign "https://github.com/neptune-glitch/razorpay-agent/blob/main/campaign.py"
click node_order "https://github.com/neptune-glitch/razorpay-agent/blob/main/razorpay_client.py"
click node_db_access "https://github.com/neptune-glitch/razorpay-agent/blob/main/db.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_app toneBlue
class node_agent,node_predictor,node_campaign toneAmber
class node_order,node_gemini toneMint
class node_db_access,node_postgres toneRose
class node_operator,node_razorpay toneIndigo
```

## Components

### Operator interface

- [Streamlit app](https://github.com/neptune-glitch/razorpay-agent/blob/main/app.py): `app.py`

### Purchase decisions

- [Upsell agent](https://github.com/neptune-glitch/razorpay-agent/blob/main/agent.py): `agent.py`
- [Reorder predictor](https://github.com/neptune-glitch/razorpay-agent/blob/main/predictor.py): `predictor.py`
- [Campaign scan](https://github.com/neptune-glitch/razorpay-agent/blob/main/campaign.py): `campaign.py`

### Order execution

- [Order client](https://github.com/neptune-glitch/razorpay-agent/blob/main/razorpay_client.py): `razorpay_client.py`

### Persistence

- [Database access](https://github.com/neptune-glitch/razorpay-agent/blob/main/db.py): `db.py`
- **PostgreSQL**

### Other components

- **Operator**
- **Gemini API**
- **Razorpay**

## Connections

- Operator → Streamlit app: uses (evidence: `app.py`)
- Streamlit app → Upsell agent: runs agent (evidence: `app.py`)
- Streamlit app → Campaign scan: runs scan (evidence: `app.py`)
- Streamlit app → Campaign scan: lists customers (evidence: `app.py`)
- Streamlit app → Database access: reads logs (evidence: `app.py`)
- Upsell agent → Reorder predictor: gets prediction (evidence: `agent.py`)
- Upsell agent → Campaign scan: lists customers (evidence: `agent.py`)
- Upsell agent → Gemini API: requests decision (evidence: `agent.py`)
- Upsell agent → Order client: creates order (evidence: `agent.py`)
- Campaign scan → Database access: lists customers (evidence: `campaign.py`)
- Campaign scan → Reorder predictor: gets predictions (evidence: `campaign.py`)
- Campaign scan → Order client: creates orders (evidence: `campaign.py`)
- Campaign scan → Database access: logs campaign (evidence: `campaign.py`)
- Reorder predictor → Database access: reads purchases (evidence: `predictor.py`)
- Order client → Razorpay: creates order (evidence: `razorpay_client.py`)
- Order client → Database access: logs outcome (evidence: `razorpay_client.py`)
- Database access → PostgreSQL: queries and writes (evidence: `db.py`)
