How deadserpent/paysphere works
PaySphere is a payment-orchestration backend that gives platforms a gateway-agnostic API. The main workflow accepts an idempotent payment request, creates a payment intent and gateway order, then exposes verification and payment-history results. Gateway webhooks are signature-checked, deduplicated, and applied to the same payment state machine; a worker reconciles stuck payments. The graph also includes the demo checkout and operational metrics. Some subsystem links rely on the README or SOURCE INDEX because their source excerpts were not provided.
Main entry points: server.js HTTP server · paymentService.js Payment orchestration · gatewayService.js Gateway facade · webhookService.js Webhook processing
Components 25
API and checkout
- Demo checkout
server/public/checkout.js - HTTP server
server/src/server.js - Payment routes
server/src/routes/paymentRoutes.js - Webhook routes
server/src/routes/webhookRoutes.js - Payment API
server/src/controllers/paymentController.js - Webhook API
server/src/controllers/webhookController.js - Idempotency claims
server/src/middleware/idempotency.js
Payment lifecycle
- Payment orchestration
server/src/services/paymentService.js - Payment state machine
server/src/domain/paymentTransitions.js - Payment states
server/src/domain/paymentStates.js - Webhook processing
server/src/services/webhookService.js
Gateway integrations
- Gateway facade
server/src/services/gatewayService.js - Razorpay adapter
server/src/services/razorpayAdapter.js - Mock adapter
server/src/services/mockGatewayAdapter.js
Persistence and operations
- Reconciliation
server/src/services/reconciliationService.js - Reconciliation worker
server/src/workers/paymentWorker.js - Payment records
server/src/repositories/paymentRepository.js - Idempotency records
server/src/repositories/idempotencyRepository.js - Webhook records
server/src/repositories/webhookRepository.js - PostgreSQL
server/src/config/database.js - Runtime configuration
server/src/config/env.js - Logs and metrics
server/src/lib/metrics.js
Other components
- Platform caller
- Shopper
- Razorpay API
Connections 33
- Shopper → Demo checkout: uses
README.md - Demo checkout → HTTP server: calls API
README.md - Platform caller → HTTP server: calls API
README.md - HTTP server → Payment routes: mounts
server/src/server.js - HTTP server → Webhook routes: mounts
server/src/server.js - Payment routes → Payment API: routes to
server/src/routes/paymentRoutes.js - Payment routes → Idempotency claims: checks claims
server/src/routes/paymentRoutes.js - Webhook routes → Webhook API: routes to
server/src/routes/webhookRoutes.js - Payment API → Payment orchestration: invokes
server/src/controllers/paymentController.js - Payment API → HTTP server: returns response
- Idempotency claims → Idempotency records: claims keys
server/src/middleware/idempotency.js - Payment orchestration → Gateway facade: creates orders
server/src/services/paymentService.js - Payment orchestration → Payment records: reads and writes
server/src/services/paymentService.js - Payment orchestration → Payment state machine: validates transitions
server/src/services/paymentService.js - Payment state machine → Payment states: uses states
server/src/domain/paymentTransitions.js - Webhook API → Webhook processing: invokes
server/src/controllers/webhookController.js - Webhook processing → Gateway facade: verifies signature
server/src/services/webhookService.js - Webhook processing → Webhook records: deduplicates events
server/src/services/webhookService.js - Webhook processing → Payment records: looks up order
server/src/services/webhookService.js - Webhook processing → Payment orchestration: applies outcome
server/src/services/webhookService.js - Gateway facade → Razorpay adapter: selects adapter
server/src/services/gatewayService.js - Gateway facade → Mock adapter: selects adapter
server/src/services/gatewayService.js - Razorpay adapter → Razorpay API: sends gateway calls
README.md - Reconciliation worker → Reconciliation: runs loop
server/src/workers/paymentWorker.js - Reconciliation → Payment orchestration: repairs payments
server/src/services/reconciliationService.js - Reconciliation → Payment records: finds stuck intents
server/src/services/reconciliationService.js - Reconciliation → Gateway facade: checks gateway
server/src/services/reconciliationService.js - Payment records → PostgreSQL: queries
server/src/repositories/paymentRepository.js - Idempotency records → PostgreSQL: queries
server/src/repositories/idempotencyRepository.js - Webhook records → PostgreSQL: queries
server/src/repositories/webhookRepository.js - HTTP server → Logs and metrics: serves metrics
server/src/server.js - Gateway facade → Runtime configuration: selects adapter
server/src/services/gatewayService.js - HTTP server → Runtime configuration: configures server
server/src/server.js