# alokraj04/offlinepay architecture

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

- Interactive diagram: https://gitdiagram.com/alokraj04/offlinepay
- Repository: https://github.com/alokraj04/offlinepay

## Overview

OfflinePay demonstrates offline-first UPI payments: a sender creates an encrypted payment packet, simulated nearby devices relay it by gossip, and a connected bridge submits it for deduplication, replay checks, and ledger settlement. The API also exposes mesh controls, server-key metadata, account and transaction views, and a dashboard. The frontend React entry is empty in the sampled source; the dashboard is served from the Spring template. Mesh transport is simulated rather than real Bluetooth, and unsampled subsystem links are limited to documented behavior.

Main entry points: [`src/main/java/com/demo/offlinepay/controller/ApiController.java`](https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/controller/ApiController.java) (REST API), [`src/main/java/com/demo/offlinepay/service/BridgeIngestionService.java`](https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/service/BridgeIngestionService.java) (Bridge ingestion), [`src/main/java/com/demo/offlinepay/service/DemoService.java`](https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/service/DemoService.java) (Packet creation), [`src/main/java/com/demo/offlinepay/service/MeshSimulatorService.java`](https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/service/MeshSimulatorService.java) (Mesh gossip)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_payment_flow["Payment flow"]
  node_demo_service["Packet creation<br/>[DemoService.java]"]
  node_crypto["Hybrid crypto"]
  node_server_key["Server keys"]
end

subgraph group_mesh["Mesh simulation"]
  node_mesh_sim["Mesh gossip"]
  node_virtual_device["Virtual devices<br/>[VirtualDevice.java]"]
end

subgraph group_settlement["Ingestion and ledger"]
  node_ingestion["Bridge ingestion"]
  node_idempotency["Deduplication cache"]
  node_settlement_service["Ledger settlement"]
  node_account_repo["Account repository"]
  node_transaction_repo["Transaction repository"]
  node_database[("Relational database")]
end

subgraph group_presentation["API and dashboard"]
  node_api["REST API<br/>[ApiController.java]"]
  node_dashboard_controller["Dashboard route"]
  node_dashboard["Dashboard template<br/>[dashboard.html]"]
end

node_sender(("Sender device"))
node_bridge(("Bridge node"))
node_api_client(("API client"))

node_sender -->|"requests send"| node_api
node_api -->|"creates packet"| node_demo_service
node_demo_service -->|"encrypts payment"| node_crypto
node_demo_service -->|"gets public key"| node_server_key
node_crypto -->|"uses private key"| node_server_key
node_api -->|"injects and controls"| node_mesh_sim
node_mesh_sim -->|"stores and relays"| node_virtual_device
node_api_client -->|"calls endpoints"| node_api
node_api -->|"dispatches ingest"| node_ingestion
node_bridge -->|"uploads packet"| node_api
node_mesh_sim -->|"flush uploads"| node_api
node_api -->|"flushes packets"| node_ingestion
node_ingestion -->|"hashes and decrypts"| node_crypto
node_ingestion -->|"claims hash"| node_idempotency
node_ingestion -->|"settles payment"| node_settlement_service
node_settlement_service -->|"reads and updates"| node_account_repo
node_settlement_service -->|"records outcome"| node_transaction_repo
node_api -->|"lists accounts"| node_account_repo
node_api -->|"lists transactions"| node_transaction_repo
node_account_repo -->|"persists accounts"| node_database
node_transaction_repo -->|"persists transactions"| node_database
node_api_client -->|"opens dashboard"| node_dashboard_controller
node_dashboard_controller -->|"renders view"| node_dashboard

