# amruthaa77/greenpay architecture

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

- Interactive diagram: https://gitdiagram.com/amruthaa77/greenpay
- Repository: https://github.com/amruthaa77/greenpay

## Overview

GreenPay is a municipal waste-accountability platform connecting residents and supervisors through verified collection records, transparent rewards, citizen identity, and ward intelligence. The principal workflow is resident sign-in or registration, supervisor verification and weighment, reward and anomaly processing, then resident tracking of waste history, wallet, impact, and redemptions. Administrators also manage users, waste, rewards, anomalies, audit records, and ward analytics. The graph combines sampled code with README-documented capabilities; several unsampled API and page relationships are therefore documented rather than source-verified.

Main entry points: [`backend/app/models`](https://github.com/amruthaa77/greenpay/tree/main/backend/app/models) (Domain records), [`frontend/src/services/api.ts`](https://github.com/amruthaa77/greenpay/blob/main/frontend/src/services/api.ts) (API client), [`frontend/src/App.tsx`](https://github.com/amruthaa77/greenpay/blob/main/frontend/src/App.tsx) (Route application), [`backend/app/api/v1/admin.py`](https://github.com/amruthaa77/greenpay/blob/main/backend/app/api/v1/admin.py) (Admin routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Frontend experience"]
  node_app["Route application<br/>[App.tsx]"]
  node_authctx["Session context<br/>[AuthContext.tsx]"]
  node_offline["Offline sync<br/>[OfflineContext.tsx]"]
  node_clientapi["API client<br/>[api.ts]"]
  node_citizenpages["Citizen portal"]
  node_adminpages["Admin console"]
  node_scan["QR verification"]
end

subgraph group_api["API and identity"]
  node_backend["FastAPI application<br/>[main.py]"]
  node_authapi["Authentication routes<br/>[auth.py]"]
end

subgraph group_operations["Municipal operations"]
  node_adminapi["Admin routes<br/>[admin.py]"]
  node_audit["Audit logging<br/>[audit_service.py]"]
end

subgraph group_insights["Rewards and intelligence"]
  node_rewardapi["Reward routes<br/>[rewards.py]"]
  node_rewardengine["Reward calculation<br/>[reward_engine.py]"]
  node_anomaly["Anomaly detection<br/>[anomaly_service.py]"]
  node_impact["Impact analytics<br/>[impact_service.py]"]
  node_forecast["Waste forecasting"]
end

subgraph group_persistence["Persistence"]
  node_domain["Domain records"]
  node_db["Database session<br/>[database.py]"]
  node_store[("Relational database")]
end

node_citizen(("Citizen"))
node_supervisor(("Supervisor"))

node_citizen -->|"uses portal"| node_app
node_supervisor -->|"uses console"| node_app
node_app -->|"provides session"| node_authctx
node_app -->|"routes to"| node_citizenpages
node_app -->|"routes to"| node_adminpages
node_authctx -->|"calls"| node_clientapi
node_offline -->|"syncs through"| node_clientapi
node_citizenpages -->|"requests data"| node_clientapi
node_adminpages -->|"requests data"| node_clientapi
node_scan -->|"looks up citizen"| node_clientapi
node_clientapi -.->|"sends REST requests"| node_backend
node_backend -->|"mounts routes"| node_authapi
node_backend -->|"creates tables"| node_db
node_authapi -->|"queries and updates"| node_domain
node_authapi -->|"records actions"| node_audit
node_adminapi -.->|"manages records"| node_domain
node_adminapi -.->|"processes weighment"| node_rewardengine
node_adminapi -.->|"checks volume"| node_anomaly
node_adminapi -.->|"logs administration"| node_audit
node_rewardapi -.->|"handles rewards"| node_rewardengine
node_rewardengine -->|"uses reward and waste records"| node_domain
node_anomaly -->|"reads waste records"| node_domain
node_impact -->|"reads waste records"| node_domain
node_forecast -->|"reads waste records"| node_domain
node_audit -->|"writes audit records"| node_domain
node_db -->|"opens sessions"| node_store
node_domain -.->|"persists entities"| node_store

click node_app "https://github.com/amruthaa77/greenpay/blob/main/frontend/src/App.tsx"
click node_authctx "https://github.com/amruthaa77/greenpay/blob/main/frontend/src/context/AuthContext.tsx"
click node_offline "https://github.com/amruthaa77/greenpay/blob/main/frontend/src/context/OfflineContext.tsx"
click node_clientapi "https://github.com/amruthaa77/greenpay/blob/main/frontend/src/services/api.ts"
click node_citizenpages "https://github.com/amruthaa77/greenpay/tree/main/frontend/src/pages"
click node_adminpages "https://github.com/amruthaa77/greenpay/tree/main/frontend/src/pages"
click node_scan "https://github.com/amruthaa77/greenpay/blob/main/frontend/src/components/CitizenQRScannerModal.tsx"
click node_backend "https://github.com/amruthaa77/greenpay/blob/main/backend/app/main.py"
click node_authapi "https://github.com/amruthaa77/greenpay/blob/main/backend/app/api/v1/auth.py"
click node_adminapi "https://github.com/amruthaa77/greenpay/blob/main/backend/app/api/v1/admin.py"
click node_rewardapi "https://github.com/amruthaa77/greenpay/blob/main/backend/app/api/v1/rewards.py"
click node_rewardengine "https://github.com/amruthaa77/greenpay/blob/main/backend/app/services/reward_engine.py"
click node_anomaly "https://github.com/amruthaa77/greenpay/blob/main/backend/app/services/anomaly_service.py"
click node_audit "https://github.com/amruthaa77/greenpay/blob/main/backend/app/services/audit_service.py"
click node_impact "https://github.com/amruthaa77/greenpay/blob/main/backend/app/services/impact_service.py"
click node_forecast "https://github.com/amruthaa77/greenpay/blob/main/backend/app/services/predictive_service.py"
click node_domain "https://github.com/amruthaa77/greenpay/tree/main/backend/app/models"
click node_db "https://github.com/amruthaa77/greenpay/blob/main/backend/app/database.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,node_authctx,node_offline,node_clientapi,node_citizenpages,node_adminpages,node_scan toneBlue
class node_backend,node_authapi toneAmber
class node_adminapi,node_audit toneMint
class node_rewardapi,node_rewardengine,node_anomaly,node_impact,node_forecast toneRose
class node_domain,node_db,node_store,node_citizen,node_supervisor toneIndigo
```

## Components

### Frontend experience

- [Route application](https://github.com/amruthaa77/greenpay/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Session context](https://github.com/amruthaa77/greenpay/blob/main/frontend/src/context/AuthContext.tsx): `frontend/src/context/AuthContext.tsx`
- [Offline sync](https://github.com/amruthaa77/greenpay/blob/main/frontend/src/context/OfflineContext.tsx): `frontend/src/context/OfflineContext.tsx`
- [API client](https://github.com/amruthaa77/greenpay/blob/main/frontend/src/services/api.ts): `frontend/src/services/api.ts`
- [Citizen portal](https://github.com/amruthaa77/greenpay/tree/main/frontend/src/pages): `frontend/src/pages`
- [Admin console](https://github.com/amruthaa77/greenpay/tree/main/frontend/src/pages): `frontend/src/pages`
- [QR verification](https://github.com/amruthaa77/greenpay/blob/main/frontend/src/components/CitizenQRScannerModal.tsx): `frontend/src/components/CitizenQRScannerModal.tsx`

### API and identity

- [FastAPI application](https://github.com/amruthaa77/greenpay/blob/main/backend/app/main.py): `backend/app/main.py`
- [Authentication routes](https://github.com/amruthaa77/greenpay/blob/main/backend/app/api/v1/auth.py): `backend/app/api/v1/auth.py`

### Municipal operations

- [Admin routes](https://github.com/amruthaa77/greenpay/blob/main/backend/app/api/v1/admin.py): `backend/app/api/v1/admin.py`
- [Audit logging](https://github.com/amruthaa77/greenpay/blob/main/backend/app/services/audit_service.py): `backend/app/services/audit_service.py`

### Rewards and intelligence

- [Reward routes](https://github.com/amruthaa77/greenpay/blob/main/backend/app/api/v1/rewards.py): `backend/app/api/v1/rewards.py`
- [Reward calculation](https://github.com/amruthaa77/greenpay/blob/main/backend/app/services/reward_engine.py): `backend/app/services/reward_engine.py`
- [Anomaly detection](https://github.com/amruthaa77/greenpay/blob/main/backend/app/services/anomaly_service.py): `backend/app/services/anomaly_service.py`
- [Impact analytics](https://github.com/amruthaa77/greenpay/blob/main/backend/app/services/impact_service.py): `backend/app/services/impact_service.py`
- [Waste forecasting](https://github.com/amruthaa77/greenpay/blob/main/backend/app/services/predictive_service.py): `backend/app/services/predictive_service.py`

### Persistence

- [Domain records](https://github.com/amruthaa77/greenpay/tree/main/backend/app/models): `backend/app/models`
- [Database session](https://github.com/amruthaa77/greenpay/blob/main/backend/app/database.py): `backend/app/database.py`
- **Relational database**

### Other components

- **Citizen**
- **Supervisor**

## Connections

- Citizen → Route application: uses portal (evidence: `README.md`)
- Supervisor → Route application: uses console (evidence: `README.md`)
- Route application → Session context: provides session (evidence: `frontend/src/App.tsx`)
- Route application → Citizen portal: routes to (evidence: `frontend/src/App.tsx`)
- Route application → Admin console: routes to (evidence: `frontend/src/App.tsx`)
- Session context → API client: calls (evidence: `frontend/src/context/AuthContext.tsx`)
- Offline sync → API client: syncs through (evidence: `frontend/src/context/OfflineContext.tsx`)
- Citizen portal → API client: requests data (evidence: `frontend/src/pages/UserDashboard.tsx`)
- Admin console → API client: requests data (evidence: `frontend/src/pages/AdminRewardManagementPage.tsx`)
- QR verification → API client: looks up citizen (evidence: `frontend/src/components/CitizenQRScannerModal.tsx`)
- API client → FastAPI application: sends REST requests (evidence: `README.md`)
- FastAPI application → Authentication routes: mounts routes (evidence: `backend/app/main.py`)
- FastAPI application → Database session: creates tables (evidence: `backend/app/main.py`)
- Authentication routes → Domain records: queries and updates (evidence: `backend/app/api/v1/auth.py`)
- Authentication routes → Audit logging: records actions (evidence: `backend/app/api/v1/auth.py`)
- Admin routes → Domain records: manages records
- Admin routes → Reward calculation: processes weighment
- Admin routes → Anomaly detection: checks volume
- Admin routes → Audit logging: logs administration
- Reward routes → Reward calculation: handles rewards
- Reward calculation → Domain records: uses reward and waste records (evidence: `backend/app/services/reward_engine.py`)
- Anomaly detection → Domain records: reads waste records (evidence: `backend/app/services/anomaly_service.py`)
- Impact analytics → Domain records: reads waste records (evidence: `backend/app/services/impact_service.py`)
- Waste forecasting → Domain records: reads waste records (evidence: `backend/app/services/predictive_service.py`)
- Audit logging → Domain records: writes audit records (evidence: `backend/app/services/audit_service.py`)
- Database session → Relational database: opens sessions (evidence: `backend/app/database.py`)
- Domain records → Relational database: persists entities
