# vardhanreddy024/risklensai architecture

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

- Interactive diagram: https://gitdiagram.com/vardhanreddy024/risklensai
- Repository: https://github.com/vardhanreddy024/risklensai

## Overview

RiskLens AI turns payment events into explainable risk decisions, then supports merchant review through investigation, reporting, and audit history. The documented primary flow is Razorpay webhook verification and normalization, transaction persistence, fraud scoring and decisioning, followed by AI investigation and dashboard visibility. The graph also includes the broader transaction and investigation APIs, tenant-aware storage, and graph-based investigation capability. Some subsystems are represented by their exact enclosing directories because their implementation files were not sampled; those relationships are omitted where the excerpts and README do not establish them.

Main entry points: [`server/db/index.ts`](https://github.com/vardhanreddy024/risklensai/blob/main/server/db/index.ts) (Data Store), [`src/App.tsx`](https://github.com/vardhanreddy024/risklensai/blob/main/src/App.tsx) (Application Router), [`server/services/razorpay.service.ts`](https://github.com/vardhanreddy024/risklensai/blob/main/server/services/razorpay.service.ts) (Webhook Processing), [`server.ts`](https://github.com/vardhanreddy024/risklensai/blob/main/server.ts) (Server Runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Payment Ingestion"]
  node_server["Server Runtime<br/>[server.ts]"]
  node_webhook_routes["Webhook Routes<br/>[webhook.routes.ts]"]
  node_webhook_controller["Webhook Controller"]
  node_razorpay_service["Webhook Processing"]
  node_transaction_api["Transaction API"]
end

subgraph group_risk["Risk Intelligence"]
  node_fraud_engine["Fraud Scoring<br/>[ml_engine.ts]"]
  node_risk_decision["Risk Decisioning"]
end

subgraph group_investigation["Investigation"]
  node_investigation_service["Investigation Service"]
  node_agent_orchestrator["Agent Orchestrator<br/>[orchestrator.ts]"]
  node_investigation_agents["Investigation Agents"]
  node_case_retrieval["Similar Case Retrieval<br/>[case_retriever.ts]"]
  node_graph_analysis["Fraud Graph Analysis<br/>[graph_engine.ts]"]
end

subgraph group_storage["Persistence And Audit"]
  node_database[("Data Store<br/>[index.ts]")]
  node_store_adapters[("Storage Adapters")]
  node_repositories["Data Repositories"]
  node_audit_contract["Audit And Store Contracts"]
  node_operational["Logging And Metrics<br/>[middleware.ts]"]
end

subgraph group_workspace["Merchant Workspace"]
  node_dashboard["Merchant Dashboard<br/>[DashboardPage.tsx]"]
  node_investigation_ui["Investigation Workspace"]
  node_razorpay_ui["Payment Monitoring"]
  node_frontend_state["Transaction And Investigation State"]
  node_api_client["API Client<br/>[api.ts]"]
  node_auth["Merchant Authentication<br/>[AuthContext.tsx]"]
  node_app["Application Router<br/>[App.tsx]"]
end

node_razorpay(("Razorpay Test Mode"))
node_merchant(("Merchant User"))

node_razorpay -->|"sends events"| node_webhook_routes
node_server -->|"mounts routes"| node_webhook_routes
node_webhook_routes -->|"routes requests"| node_webhook_controller
node_webhook_controller -->|"handles events"| node_razorpay_service
node_razorpay_service -->|"claims and stores events"| node_database
node_razorpay_service -->|"scores transactions"| node_fraud_engine
node_razorpay_service -->|"starts investigation"| node_investigation_service
node_razorpay_service -->|"records metrics"| node_operational
node_server -->|"initializes"| node_database
node_server -->|"configures middleware"| node_operational
node_database -->|"selects adapter"| node_store_adapters
node_database -->|"creates repositories"| node_repositories
node_repositories -->|"implement contracts"| node_audit_contract
node_transaction_api -->|"reads and writes transactions"| node_database
node_transaction_api -->|"scores transactions"| node_fraud_engine
node_investigation_service -->|"orchestrates analysis"| node_agent_orchestrator
node_investigation_service -->|"persists dossiers"| node_database
node_agent_orchestrator -->|"dispatches agents"| node_investigation_agents
node_investigation_agents -.->|"retrieves cases"| node_case_retrieval
node_case_retrieval -.->|"uses graph analysis"| node_graph_analysis
node_merchant -->|"uses workspace"| node_app
node_app -->|"provides authentication"| node_auth
node_app -->|"provides application state"| node_frontend_state
node_app -->|"routes to"| node_dashboard
node_app -->|"routes to"| node_investigation_ui
node_app -->|"routes to"| node_razorpay_ui
node_frontend_state -->|"calls API"| node_api_client
node_frontend_state -->|"evaluates transactions"| node_fraud_engine
node_investigation_ui -.->|"displays graph insights"| node_graph_analysis
node_razorpay_ui -.->|"loads payment data"| node_api_client
node_api_client -.->|"requests backend data"| node_database

click node_server "https://github.com/vardhanreddy024/risklensai/blob/main/server.ts"
click node_webhook_routes "https://github.com/vardhanreddy024/risklensai/blob/main/server/routes/webhook.routes.ts"
click node_webhook_controller "https://github.com/vardhanreddy024/risklensai/blob/main/server/controllers/webhook.controller.ts"
click node_razorpay_service "https://github.com/vardhanreddy024/risklensai/blob/main/server/services/razorpay.service.ts"
click node_transaction_api "https://github.com/vardhanreddy024/risklensai/blob/main/server/services/transaction.service.ts"
click node_fraud_engine "https://github.com/vardhanreddy024/risklensai/blob/main/src/lib/ml_engine.ts"
click node_risk_decision "https://github.com/vardhanreddy024/risklensai/blob/main/server/services/razorpay.service.ts"
click node_investigation_service "https://github.com/vardhanreddy024/risklensai/blob/main/server/services/investigation.service.ts"
click node_agent_orchestrator "https://github.com/vardhanreddy024/risklensai/blob/main/server/agents/orchestrator.ts"
click node_investigation_agents "https://github.com/vardhanreddy024/risklensai/tree/main/server/agents"
click node_case_retrieval "https://github.com/vardhanreddy024/risklensai/blob/main/server/agents/case_retriever.ts"
click node_graph_analysis "https://github.com/vardhanreddy024/risklensai/blob/main/src/lib/graph_engine.ts"
click node_database "https://github.com/vardhanreddy024/risklensai/blob/main/server/db/index.ts"
click node_store_adapters "https://github.com/vardhanreddy024/risklensai/tree/main/server/db/adapters"
click node_repositories "https://github.com/vardhanreddy024/risklensai/tree/main/server/db/repositories"
click node_audit_contract "https://github.com/vardhanreddy024/risklensai/blob/main/server/db/interfaces/IDataStoreAdapter.ts"
click node_dashboard "https://github.com/vardhanreddy024/risklensai/blob/main/src/components/pages/DashboardPage.tsx"
click node_investigation_ui "https://github.com/vardhanreddy024/risklensai/blob/main/src/components/pages/InvestigationPage.tsx"
click node_razorpay_ui "https://github.com/vardhanreddy024/risklensai/blob/main/src/components/pages/RazorpayMonitorPage.tsx"
click node_frontend_state "https://github.com/vardhanreddy024/risklensai/blob/main/src/context/TransactionContext.tsx"
click node_api_client "https://github.com/vardhanreddy024/risklensai/blob/main/src/lib/api.ts"
click node_auth "https://github.com/vardhanreddy024/risklensai/blob/main/src/context/AuthContext.tsx"
click node_app "https://github.com/vardhanreddy024/risklensai/blob/main/src/App.tsx"
click node_operational "https://github.com/vardhanreddy024/risklensai/blob/main/server/middleware.ts"

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_server,node_webhook_routes,node_webhook_controller,node_razorpay_service,node_transaction_api,node_merchant toneBlue
class node_fraud_engine,node_risk_decision toneAmber
class node_investigation_service,node_agent_orchestrator,node_investigation_agents,node_case_retrieval,node_graph_analysis toneMint
class node_database,node_store_adapters,node_repositories,node_audit_contract,node_operational toneRose
class node_dashboard,node_investigation_ui,node_razorpay_ui,node_frontend_state,node_api_client,node_auth,node_app,node_razorpay toneIndigo
```

## Components

### Payment Ingestion

- [Server Runtime](https://github.com/vardhanreddy024/risklensai/blob/main/server.ts): `server.ts`
- [Webhook Routes](https://github.com/vardhanreddy024/risklensai/blob/main/server/routes/webhook.routes.ts): `server/routes/webhook.routes.ts`
- [Webhook Controller](https://github.com/vardhanreddy024/risklensai/blob/main/server/controllers/webhook.controller.ts): `server/controllers/webhook.controller.ts`
- [Webhook Processing](https://github.com/vardhanreddy024/risklensai/blob/main/server/services/razorpay.service.ts): `server/services/razorpay.service.ts`
- [Transaction API](https://github.com/vardhanreddy024/risklensai/blob/main/server/services/transaction.service.ts): `server/services/transaction.service.ts`

### Risk Intelligence

- [Fraud Scoring](https://github.com/vardhanreddy024/risklensai/blob/main/src/lib/ml_engine.ts): `src/lib/ml_engine.ts`
- [Risk Decisioning](https://github.com/vardhanreddy024/risklensai/blob/main/server/services/razorpay.service.ts): `server/services/razorpay.service.ts`

### Investigation

- [Investigation Service](https://github.com/vardhanreddy024/risklensai/blob/main/server/services/investigation.service.ts): `server/services/investigation.service.ts`
- [Agent Orchestrator](https://github.com/vardhanreddy024/risklensai/blob/main/server/agents/orchestrator.ts): `server/agents/orchestrator.ts`
- [Investigation Agents](https://github.com/vardhanreddy024/risklensai/tree/main/server/agents): `server/agents`
- [Similar Case Retrieval](https://github.com/vardhanreddy024/risklensai/blob/main/server/agents/case_retriever.ts): `server/agents/case_retriever.ts`
- [Fraud Graph Analysis](https://github.com/vardhanreddy024/risklensai/blob/main/src/lib/graph_engine.ts): `src/lib/graph_engine.ts`

### Persistence And Audit

- [Data Store](https://github.com/vardhanreddy024/risklensai/blob/main/server/db/index.ts): `server/db/index.ts`
- [Storage Adapters](https://github.com/vardhanreddy024/risklensai/tree/main/server/db/adapters): `server/db/adapters`
- [Data Repositories](https://github.com/vardhanreddy024/risklensai/tree/main/server/db/repositories): `server/db/repositories`
- [Audit And Store Contracts](https://github.com/vardhanreddy024/risklensai/blob/main/server/db/interfaces/IDataStoreAdapter.ts): `server/db/interfaces/IDataStoreAdapter.ts`
- [Logging And Metrics](https://github.com/vardhanreddy024/risklensai/blob/main/server/middleware.ts): `server/middleware.ts`

### Merchant Workspace

- [Merchant Dashboard](https://github.com/vardhanreddy024/risklensai/blob/main/src/components/pages/DashboardPage.tsx): `src/components/pages/DashboardPage.tsx`
- [Investigation Workspace](https://github.com/vardhanreddy024/risklensai/blob/main/src/components/pages/InvestigationPage.tsx): `src/components/pages/InvestigationPage.tsx`
- [Payment Monitoring](https://github.com/vardhanreddy024/risklensai/blob/main/src/components/pages/RazorpayMonitorPage.tsx): `src/components/pages/RazorpayMonitorPage.tsx`
- [Transaction And Investigation State](https://github.com/vardhanreddy024/risklensai/blob/main/src/context/TransactionContext.tsx): `src/context/TransactionContext.tsx`
- [API Client](https://github.com/vardhanreddy024/risklensai/blob/main/src/lib/api.ts): `src/lib/api.ts`
- [Merchant Authentication](https://github.com/vardhanreddy024/risklensai/blob/main/src/context/AuthContext.tsx): `src/context/AuthContext.tsx`
- [Application Router](https://github.com/vardhanreddy024/risklensai/blob/main/src/App.tsx): `src/App.tsx`

### Other components

- **Razorpay Test Mode**
- **Merchant User**

## Connections

- Razorpay Test Mode → Webhook Routes: sends events
- Server Runtime → Webhook Routes: mounts routes (evidence: `server.ts`)
- Webhook Routes → Webhook Controller: routes requests (evidence: `server/routes/webhook.routes.ts`)
- Webhook Controller → Webhook Processing: handles events (evidence: `server/controllers/webhook.controller.ts`)
- Webhook Processing → Data Store: claims and stores events (evidence: `server/services/razorpay.service.ts`)
- Webhook Processing → Fraud Scoring: scores transactions (evidence: `server/services/razorpay.service.ts`)
- Webhook Processing → Investigation Service: starts investigation (evidence: `server/services/razorpay.service.ts`)
- Webhook Processing → Logging And Metrics: records metrics (evidence: `server/services/razorpay.service.ts`)
- Server Runtime → Data Store: initializes (evidence: `server.ts`)
- Server Runtime → Logging And Metrics: configures middleware (evidence: `server.ts`)
- Data Store → Storage Adapters: selects adapter (evidence: `server/db/index.ts`)
- Data Store → Data Repositories: creates repositories (evidence: `server/db/index.ts`)
- Data Repositories → Audit And Store Contracts: implement contracts (evidence: `server/db/repositories/AuditLogRepository.ts`)
- Transaction API → Data Store: reads and writes transactions (evidence: `server/services/transaction.service.ts`)
- Transaction API → Fraud Scoring: scores transactions (evidence: `server/services/transaction.service.ts`)
- Investigation Service → Agent Orchestrator: orchestrates analysis (evidence: `server/services/investigation.service.ts`)
- Investigation Service → Data Store: persists dossiers (evidence: `server/services/investigation.service.ts`)
- Agent Orchestrator → Investigation Agents: dispatches agents (evidence: `server/agents/orchestrator.ts`)
- Investigation Agents → Similar Case Retrieval: retrieves cases (evidence: `server/agents/orchestrator.ts`)
- Similar Case Retrieval → Fraud Graph Analysis: uses graph analysis
- Merchant User → Application Router: uses workspace
- Application Router → Merchant Authentication: provides authentication (evidence: `src/App.tsx`)
- Application Router → Transaction And Investigation State: provides application state (evidence: `src/App.tsx`)
- Application Router → Merchant Dashboard: routes to (evidence: `src/App.tsx`)
- Application Router → Investigation Workspace: routes to (evidence: `src/App.tsx`)
- Application Router → Payment Monitoring: routes to (evidence: `src/App.tsx`)
- Transaction And Investigation State → API Client: calls API (evidence: `src/context/TransactionContext.tsx`)
- Transaction And Investigation State → Fraud Scoring: evaluates transactions (evidence: `src/context/TransactionContext.tsx`)
- Investigation Workspace → Fraud Graph Analysis: displays graph insights
- Payment Monitoring → API Client: loads payment data
- API Client → Data Store: requests backend data