click node_demo_service "https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/service/DemoService.java"
click node_crypto "https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/crypto/HybridCryptoService.java"
click node_server_key "https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/crypto/ServerKeyHolder.java"
click node_mesh_sim "https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/service/MeshSimulatorService.java"
click node_virtual_device "https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/service/VirtualDevice.java"
click node_api "https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/controller/ApiController.java"
click node_dashboard_controller "https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/controller/DashboardController.java"
click node_dashboard "https://github.com/alokraj04/offlinepay/blob/main/src/main/resources/templates/dashboard.html"
click node_ingestion "https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/service/BridgeIngestionService.java"
click node_idempotency "https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/service/IdempotencyService.java"
click node_settlement_service "https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/service/SettlementService.java"
click node_account_repo "https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/model/AccountRepository.java"
click node_transaction_repo "https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/model/TransactionRepository.java"

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_demo_service,node_crypto,node_server_key,node_api_client toneBlue
class node_mesh_sim,node_virtual_device toneAmber
class node_ingestion,node_idempotency,node_settlement_service,node_account_repo,node_transaction_repo,node_database toneMint
class node_api,node_dashboard_controller,node_dashboard toneRose
class node_sender,node_bridge toneIndigo
```

## Components

### Payment flow

- [Packet creation](https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/service/DemoService.java): `src/main/java/com/demo/offlinepay/service/DemoService.java`
- [Hybrid crypto](https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/crypto/HybridCryptoService.java): `src/main/java/com/demo/offlinepay/crypto/HybridCryptoService.java`
- [Server keys](https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/crypto/ServerKeyHolder.java): `src/main/java/com/demo/offlinepay/crypto/ServerKeyHolder.java`

### Mesh simulation

- [Mesh gossip](https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/service/MeshSimulatorService.java): `src/main/java/com/demo/offlinepay/service/MeshSimulatorService.java`
- [Virtual devices](https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/service/VirtualDevice.java): `src/main/java/com/demo/offlinepay/service/VirtualDevice.java`

### Ingestion and ledger

- [Bridge ingestion](https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/service/BridgeIngestionService.java): `src/main/java/com/demo/offlinepay/service/BridgeIngestionService.java`
- [Deduplication cache](https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/service/IdempotencyService.java): `src/main/java/com/demo/offlinepay/service/IdempotencyService.java`
- [Ledger settlement](https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/service/SettlementService.java): `src/main/java/com/demo/offlinepay/service/SettlementService.java`
- [Account repository](https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/model/AccountRepository.java): `src/main/java/com/demo/offlinepay/model/AccountRepository.java`
- [Transaction repository](https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/model/TransactionRepository.java): `src/main/java/com/demo/offlinepay/model/TransactionRepository.java`
- **Relational database**

### API and dashboard

- [REST API](https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/controller/ApiController.java): `src/main/java/com/demo/offlinepay/controller/ApiController.java`
- [Dashboard route](https://github.com/alokraj04/offlinepay/blob/main/src/main/java/com/demo/offlinepay/controller/DashboardController.java): `src/main/java/com/demo/offlinepay/controller/DashboardController.java`
- [Dashboard template](https://github.com/alokraj04/offlinepay/blob/main/src/main/resources/templates/dashboard.html): `src/main/resources/templates/dashboard.html`

### Other components

- **Sender device**
- **Bridge node**
- **API client**

## Connections

- Sender device → REST API: requests send
- REST API → Packet creation: creates packet
- Packet creation → Hybrid crypto: encrypts payment
- Packet creation → Server keys: gets public key
- Hybrid crypto → Server keys: uses private key
- REST API → Mesh gossip: injects and controls
- Mesh gossip → Virtual devices: stores and relays
- API client → REST API: calls endpoints
- REST API → Bridge ingestion: dispatches ingest
- Bridge node → REST API: uploads packet
- Mesh gossip → REST API: flush uploads
- REST API → Bridge ingestion: flushes packets
- Bridge ingestion → Hybrid crypto: hashes and decrypts
- Bridge ingestion → Deduplication cache: claims hash
- Bridge ingestion → Ledger settlement: settles payment
- Ledger settlement → Account repository: reads and updates
- Ledger settlement → Transaction repository: records outcome
- REST API → Account repository: lists accounts
- REST API → Transaction repository: lists transactions
- Account repository → Relational database: persists accounts
- Transaction repository → Relational database: persists transactions
- API client → Dashboard route: opens dashboard
- Dashboard route → Dashboard template: renders view
