# romanitalian/durapay architecture

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

- Interactive diagram: https://gitdiagram.com/romanitalian/durapay
- Repository: https://github.com/romanitalian/durapay

## Overview

Durapay is a reference payment application built around durable, resumable order-payment workflows. The main path is client order submission through REST or gRPC, order creation and workflow enqueueing, then worker-side payment, event publication, and notification. Separate branches provide administrative order/user/feature-flag operations, authentication, and observability. README statements describe workflow steps and PostgreSQL durability; sampled runtime and handler excerpts establish several wiring and call relationships. Other subsystem details are retained where documented, without inferring unsampled connections.

Main entry points: [`internal/app/runtime.go`](https://github.com/romanitalian/durapay/blob/main/internal/app/runtime.go) (Runtime wiring), [`internal/workflow/order_payment.go`](https://github.com/romanitalian/durapay/blob/main/internal/workflow/order_payment.go) (Payment workflow), [`internal/repo/order_repo.go`](https://github.com/romanitalian/durapay/blob/main/internal/repo/order_repo.go) (Order repository), [`internal/service/admin_service.go`](https://github.com/romanitalian/durapay/blob/main/internal/service/admin_service.go) (Admin service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Order interfaces"]
  node_http["REST API<br/>[handler.go]"]
  node_grpc["gRPC API<br/>[server.go]"]
  node_order_service["Order service<br/>[order_service.go]"]
  node_order_repo["Order repository<br/>[order_repo.go]"]
end

subgraph group_workflow["Payment processing"]
  node_worker["Worker process<br/>[main.go]"]
  node_payment_workflow["Payment workflow<br/>[order_payment.go]"]
  node_payment_provider["Mock payment provider<br/>[provider.go]"]
  node_circuit_breaker["Circuit breaker<br/>[breaker.go]"]
  node_nats["NATS events<br/>[publisher.go]"]
  node_notifications["Notification fanout<br/>[notifier.go]"]
end

subgraph group_admin["Administration"]
  node_admin_ui["Admin console<br/>[handler.go]"]
  node_admin_service["Admin service<br/>[admin_service.go]"]
  node_admin_auth["Admin authentication<br/>[auth.go]"]
  node_cognito["Cognito OIDC<br/>[cognito_oidc.go]"]
  node_admin_repos["Admin repositories"]
  node_feature_flags["Feature flags<br/>[store.go]"]
end

subgraph group_platform["Runtime services"]
  node_postgres[("PostgreSQL")]
  node_runtime["Runtime wiring<br/>[runtime.go]"]
  node_telemetry["Observability<br/>[otel.go]"]
end

node_client(("Client"))

node_client -->|"submits orders"| node_http
node_http -->|"calls"| node_order_service
node_grpc -->|"calls"| node_order_service
node_order_service -->|"persists orders"| node_order_repo
node_order_service -->|"starts workflow"| node_payment_workflow
node_payment_workflow -->|"charges payment"| node_payment_provider
node_payment_workflow -->|"updates order"| node_order_repo
node_payment_provider -->|"stores charges"| node_order_repo
node_payment_provider -->|"checks failures"| node_circuit_breaker
node_payment_workflow -->|"publishes paid event"| node_nats
node_payment_workflow -->|"runs fanout"| node_notifications
node_worker -->|"registers workflow"| node_payment_workflow
node_order_repo -->|"reads and writes"| node_postgres
node_admin_ui -->|"authenticates requests"| node_admin_auth
node_admin_ui -->|"exchanges login code"| node_cognito
node_admin_ui -->|"handles admin actions"| node_admin_service
node_admin_service -->|"reads order data"| node_order_repo
node_admin_service -->|"re-enqueues retry"| node_payment_workflow
node_admin_service -->|"resends notifications"| node_notifications
node_admin_service -->|"manages users and flags"| node_admin_repos
node_runtime -->|"builds handler"| node_http
node_runtime -->|"registers server"| node_grpc
node_runtime -->|"creates repository"| node_order_repo
node_runtime -->|"configures provider"| node_payment_provider
node_runtime -->|"connects publisher"| node_nats
node_runtime -->|"initializes tracing"| node_telemetry
node_runtime -->|"provides flag store"| node_feature_flags

click node_http "https://github.com/romanitalian/durapay/blob/main/internal/handler/httpapi/handler.go"
click node_grpc "https://github.com/romanitalian/durapay/blob/main/internal/handler/grpcapi/server.go"
click node_order_service "https://github.com/romanitalian/durapay/blob/main/internal/service/order_service.go"
click node_order_repo "https://github.com/romanitalian/durapay/blob/main/internal/repo/order_repo.go"
click node_admin_ui "https://github.com/romanitalian/durapay/blob/main/internal/handler/adminui/handler.go"
click node_admin_service "https://github.com/romanitalian/durapay/blob/main/internal/service/admin_service.go"
click node_admin_auth "https://github.com/romanitalian/durapay/blob/main/internal/adminauth/auth.go"
click node_cognito "https://github.com/romanitalian/durapay/blob/main/internal/adminauth/cognito_oidc.go"
click node_admin_repos "https://github.com/romanitalian/durapay/tree/main/internal/repo"
click node_worker "https://github.com/romanitalian/durapay/blob/main/cmd/worker/main.go"
click node_payment_workflow "https://github.com/romanitalian/durapay/blob/main/internal/workflow/order_payment.go"
click node_payment_provider "https://github.com/romanitalian/durapay/blob/main/internal/payment/provider.go"
click node_circuit_breaker "https://github.com/romanitalian/durapay/blob/main/internal/circuitbreaker/breaker.go"
click node_nats "https://github.com/romanitalian/durapay/blob/main/internal/natsx/publisher.go"
click node_notifications "https://github.com/romanitalian/durapay/blob/main/internal/alert/notifier.go"
click node_runtime "https://github.com/romanitalian/durapay/blob/main/internal/app/runtime.go"
click node_telemetry "https://github.com/romanitalian/durapay/blob/main/internal/telemetry/otel.go"
click node_feature_flags "https://github.com/romanitalian/durapay/blob/main/internal/featureflag/store.go"

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_http,node_grpc,node_order_service,node_order_repo,node_client toneBlue
class node_worker,node_payment_workflow,node_payment_provider,node_circuit_breaker,node_nats,node_notifications toneAmber
class node_admin_ui,node_admin_service,node_admin_auth,node_cognito,node_admin_repos,node_feature_flags toneMint
class node_postgres,node_runtime,node_telemetry toneRose
```

## Components

### Order interfaces

- [REST API](https://github.com/romanitalian/durapay/blob/main/internal/handler/httpapi/handler.go): `internal/handler/httpapi/handler.go`
- [gRPC API](https://github.com/romanitalian/durapay/blob/main/internal/handler/grpcapi/server.go): `internal/handler/grpcapi/server.go`
- [Order service](https://github.com/romanitalian/durapay/blob/main/internal/service/order_service.go): `internal/service/order_service.go`
- [Order repository](https://github.com/romanitalian/durapay/blob/main/internal/repo/order_repo.go): `internal/repo/order_repo.go`

### Payment processing

- [Worker process](https://github.com/romanitalian/durapay/blob/main/cmd/worker/main.go): `cmd/worker/main.go`
- [Payment workflow](https://github.com/romanitalian/durapay/blob/main/internal/workflow/order_payment.go): `internal/workflow/order_payment.go`
- [Mock payment provider](https://github.com/romanitalian/durapay/blob/main/internal/payment/provider.go): `internal/payment/provider.go`
- [Circuit breaker](https://github.com/romanitalian/durapay/blob/main/internal/circuitbreaker/breaker.go): `internal/circuitbreaker/breaker.go`
- [NATS events](https://github.com/romanitalian/durapay/blob/main/internal/natsx/publisher.go): `internal/natsx/publisher.go`
- [Notification fanout](https://github.com/romanitalian/durapay/blob/main/internal/alert/notifier.go): `internal/alert/notifier.go`

### Administration

- [Admin console](https://github.com/romanitalian/durapay/blob/main/internal/handler/adminui/handler.go): `internal/handler/adminui/handler.go`
- [Admin service](https://github.com/romanitalian/durapay/blob/main/internal/service/admin_service.go): `internal/service/admin_service.go`
- [Admin authentication](https://github.com/romanitalian/durapay/blob/main/internal/adminauth/auth.go): `internal/adminauth/auth.go`
- [Cognito OIDC](https://github.com/romanitalian/durapay/blob/main/internal/adminauth/cognito_oidc.go): `internal/adminauth/cognito_oidc.go`
- [Admin repositories](https://github.com/romanitalian/durapay/tree/main/internal/repo): `internal/repo`
- [Feature flags](https://github.com/romanitalian/durapay/blob/main/internal/featureflag/store.go): `internal/featureflag/store.go`

### Runtime services

- **PostgreSQL**
- [Runtime wiring](https://github.com/romanitalian/durapay/blob/main/internal/app/runtime.go): `internal/app/runtime.go`
- [Observability](https://github.com/romanitalian/durapay/blob/main/internal/telemetry/otel.go): `internal/telemetry/otel.go`

### Other components

- **Client**

## Connections

- Client → REST API: submits orders (evidence: `README.md`)
- REST API → Order service: calls (evidence: `internal/handler/httpapi/handler.go`)
- gRPC API → Order service: calls (evidence: `internal/handler/grpcapi/server.go`)
- Order service → Order repository: persists orders (evidence: `internal/service/order_service.go`)
- Order service → Payment workflow: starts workflow (evidence: `internal/service/order_service.go`)
- Payment workflow → Mock payment provider: charges payment (evidence: `internal/workflow/order_payment.go`)
- Payment workflow → Order repository: updates order (evidence: `README.md`)
- Mock payment provider → Order repository: stores charges (evidence: `internal/payment/provider.go`)
- Mock payment provider → Circuit breaker: checks failures (evidence: `internal/payment/provider.go`)
- Payment workflow → NATS events: publishes paid event (evidence: `README.md`)
- Payment workflow → Notification fanout: runs fanout (evidence: `README.md`)
- Worker process → Payment workflow: registers workflow (evidence: `cmd/worker/main.go`)
- Order repository → PostgreSQL: reads and writes (evidence: `README.md`)
- Admin console → Admin authentication: authenticates requests (evidence: `internal/handler/adminui/handler.go`)
- Admin console → Cognito OIDC: exchanges login code (evidence: `internal/handler/adminui/handler.go`)
- Admin console → Admin service: handles admin actions (evidence: `internal/handler/adminui/handler.go`)
- Admin service → Order repository: reads order data (evidence: `internal/service/admin_service.go`)
- Admin service → Payment workflow: re-enqueues retry (evidence: `internal/service/admin_service.go`)
- Admin service → Notification fanout: resends notifications (evidence: `internal/service/admin_service.go`)
- Admin service → Admin repositories: manages users and flags (evidence: `internal/service/admin_service.go`)
- Runtime wiring → REST API: builds handler (evidence: `internal/app/runtime.go`)
- Runtime wiring → gRPC API: registers server (evidence: `internal/app/runtime.go`)
- Runtime wiring → Order repository: creates repository (evidence: `internal/app/runtime.go`)
- Runtime wiring → Mock payment provider: configures provider (evidence: `internal/app/runtime.go`)
- Runtime wiring → NATS events: connects publisher (evidence: `internal/app/runtime.go`)
- Runtime wiring → Observability: initializes tracing
- Runtime wiring → Feature flags: provides flag store (evidence: `internal/app/runtime.go`)
