How singhlalit755/distributed-payment-system works
This platform accepts authenticated merchant payment and refund requests, stores workflow state, and dispatches asynchronous work to provider and webhook processing. Separate reconciliation and operations paths compare provider state, expose failures, and support retries; ledger records preserve financial history. The README also describes state-machine enforcement, multiple provider adapters, rate limiting, and observability. Edges use the sampled source or explicit README statements; some asynchronous worker wiring is documented rather than directly visible in the excerpts.
Main entry points: payments.service.ts Payment service · webhook.consumer.ts Webhook worker · kafka.service.ts Kafka messaging · prisma.service.ts PostgreSQL state
Components 21
API and access
- API application
apps/api/src/app.module.ts - Auth and RBAC
apps/api/src/auth - Payments API
apps/api/src/payments/payments.controller.ts
Payment processing
- Payment service
apps/api/src/payments/payments.service.ts - Idempotency
apps/api/src/payments/idempotency.service.ts - Provider adapters
libs/providers/src - Payment worker
apps/payment-worker/src/payment.processor.ts - Webhook intake
apps/api/src/webhooks/webhooks.controller.ts - Webhook worker
apps/webhook-worker/src/webhook.consumer.ts - Reconciliation
apps/reconciliation-worker/src/reconciliation.service.ts
State and messaging
- PostgreSQL state
libs/database/src/prisma.service.ts - Double-entry ledger
libs/database/src/ledger.service.ts - Payment rules
libs/domain/src/state-machine.ts - Kafka messaging
libs/messaging/src/kafka.service.ts - Redis controls
libs/messaging/src/redis.service.ts
Operations and telemetry
- Admin operations
apps/api/src/admin/admin.controller.ts - Metrics endpoint
apps/api/src/metrics.controller.ts - Metrics and tracing
libs/observability/src
Other components
- Client apps
- Payment providers
- Operators
Connections 31
- Client apps → API application: submit requests
- API application → Auth and RBAC: configures
apps/api/src/app.module.ts - API application → Payments API: routes to
apps/api/src/app.module.ts - Payments API → Payment service: calls
apps/api/src/payments/payments.controller.ts - Payment service → Idempotency: checks keys
apps/api/src/payments/payments.service.ts - Payment service → PostgreSQL state: reads and writes
apps/api/src/payments/payments.service.ts - Payment service → Redis controls: limits and locks
apps/api/src/payments/payments.service.ts - Payment service → Payment rules: enforces rules
apps/api/src/payments/payments.service.ts - Payment service → Double-entry ledger: posts entries
apps/api/src/payments/payments.service.ts - Payment service → Kafka messaging: publishes commands
apps/api/src/payments/payments.service.ts - Payment worker → Kafka messaging: consumes commands
- Payment worker → Provider adapters: invokes
- Provider adapters → Payment providers: charges and queries
- Webhook intake → Provider adapters: verifies signature
apps/api/src/webhooks/webhooks.controller.ts - Webhook intake → PostgreSQL state: stores event
apps/api/src/webhooks/webhooks.controller.ts - Webhook intake → Kafka messaging: publishes event
apps/api/src/webhooks/webhooks.controller.ts - Webhook worker → Kafka messaging: consumes events
apps/webhook-worker/src/webhook.consumer.ts - Webhook worker → PostgreSQL state: updates payment
apps/webhook-worker/src/webhook.consumer.ts - Webhook worker → Payment rules: checks transition
apps/webhook-worker/src/webhook.consumer.ts - Webhook worker → Double-entry ledger: posts capture
apps/webhook-worker/src/webhook.consumer.ts - Reconciliation → Kafka messaging: consumes and publishes
apps/reconciliation-worker/src/reconciliation.service.ts - Reconciliation → PostgreSQL state: compares and records
apps/reconciliation-worker/src/reconciliation.service.ts - Reconciliation → Provider adapters: queries provider
apps/reconciliation-worker/src/reconciliation.service.ts - Operators → Admin operations: inspect and retry
- Admin operations → PostgreSQL state: reads and audits
apps/api/src/admin/admin.controller.ts - Admin operations → Kafka messaging: requeues payments
apps/api/src/admin/admin.controller.ts - API application → Metrics endpoint: exposes
apps/api/src/app.module.ts - Metrics endpoint → Metrics and tracing: reads registry
apps/api/src/metrics.controller.ts - Payment worker → Metrics and tracing: records telemetry
- Reconciliation → Metrics and tracing: records metrics
apps/reconciliation-worker/src/reconciliation.service.ts - Webhook worker → Metrics and tracing: records duration
apps/webhook-worker/src/webhook.consumer.ts