# krestovsky13/payment architecture

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

- Interactive diagram: https://gitdiagram.com/krestovsky13/payment
- Repository: https://github.com/krestovsky13/payment

## Overview

Payment Service accepts authenticated, idempotent payment requests, persists them with an outbox event, and processes queued events asynchronously to update payment status and optionally send a webhook. The graph includes payment creation and lookup, persistence/outbox, and the RabbitMQ retry/DLQ processing path. Relationships in unsampled subsystems are included only where the README or SOURCE INDEX supports them; detailed database and retry internals were not inspected.

Main entry points: [`src/api/v1/payment/handlers.py`](https://github.com/krestovsky13/payment/blob/main/src/api/v1/payment/handlers.py) (Payment routes), [`src/core/app.py`](https://github.com/krestovsky13/payment/blob/main/src/core/app.py) (API runtime), [`src/application/payments/use_cases/make_payment.py`](https://github.com/krestovsky13/payment/blob/main/src/application/payments/use_cases/make_payment.py) (Create payment), [`src/application/payments/use_cases/processing_payment.py`](https://github.com/krestovsky13/payment/blob/main/src/application/payments/use_cases/processing_payment.py) (Process payment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_app_runtime["API runtime<br/>[app.py]"]
  node_payment_routes["Payment routes<br/>[handlers.py]"]
  node_auth_key["API key check<br/>[deps.py]"]
  node_payment_api["Payment API schema<br/>[schemas.py]"]
end

subgraph group_app["Payment application"]
  node_make_payment["Create payment<br/>[make_payment.py]"]
  node_get_payment["Get payment<br/>[get_payment.py]"]
  node_process_payment["Process payment"]
  node_payment_domain["Payment lifecycle<br/>[entities.py]"]
  node_payment_values["Payment values<br/>[value_objects.py]"]
  node_payment_repo_port["Payment repository port<br/>[repositories.py]"]
  node_outbox_port["Outbox port and events<br/>[outbox.py]"]
end

subgraph group_infra["Persistence and outbox"]
  node_db_repos["SQL repositories"]
  node_db_models["Database models"]
  node_database[("SQL database")]
  node_uow["SQL unit of work<br/>[uow.py]"]
  node_outbox_worker["Outbox worker<br/>[worker.py]"]
  node_container["Dependency wiring<br/>[containter.py]"]
end

subgraph group_messaging["Message processing"]
  node_consumer_runtime["Consumer runtime<br/>[consumer.py]"]
  node_mq_router["Message router<br/>[router.py]"]
  node_mq_handler["Payment message handler<br/>[payments.py]"]
  node_mq_topology["Queue topology<br/>[topology.py]"]
  node_rabbitmq["RabbitMQ"]
end

node_client(("API client"))
node_webhook(("Webhook endpoint"))

node_client -->|"sends request"| node_app_runtime
node_app_runtime -->|"registers routes"| node_payment_routes
node_payment_routes -->|"checks API key"| node_auth_key
node_payment_routes -->|"uses schemas"| node_payment_api
node_payment_routes -->|"creates payment"| node_make_payment
node_payment_routes -->|"fetches payment"| node_get_payment
node_make_payment -->|"creates entity"| node_payment_domain
node_make_payment -->|"stores payment"| node_payment_repo_port
node_make_payment -->|"records event"| node_outbox_port
node_get_payment -->|"loads payment"| node_payment_repo_port
node_process_payment -->|"loads and updates"| node_payment_repo_port
node_process_payment -->|"changes status"| node_payment_domain
node_process_payment -->|"posts webhook"| node_webhook
node_payment_routes -->|"builds remittance"| node_payment_values
node_payment_domain -->|"uses values"| node_payment_values
node_container -->|"provides repositories"| node_db_repos
node_db_repos -->|"implements port"| node_payment_repo_port
node_db_repos -->|"maps records"| node_db_models
node_db_models -.->|"persists records"| node_database
node_container -->|"provides unit of work"| node_uow
node_container -->|"provides worker"| node_outbox_worker
node_app_runtime -->|"starts worker"| node_outbox_worker
node_outbox_worker -->|"reads and marks"| node_outbox_port
node_outbox_worker -->|"publishes events"| node_rabbitmq
node_consumer_runtime -->|"starts consumer"| node_mq_router
node_mq_router -->|"routes messages"| node_mq_handler
node_mq_handler -->|"invokes processing"| node_process_payment
node_app_runtime -->|"declares queues"| node_mq_topology
node_mq_topology -->|"configures queues"| node_rabbitmq
node_rabbitmq -.->|"delivers messages"| node_mq_handler
node_mq_handler -.->|"retries or dead-letters"| node_rabbitmq

click node_app_runtime "https://github.com/krestovsky13/payment/blob/main/src/core/app.py"
click node_payment_routes "https://github.com/krestovsky13/payment/blob/main/src/api/v1/payment/handlers.py"
click node_auth_key "https://github.com/krestovsky13/payment/blob/main/src/api/deps.py"
click node_payment_api "https://github.com/krestovsky13/payment/blob/main/src/api/v1/payment/schemas.py"
click node_make_payment "https://github.com/krestovsky13/payment/blob/main/src/application/payments/use_cases/make_payment.py"
click node_get_payment "https://github.com/krestovsky13/payment/blob/main/src/application/payments/use_cases/get_payment.py"
click node_process_payment "https://github.com/krestovsky13/payment/blob/main/src/application/payments/use_cases/processing_payment.py"
click node_payment_domain "https://github.com/krestovsky13/payment/blob/main/src/domain/payment/entities.py"
click node_payment_values "https://github.com/krestovsky13/payment/blob/main/src/domain/payment/value_objects.py"
click node_payment_repo_port "https://github.com/krestovsky13/payment/blob/main/src/domain/payment/repositories.py"
click node_outbox_port "https://github.com/krestovsky13/payment/blob/main/src/application/ports/outbox.py"
click node_db_repos "https://github.com/krestovsky13/payment/tree/main/src/infrastructure/db/repositories"
click node_db_models "https://github.com/krestovsky13/payment/tree/main/src/infrastructure/db/models"
click node_uow "https://github.com/krestovsky13/payment/blob/main/src/infrastructure/db/uow.py"
click node_outbox_worker "https://github.com/krestovsky13/payment/blob/main/src/infrastructure/outbox/worker.py"
click node_container "https://github.com/krestovsky13/payment/blob/main/src/core/containter.py"
click node_consumer_runtime "https://github.com/krestovsky13/payment/blob/main/cmd/consumer.py"
click node_mq_router "https://github.com/krestovsky13/payment/blob/main/src/infrastructure/mq/router.py"
click node_mq_handler "https://github.com/krestovsky13/payment/blob/main/src/infrastructure/mq/handlers/payments.py"
click node_mq_topology "https://github.com/krestovsky13/payment/blob/main/src/infrastructure/mq/topology.py"

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_app_runtime,node_payment_routes,node_auth_key,node_payment_api,node_client toneBlue
class node_make_payment,node_get_payment,node_process_payment,node_payment_domain,node_payment_values,node_payment_repo_port,node_outbox_port toneAmber
class node_db_repos,node_db_models,node_database,node_uow,node_outbox_worker,node_container,node_webhook toneMint
class node_consumer_runtime,node_mq_router,node_mq_handler,node_mq_topology,node_rabbitmq toneRose
```

## Components

### HTTP API

- [API runtime](https://github.com/krestovsky13/payment/blob/main/src/core/app.py): `src/core/app.py`
- [Payment routes](https://github.com/krestovsky13/payment/blob/main/src/api/v1/payment/handlers.py): `src/api/v1/payment/handlers.py`
- [API key check](https://github.com/krestovsky13/payment/blob/main/src/api/deps.py): `src/api/deps.py`
- [Payment API schema](https://github.com/krestovsky13/payment/blob/main/src/api/v1/payment/schemas.py): `src/api/v1/payment/schemas.py`

### Payment application

- [Create payment](https://github.com/krestovsky13/payment/blob/main/src/application/payments/use_cases/make_payment.py): `src/application/payments/use_cases/make_payment.py`
- [Get payment](https://github.com/krestovsky13/payment/blob/main/src/application/payments/use_cases/get_payment.py): `src/application/payments/use_cases/get_payment.py`
- [Process payment](https://github.com/krestovsky13/payment/blob/main/src/application/payments/use_cases/processing_payment.py): `src/application/payments/use_cases/processing_payment.py`
- [Payment lifecycle](https://github.com/krestovsky13/payment/blob/main/src/domain/payment/entities.py): `src/domain/payment/entities.py`
- [Payment values](https://github.com/krestovsky13/payment/blob/main/src/domain/payment/value_objects.py): `src/domain/payment/value_objects.py`
- [Payment repository port](https://github.com/krestovsky13/payment/blob/main/src/domain/payment/repositories.py): `src/domain/payment/repositories.py`
- [Outbox port and events](https://github.com/krestovsky13/payment/blob/main/src/application/ports/outbox.py): `src/application/ports/outbox.py`

### Persistence and outbox

- [SQL repositories](https://github.com/krestovsky13/payment/tree/main/src/infrastructure/db/repositories): `src/infrastructure/db/repositories`
- [Database models](https://github.com/krestovsky13/payment/tree/main/src/infrastructure/db/models): `src/infrastructure/db/models`
- **SQL database**
- [SQL unit of work](https://github.com/krestovsky13/payment/blob/main/src/infrastructure/db/uow.py): `src/infrastructure/db/uow.py`
- [Outbox worker](https://github.com/krestovsky13/payment/blob/main/src/infrastructure/outbox/worker.py): `src/infrastructure/outbox/worker.py`
- [Dependency wiring](https://github.com/krestovsky13/payment/blob/main/src/core/containter.py): `src/core/containter.py`

### Message processing

- [Consumer runtime](https://github.com/krestovsky13/payment/blob/main/cmd/consumer.py): `cmd/consumer.py`
- [Message router](https://github.com/krestovsky13/payment/blob/main/src/infrastructure/mq/router.py): `src/infrastructure/mq/router.py`
- [Payment message handler](https://github.com/krestovsky13/payment/blob/main/src/infrastructure/mq/handlers/payments.py): `src/infrastructure/mq/handlers/payments.py`
- [Queue topology](https://github.com/krestovsky13/payment/blob/main/src/infrastructure/mq/topology.py): `src/infrastructure/mq/topology.py`
- **RabbitMQ**

### Other components

- **API client**
- **Webhook endpoint**

## Connections

- API client → API runtime: sends request (evidence: `README.md`)
- API runtime → Payment routes: registers routes (evidence: `src/core/app.py`)
- Payment routes → API key check: checks API key (evidence: `src/api/v1/payment/handlers.py`)
- Payment routes → Payment API schema: uses schemas (evidence: `src/api/v1/payment/handlers.py`)
- Payment routes → Create payment: creates payment (evidence: `src/api/v1/payment/handlers.py`)
- Payment routes → Get payment: fetches payment (evidence: `src/api/v1/payment/handlers.py`)
- Create payment → Payment lifecycle: creates entity (evidence: `src/application/payments/use_cases/make_payment.py`)
- Create payment → Payment repository port: stores payment (evidence: `src/application/payments/use_cases/make_payment.py`)
- Create payment → Outbox port and events: records event (evidence: `src/application/payments/use_cases/make_payment.py`)
- Get payment → Payment repository port: loads payment (evidence: `src/application/payments/use_cases/get_payment.py`)
- Process payment → Payment repository port: loads and updates (evidence: `src/application/payments/use_cases/processing_payment.py`)
- Process payment → Payment lifecycle: changes status (evidence: `src/application/payments/use_cases/processing_payment.py`)
- Process payment → Webhook endpoint: posts webhook (evidence: `src/application/payments/use_cases/processing_payment.py`)
- Payment routes → Payment values: builds remittance (evidence: `src/api/v1/payment/handlers.py`)
- Payment lifecycle → Payment values: uses values (evidence: `src/domain/payment/entities.py`)
- Dependency wiring → SQL repositories: provides repositories (evidence: `src/core/containter.py`)
- SQL repositories → Payment repository port: implements port (evidence: `src/infrastructure/db/repositories/payment.py`)
- SQL repositories → Database models: maps records (evidence: `src/infrastructure/db/repositories/payment.py`)
- Database models → SQL database: persists records (evidence: `README.md`)
- Dependency wiring → SQL unit of work: provides unit of work (evidence: `src/core/containter.py`)
- Dependency wiring → Outbox worker: provides worker (evidence: `src/core/containter.py`)
- API runtime → Outbox worker: starts worker (evidence: `src/core/app.py`)
- Outbox worker → Outbox port and events: reads and marks (evidence: `src/infrastructure/outbox/worker.py`)
- Outbox worker → RabbitMQ: publishes events (evidence: `src/infrastructure/outbox/worker.py`)
- Consumer runtime → Message router: starts consumer (evidence: `cmd/consumer.py`)
- Message router → Payment message handler: routes messages (evidence: `src/infrastructure/mq/router.py`)
- Payment message handler → Process payment: invokes processing (evidence: `src/infrastructure/mq/handlers/payments.py`)
- API runtime → Queue topology: declares queues (evidence: `src/core/app.py`)
- Queue topology → RabbitMQ: configures queues (evidence: `src/infrastructure/mq/topology.py`)
- RabbitMQ → Payment message handler: delivers messages (evidence: `README.md`)
- Payment message handler → RabbitMQ: retries or dead-letters (evidence: `README.md`)
