# gxurav1710/youpi-pg architecture

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

- Interactive diagram: https://gitdiagram.com/gxurav1710/youpi-pg
- Repository: https://github.com/gxurav1710/youpi-pg

## Overview

YOUPI PG is a self-hosted UPI payment gateway. A buyer starts checkout through the merchant integration, verifies by WhatsApp OTP, enters a single-slot FIFO queue, pays the displayed UPI QR, and receives confirmation after banking observations are matched to a payment. Its major capabilities also include Android, Gmail, and Google Messages observers; merchant administration; and service/tunnel management. The README documents the end-to-end flow; sampled code confirms selected route, parsing, persistence, and observation links. Some unsampled route and integration wiring is therefore omitted.

Main entry points: [`apps/payment-api/src/server.js`](https://github.com/gxurav1710/youpi-pg/blob/main/apps/payment-api/src/server.js) (Payment API), [`apps/payment-api/src/routes/checkout.routes.js`](https://github.com/gxurav1710/youpi-pg/blob/main/apps/payment-api/src/routes/checkout.routes.js) (Checkout Routes), [`packages/db/src/repositories/payment-session.repository.js`](https://github.com/gxurav1710/youpi-pg/blob/main/packages/db/src/repositories/payment-session.repository.js) (Payment Sessions), [`packages/core/src/verification-pipeline.js`](https://github.com/gxurav1710/youpi-pg/blob/main/packages/core/src/verification-pipeline.js) (Verification Pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_checkout["Checkout"]
  node_merchant_sdk["Merchant Integration<br/>[youpi.js]"]
  node_checkout_ui["Checkout UI<br/>[youpi.js]"]
  node_qr["QR Generation<br/>[qr-lib.js]"]
end

subgraph group_gateway["Gateway"]
  node_payment_api["Payment API<br/>[server.js]"]
  node_checkout_routes["Checkout Routes<br/>[checkout.routes.js]"]
  node_admin_routes["Merchant Admin<br/>[admin.routes.js]"]
  node_whatsapp["WhatsApp OTP"]
  node_queue["FIFO Queue<br/>[queue-engine.js]"]
  node_timing["Payment Timers<br/>[timing-engine.js]"]
  node_verification["Verification Pipeline"]
  node_attribution["Attribution Engine"]
  node_webhooks["Webhook Delivery<br/>[webhook-engine.js]"]
end

subgraph group_observation["Bank Observers"]
  node_android["Android Observer"]
  node_gmail["Gmail Observer<br/>[gmail-poller.js]"]
  node_gmail_browser["Gmail Browser Automation"]
  node_sms["Google Messages Observer<br/>[sms-service.js]"]
  node_sms_browser["Messages Automation"]
end

subgraph group_persistence["Persistence"]
  node_database[("SQLite Database<br/>[database.js]")]
  node_sessions["Payment Sessions"]
  node_customers["Customer Records"]
end

subgraph group_operations["Operations"]
  node_control["Service Control Center<br/>[process-manager.js]"]
  node_tunnel["Tunnel Manager<br/>[tunnel-manager.js]"]
end

node_buyer(("Buyer"))
node_merchant["Merchant Storefront"]
node_bank["Bank / UPI Rails"]

node_buyer -->|"starts checkout"| node_checkout_ui
node_merchant -->|"integrates"| node_merchant_sdk
node_merchant_sdk -->|"opens checkout"| node_checkout_ui
node_checkout_ui -->|"requests payment"| node_payment_api
node_payment_api -->|"routes checkout"| node_checkout_routes
node_checkout_routes -->|"authenticates buyer"| node_whatsapp
node_checkout_routes -->|"acquires slot"| node_queue
node_queue -->|"reserves slot"| node_sessions
node_checkout_routes -->|"provides payment QR"| node_qr
node_buyer -->|"pays by UPI"| node_bank
node_bank -->|"sends SMS and alerts"| node_android
node_bank -->|"sends credit email"| node_gmail
node_android -->|"submits observation"| node_payment_api
node_gmail -->|"supplies observation"| node_verification
node_sms -->|"submits observation"| node_payment_api
node_sms_browser -->|"provides messages"| node_sms
node_gmail_browser -->|"automates inbox"| node_gmail
node_verification -->|"passes verified data"| node_attribution
node_verification -->|"checks payment sessions"| node_sessions
node_attribution -->|"records attribution"| node_sessions
node_attribution -.->|"confirms payment"| node_webhooks
node_webhooks -->|"sends result webhook"| node_merchant
node_payment_api -->|"serves administration"| node_admin_routes
node_admin_routes -->|"manages tunnel"| node_tunnel
node_control -->|"manages service"| node_payment_api
node_sessions -->|"reads and writes"| node_database
node_customers -->|"reads and writes"| node_database

click node_merchant_sdk "https://github.com/gxurav1710/youpi-pg/blob/main/packages/merchant-sdk/src/youpi.js"
click node_checkout_ui "https://github.com/gxurav1710/youpi-pg/blob/main/apps/checkout-portal/src/sdk/youpi.js"
click node_qr "https://github.com/gxurav1710/youpi-pg/blob/main/apps/checkout-portal/src/qr-lib.js"
click node_payment_api "https://github.com/gxurav1710/youpi-pg/blob/main/apps/payment-api/src/server.js"
click node_checkout_routes "https://github.com/gxurav1710/youpi-pg/blob/main/apps/payment-api/src/routes/checkout.routes.js"
click node_admin_routes "https://github.com/gxurav1710/youpi-pg/blob/main/apps/payment-api/src/routes/admin.routes.js"
click node_whatsapp "https://github.com/gxurav1710/youpi-pg/blob/main/apps/payment-api/src/services/whatsapp-berry.service.js"
click node_queue "https://github.com/gxurav1710/youpi-pg/blob/main/packages/core/src/queue-engine.js"
click node_timing "https://github.com/gxurav1710/youpi-pg/blob/main/packages/core/src/timing-engine.js"
click node_verification "https://github.com/gxurav1710/youpi-pg/blob/main/packages/core/src/verification-pipeline.js"
click node_attribution "https://github.com/gxurav1710/youpi-pg/blob/main/packages/core/src/attribution-engine.js"
click node_webhooks "https://github.com/gxurav1710/youpi-pg/blob/main/packages/core/src/webhook-engine.js"
click node_android "https://github.com/gxurav1710/youpi-pg/blob/main/apps/android-observer-app/app/src/main/java/com/youpi/observer/ForegroundService.kt"
click node_gmail "https://github.com/gxurav1710/youpi-pg/blob/main/apps/gmail-observer/src/gmail-poller.js"
click node_gmail_browser "https://github.com/gxurav1710/youpi-pg/blob/main/apps/gmail-observer/src/browser-automator.js"
click node_sms "https://github.com/gxurav1710/youpi-pg/blob/main/apps/sms-observer/src/sms-service.js"
click node_sms_browser "https://github.com/gxurav1710/youpi-pg/blob/main/apps/sms-observer/src/browser-automator.js"
click node_database "https://github.com/gxurav1710/youpi-pg/blob/main/packages/db/src/database.js"
click node_sessions "https://github.com/gxurav1710/youpi-pg/blob/main/packages/db/src/repositories/payment-session.repository.js"
click node_customers "https://github.com/gxurav1710/youpi-pg/blob/main/packages/db/src/repositories/customer.repository.js"
click node_control "https://github.com/gxurav1710/youpi-pg/blob/main/apps/control-center/src/process-manager.js"
click node_tunnel "https://github.com/gxurav1710/youpi-pg/blob/main/apps/payment-api/src/services/tunnel-manager.js"

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_merchant_sdk,node_checkout_ui,node_qr toneBlue
class node_payment_api,node_checkout_routes,node_admin_routes,node_whatsapp,node_queue,node_timing,node_verification,node_attribution,node_webhooks toneAmber
class node_android,node_gmail,node_gmail_browser,node_sms,node_sms_browser toneMint
class node_database,node_sessions,node_customers toneRose
class node_control,node_tunnel,node_buyer,node_merchant,node_bank toneIndigo
```

## Components

### Checkout

- [Merchant Integration](https://github.com/gxurav1710/youpi-pg/blob/main/packages/merchant-sdk/src/youpi.js): `packages/merchant-sdk/src/youpi.js`
- [Checkout UI](https://github.com/gxurav1710/youpi-pg/blob/main/apps/checkout-portal/src/sdk/youpi.js): `apps/checkout-portal/src/sdk/youpi.js`
- [QR Generation](https://github.com/gxurav1710/youpi-pg/blob/main/apps/checkout-portal/src/qr-lib.js): `apps/checkout-portal/src/qr-lib.js`

### Gateway

- [Payment API](https://github.com/gxurav1710/youpi-pg/blob/main/apps/payment-api/src/server.js): `apps/payment-api/src/server.js`
- [Checkout Routes](https://github.com/gxurav1710/youpi-pg/blob/main/apps/payment-api/src/routes/checkout.routes.js): `apps/payment-api/src/routes/checkout.routes.js`
- [Merchant Admin](https://github.com/gxurav1710/youpi-pg/blob/main/apps/payment-api/src/routes/admin.routes.js): `apps/payment-api/src/routes/admin.routes.js`
- [WhatsApp OTP](https://github.com/gxurav1710/youpi-pg/blob/main/apps/payment-api/src/services/whatsapp-berry.service.js): `apps/payment-api/src/services/whatsapp-berry.service.js`
- [FIFO Queue](https://github.com/gxurav1710/youpi-pg/blob/main/packages/core/src/queue-engine.js): `packages/core/src/queue-engine.js`
- [Payment Timers](https://github.com/gxurav1710/youpi-pg/blob/main/packages/core/src/timing-engine.js): `packages/core/src/timing-engine.js`
- [Verification Pipeline](https://github.com/gxurav1710/youpi-pg/blob/main/packages/core/src/verification-pipeline.js): `packages/core/src/verification-pipeline.js`
- [Attribution Engine](https://github.com/gxurav1710/youpi-pg/blob/main/packages/core/src/attribution-engine.js): `packages/core/src/attribution-engine.js`
- [Webhook Delivery](https://github.com/gxurav1710/youpi-pg/blob/main/packages/core/src/webhook-engine.js): `packages/core/src/webhook-engine.js`

### Bank Observers

- [Android Observer](https://github.com/gxurav1710/youpi-pg/blob/main/apps/android-observer-app/app/src/main/java/com/youpi/observer/ForegroundService.kt): `apps/android-observer-app/app/src/main/java/com/youpi/observer/ForegroundService.kt`
- [Gmail Observer](https://github.com/gxurav1710/youpi-pg/blob/main/apps/gmail-observer/src/gmail-poller.js): `apps/gmail-observer/src/gmail-poller.js`
- [Gmail Browser Automation](https://github.com/gxurav1710/youpi-pg/blob/main/apps/gmail-observer/src/browser-automator.js): `apps/gmail-observer/src/browser-automator.js`
- [Google Messages Observer](https://github.com/gxurav1710/youpi-pg/blob/main/apps/sms-observer/src/sms-service.js): `apps/sms-observer/src/sms-service.js`
- [Messages Automation](https://github.com/gxurav1710/youpi-pg/blob/main/apps/sms-observer/src/browser-automator.js): `apps/sms-observer/src/browser-automator.js`

### Persistence

- [SQLite Database](https://github.com/gxurav1710/youpi-pg/blob/main/packages/db/src/database.js): `packages/db/src/database.js`
- [Payment Sessions](https://github.com/gxurav1710/youpi-pg/blob/main/packages/db/src/repositories/payment-session.repository.js): `packages/db/src/repositories/payment-session.repository.js`
- [Customer Records](https://github.com/gxurav1710/youpi-pg/blob/main/packages/db/src/repositories/customer.repository.js): `packages/db/src/repositories/customer.repository.js`

### Operations

- [Service Control Center](https://github.com/gxurav1710/youpi-pg/blob/main/apps/control-center/src/process-manager.js): `apps/control-center/src/process-manager.js`
- [Tunnel Manager](https://github.com/gxurav1710/youpi-pg/blob/main/apps/payment-api/src/services/tunnel-manager.js): `apps/payment-api/src/services/tunnel-manager.js`

### Other components

- **Buyer**
- **Merchant Storefront**
- **Bank / UPI Rails**

## Connections

- Buyer → Checkout UI: starts checkout
- Merchant Storefront → Merchant Integration: integrates
- Merchant Integration → Checkout UI: opens checkout
- Checkout UI → Payment API: requests payment
- Payment API → Checkout Routes: routes checkout (evidence: `apps/payment-api/src/routes/checkout.routes.js`)
- Checkout Routes → WhatsApp OTP: authenticates buyer
- Checkout Routes → FIFO Queue: acquires slot (evidence: `apps/payment-api/src/routes/checkout.routes.js`)
- FIFO Queue → Payment Sessions: reserves slot
- Checkout Routes → QR Generation: provides payment QR
- Buyer → Bank / UPI Rails: pays by UPI
- Bank / UPI Rails → Android Observer: sends SMS and alerts
- Bank / UPI Rails → Gmail Observer: sends credit email
- Android Observer → Payment API: submits observation
- Gmail Observer → Verification Pipeline: supplies observation
- Google Messages Observer → Payment API: submits observation (evidence: `apps/sms-observer/src/sms-service.js`)
- Messages Automation → Google Messages Observer: provides messages (evidence: `apps/sms-observer/src/browser-automator.js`)
- Gmail Browser Automation → Gmail Observer: automates inbox (evidence: `apps/gmail-observer/src/browser-automator.js`)
- Verification Pipeline → Attribution Engine: passes verified data (evidence: `packages/core/src/verification-pipeline.js`)
- Verification Pipeline → Payment Sessions: checks payment sessions (evidence: `packages/core/src/verification-pipeline.js`)
- Attribution Engine → Payment Sessions: records attribution (evidence: `packages/core/src/attribution-engine.js`)
- Attribution Engine → Webhook Delivery: confirms payment
- Webhook Delivery → Merchant Storefront: sends result webhook
- Payment API → Merchant Admin: serves administration (evidence: `apps/payment-api/src/routes/admin.routes.js`)
- Merchant Admin → Tunnel Manager: manages tunnel (evidence: `apps/payment-api/src/routes/admin.routes.js`)
- Service Control Center → Payment API: manages service (evidence: `apps/control-center/src/process-manager.js`)
- Payment Sessions → SQLite Database: reads and writes (evidence: `packages/db/src/database.js`)
- Customer Records → SQLite Database: reads and writes (evidence: `packages/db/src/repositories/customer.repository.js`)
