# aru-0504/chargeguard architecture

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

- Interactive diagram: https://gitdiagram.com/aru-0504/chargeguard
- Repository: https://github.com/aru-0504/chargeguard

## Overview

ChargeGuard is a chargeback review workspace. A reviewer submits transaction details through the dashboard; the API scores the transaction, explains and records the decision, and supports case review, outcome tracking, and audit history. For fight decisions, the API can invoke the evidence workflow, whose draft can be reviewed, saved, and exported. Model inspection and retraining are supporting capabilities. Edges reflect the excerpts and README; unsampled route internals are not inferred.

Main entry points: [`backend/app/main.py`](https://github.com/aru-0504/chargeguard/blob/main/backend/app/main.py) (FastAPI routes), [`backend/retrain_model.py`](https://github.com/aru-0504/chargeguard/blob/main/backend/retrain_model.py) (Model retraining), [`frontend/src/app/page.tsx`](https://github.com/aru-0504/chargeguard/blob/main/frontend/src/app/page.tsx) (Review dashboard), [`backend/app/db.py`](https://github.com/aru-0504/chargeguard/blob/main/backend/app/db.py) (Database access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_review["Review workspace"]
  node_dashboard["Review dashboard<br/>[page.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
  node_pdf_export["PDF export<br/>[page.tsx]"]
end

subgraph group_service["Scoring service"]
  node_fastapi["FastAPI routes<br/>[main.py]"]
  node_serving_model["Fraud model"]
  node_model_metrics["Model metrics<br/>[metrics.json]"]
  node_case_schema["Case records<br/>[models.py]"]
  node_db_access["Database access<br/>[db.py]"]
  node_case_store[("Case database<br/>[db.py]")]
end

subgraph group_evidence["Evidence workflow"]
  node_evidence_agent["Evidence agent<br/>[evidence_agent.py]"]
end

subgraph group_operations["Model operations"]
  node_retraining["Model retraining<br/>[retrain_model.py]"]
  node_training_data["Training data"]
end

node_reviewer(("Reviewer"))
node_openai{{"OpenAI"}}

node_reviewer -->|"uses"| node_dashboard
node_dashboard -->|"requests data"| node_api_client
node_api_client -->|"HTTP requests"| node_fastapi
node_fastapi -->|"scores with"| node_serving_model
node_fastapi -->|"loads settings"| node_model_metrics
node_fastapi -->|"uses sessions"| node_db_access
node_db_access -->|"initializes tables"| node_case_schema
node_fastapi -->|"records cases"| node_case_schema
node_fastapi -->|"invokes"| node_evidence_agent
node_evidence_agent -.->|"drafts with"| node_openai
node_dashboard -->|"exports PDF"| node_pdf_export
node_retraining -->|"trains from"| node_training_data
node_retraining -->|"registers versions"| node_db_access
node_retraining -->|"reads outcomes"| node_case_schema

click node_dashboard "https://github.com/aru-0504/chargeguard/blob/main/frontend/src/app/page.tsx"
click node_api_client "https://github.com/aru-0504/chargeguard/blob/main/frontend/src/lib/api.ts"
click node_fastapi "https://github.com/aru-0504/chargeguard/blob/main/backend/app/main.py"
click node_serving_model "https://github.com/aru-0504/chargeguard/blob/main/backend/app/chargeback_model.pkl"
click node_model_metrics "https://github.com/aru-0504/chargeguard/blob/main/backend/app/metrics.json"
click node_case_schema "https://github.com/aru-0504/chargeguard/blob/main/backend/app/models.py"
click node_db_access "https://github.com/aru-0504/chargeguard/blob/main/backend/app/db.py"
click node_case_store "https://github.com/aru-0504/chargeguard/blob/main/backend/app/db.py"
click node_evidence_agent "https://github.com/aru-0504/chargeguard/blob/main/agent/evidence_agent.py"
click node_pdf_export "https://github.com/aru-0504/chargeguard/blob/main/frontend/src/app/page.tsx"
click node_retraining "https://github.com/aru-0504/chargeguard/blob/main/backend/retrain_model.py"
click node_training_data "https://github.com/aru-0504/chargeguard/tree/main/ml/data"

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_dashboard,node_api_client,node_pdf_export,node_reviewer toneBlue
class node_fastapi,node_serving_model,node_model_metrics,node_case_schema,node_db_access,node_case_store toneAmber
class node_evidence_agent toneMint
class node_retraining,node_training_data toneRose
class node_openai toneIndigo
```

## Components

### Review workspace

- [Review dashboard](https://github.com/aru-0504/chargeguard/blob/main/frontend/src/app/page.tsx): `frontend/src/app/page.tsx`
- [API client](https://github.com/aru-0504/chargeguard/blob/main/frontend/src/lib/api.ts): `frontend/src/lib/api.ts`
- [PDF export](https://github.com/aru-0504/chargeguard/blob/main/frontend/src/app/page.tsx): `frontend/src/app/page.tsx`

### Scoring service

- [FastAPI routes](https://github.com/aru-0504/chargeguard/blob/main/backend/app/main.py): `backend/app/main.py`
- [Fraud model](https://github.com/aru-0504/chargeguard/blob/main/backend/app/chargeback_model.pkl): `backend/app/chargeback_model.pkl`
- [Model metrics](https://github.com/aru-0504/chargeguard/blob/main/backend/app/metrics.json): `backend/app/metrics.json`
- [Case records](https://github.com/aru-0504/chargeguard/blob/main/backend/app/models.py): `backend/app/models.py`
- [Database access](https://github.com/aru-0504/chargeguard/blob/main/backend/app/db.py): `backend/app/db.py`
- [Case database](https://github.com/aru-0504/chargeguard/blob/main/backend/app/db.py): `backend/app/db.py`

### Evidence workflow

- [Evidence agent](https://github.com/aru-0504/chargeguard/blob/main/agent/evidence_agent.py): `agent/evidence_agent.py`

### Model operations

- [Model retraining](https://github.com/aru-0504/chargeguard/blob/main/backend/retrain_model.py): `backend/retrain_model.py`
- [Training data](https://github.com/aru-0504/chargeguard/tree/main/ml/data): `ml/data`

### Other components

- **Reviewer**
- **OpenAI**

## Connections

- Reviewer → Review dashboard: uses (evidence: `README.md`)
- Review dashboard → API client: requests data (evidence: `frontend/src/app/page.tsx`)
- API client → FastAPI routes: HTTP requests (evidence: `README.md`)
- FastAPI routes → Fraud model: scores with (evidence: `README.md`)
- FastAPI routes → Model metrics: loads settings (evidence: `backend/app/main.py`)
- FastAPI routes → Database access: uses sessions (evidence: `backend/app/main.py`)
- Database access → Case records: initializes tables (evidence: `backend/app/db.py`)
- FastAPI routes → Case records: records cases (evidence: `README.md`)
- FastAPI routes → Evidence agent: invokes (evidence: `backend/app/main.py`)
- Evidence agent → OpenAI: drafts with (evidence: `agent/evidence_agent.py`)
- Review dashboard → PDF export: exports PDF (evidence: `frontend/src/app/page.tsx`)
- Model retraining → Training data: trains from (evidence: `README.md`)
- Model retraining → Database access: registers versions (evidence: `backend/retrain_model.py`)
- Model retraining → Case records: reads outcomes (evidence: `backend/retrain_model.py`)
