# pampam000/testtasksecunda architecture

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

- Interactive diagram: https://gitdiagram.com/pampam000/testtasksecunda
- Repository: https://github.com/pampam000/testtasksecunda

## Overview

Payment Service accepts authenticated, idempotent payment requests, atomically stores each payment with an outbox event, and returns a response. A relay publishes pending events to RabbitMQ; a consumer processes pending payments through an emulated gateway, persists the outcome, and attempts a customer webhook. Broker retry queues and a dead-letter queue handle failed processing. The graph also preserves API lookup, authentication, configuration, and the documented circuit-breaker behavior. Relationships for unsampled details rely on README descriptions; source excerpts do not show every persistence or broker interaction.

Main entry points: [`app/api/payments.py`](https://github.com/pampam000/testtasksecunda/blob/main/app/api/payments.py) (Payment routes), [`app/consumer/handler.py`](https://github.com/pampam000/testtasksecunda/blob/main/app/consumer/handler.py) (Payment consumer), [`app/messaging/topology.py`](https://github.com/pampam000/testtasksecunda/blob/main/app/messaging/topology.py) (Broker topology), [`app/main.py`](https://github.com/pampam000/testtasksecunda/blob/main/app/main.py) (Application startup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Payment API"]
  node_api["Payment routes<br/>[payments.py]"]
  node_auth["API key auth<br/>[deps.py]"]
  node_schemas["Payment schemas<br/>[payment.py]"]
  node_main["Application startup<br/>[main.py]"]
  node_config["Service settings<br/>[config.py]"]
end

subgraph group_storage["Persistence and outbox"]
  node_repository["Payment repository<br/>[payments.py]"]
  node_payment_model["Payment model<br/>[payment.py]"]
  node_outbox_model["Outbox model<br/>[outbox.py]"]
  node_relay["Outbox relay<br/>[relay.py]"]
end

subgraph group_broker["Messaging"]
  node_topology["Broker topology<br/>[topology.py]"]
end

subgraph group_processing["Payment processing"]
  node_handler["Payment consumer<br/>[handler.py]"]
  node_processor["Payment processor<br/>[processor.py]"]
  node_gateway["Emulated gateway<br/>[gateway.py]"]
  node_retry["Retry publisher<br/>[retry.py]"]
  node_webhook["Webhook delivery<br/>[webhook.py]"]
end

node_client(("API client"))
node_database[("PostgreSQL")]
node_rabbit["RabbitMQ"]
node_destination(("Customer webhook"))

node_client -->|"submits or queries"| node_api
node_api -->|"requires key"| node_auth
node_api -->|"validates and formats"| node_schemas
node_api -->|"calls"| node_repository
node_repository -->|"creates and fetches"| node_payment_model
node_repository -->|"creates event"| node_outbox_model
node_repository -->|"reads and writes"| node_database
node_api -->|"commits transaction"| node_database
node_main -->|"registers routes"| node_api
node_main -->|"loads settings"| node_config
node_main -->|"connects and declares"| node_topology
node_main -->|"starts relay"| node_relay
node_relay -->|"claims and marks published"| node_outbox_model
node_relay -->|"uses event publisher"| node_topology
node_topology -->|"declares and publishes"| node_rabbit
node_rabbit -->|"delivers payment events"| node_handler
node_handler -->|"subscribes to queue"| node_topology
node_handler -->|"invokes processing"| node_processor
node_processor -->|"checks and updates status"| node_payment_model
node_processor -->|"runs charge simulation"| node_gateway
node_processor -->|"requests delivery"| node_webhook
node_handler -->|"publishes on failure"| node_retry
node_retry -->|"dispatches retry"| node_rabbit
node_handler -->|"configures retry queues"| node_topology
node_webhook -->|"posts with backoff"| node_destination

click node_api "https://github.com/pampam000/testtasksecunda/blob/main/app/api/payments.py"
click node_auth "https://github.com/pampam000/testtasksecunda/blob/main/app/api/deps.py"
click node_schemas "https://github.com/pampam000/testtasksecunda/blob/main/app/schemas/payment.py"
click node_main "https://github.com/pampam000/testtasksecunda/blob/main/app/main.py"
click node_config "https://github.com/pampam000/testtasksecunda/blob/main/app/core/config.py"
click node_repository "https://github.com/pampam000/testtasksecunda/blob/main/app/repositories/payments.py"
click node_payment_model "https://github.com/pampam000/testtasksecunda/blob/main/app/models/payment.py"
click node_outbox_model "https://github.com/pampam000/testtasksecunda/blob/main/app/models/outbox.py"
click node_relay "https://github.com/pampam000/testtasksecunda/blob/main/app/outbox/relay.py"
click node_topology "https://github.com/pampam000/testtasksecunda/blob/main/app/messaging/topology.py"
click node_handler "https://github.com/pampam000/testtasksecunda/blob/main/app/consumer/handler.py"
click node_processor "https://github.com/pampam000/testtasksecunda/blob/main/app/consumer/processor.py"
click node_gateway "https://github.com/pampam000/testtasksecunda/blob/main/app/consumer/gateway.py"
click node_retry "https://github.com/pampam000/testtasksecunda/blob/main/app/consumer/retry.py"
click node_webhook "https://github.com/pampam000/testtasksecunda/blob/main/app/consumer/webhook.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_api,node_auth,node_schemas,node_main,node_config,node_client toneBlue
class node_repository,node_payment_model,node_outbox_model,node_relay,node_database toneAmber
class node_topology,node_destination toneMint
class node_handler,node_processor,node_gateway,node_retry,node_webhook toneRose
class node_rabbit toneIndigo
```

## Components

### Payment API

- [Payment routes](https://github.com/pampam000/testtasksecunda/blob/main/app/api/payments.py): `app/api/payments.py`
- [API key auth](https://github.com/pampam000/testtasksecunda/blob/main/app/api/deps.py): `app/api/deps.py`
- [Payment schemas](https://github.com/pampam000/testtasksecunda/blob/main/app/schemas/payment.py): `app/schemas/payment.py`
- [Application startup](https://github.com/pampam000/testtasksecunda/blob/main/app/main.py): `app/main.py`
- [Service settings](https://github.com/pampam000/testtasksecunda/blob/main/app/core/config.py): `app/core/config.py`

### Persistence and outbox

- [Payment repository](https://github.com/pampam000/testtasksecunda/blob/main/app/repositories/payments.py): `app/repositories/payments.py`
- [Payment model](https://github.com/pampam000/testtasksecunda/blob/main/app/models/payment.py): `app/models/payment.py`
- [Outbox model](https://github.com/pampam000/testtasksecunda/blob/main/app/models/outbox.py): `app/models/outbox.py`
- [Outbox relay](https://github.com/pampam000/testtasksecunda/blob/main/app/outbox/relay.py): `app/outbox/relay.py`

### Messaging

- [Broker topology](https://github.com/pampam000/testtasksecunda/blob/main/app/messaging/topology.py): `app/messaging/topology.py`

### Payment processing

- [Payment consumer](https://github.com/pampam000/testtasksecunda/blob/main/app/consumer/handler.py): `app/consumer/handler.py`
- [Payment processor](https://github.com/pampam000/testtasksecunda/blob/main/app/consumer/processor.py): `app/consumer/processor.py`
- [Emulated gateway](https://github.com/pampam000/testtasksecunda/blob/main/app/consumer/gateway.py): `app/consumer/gateway.py`
- [Retry publisher](https://github.com/pampam000/testtasksecunda/blob/main/app/consumer/retry.py): `app/consumer/retry.py`
- [Webhook delivery](https://github.com/pampam000/testtasksecunda/blob/main/app/consumer/webhook.py): `app/consumer/webhook.py`

### Other components

- **API client**
- **PostgreSQL**
- **RabbitMQ**
- **Customer webhook**

## Connections

- API client → Payment routes: submits or queries (evidence: `README.md`)
- Payment routes → API key auth: requires key (evidence: `app/api/payments.py`)
- Payment routes → Payment schemas: validates and formats (evidence: `app/api/payments.py`)
- Payment routes → Payment repository: calls (evidence: `app/api/payments.py`)
- Payment repository → Payment model: creates and fetches (evidence: `app/repositories/payments.py`)
- Payment repository → Outbox model: creates event (evidence: `app/repositories/payments.py`)
- Payment repository → PostgreSQL: reads and writes (evidence: `README.md`)
- Payment routes → PostgreSQL: commits transaction (evidence: `app/api/payments.py`)
- Application startup → Payment routes: registers routes (evidence: `app/main.py`)
- Application startup → Service settings: loads settings (evidence: `app/main.py`)
- Application startup → Broker topology: connects and declares (evidence: `app/main.py`)
- Application startup → Outbox relay: starts relay (evidence: `app/main.py`)
- Outbox relay → Outbox model: claims and marks published (evidence: `app/outbox/relay.py`)
- Outbox relay → Broker topology: uses event publisher (evidence: `app/main.py`)
- Broker topology → RabbitMQ: declares and publishes (evidence: `app/messaging/topology.py`)
- RabbitMQ → Payment consumer: delivers payment events (evidence: `app/consumer/handler.py`)
- Payment consumer → Broker topology: subscribes to queue (evidence: `app/consumer/handler.py`)
- Payment consumer → Payment processor: invokes processing (evidence: `app/consumer/handler.py`)
- Payment processor → Payment model: checks and updates status (evidence: `app/consumer/processor.py`)
- Payment processor → Emulated gateway: runs charge simulation (evidence: `app/consumer/processor.py`)
- Payment processor → Webhook delivery: requests delivery (evidence: `app/consumer/processor.py`)
- Payment consumer → Retry publisher: publishes on failure (evidence: `app/consumer/handler.py`)
- Retry publisher → RabbitMQ: dispatches retry (evidence: `app/consumer/retry.py`)
- Payment consumer → Broker topology: configures retry queues (evidence: `app/consumer/handler.py`)
- Webhook delivery → Customer webhook: posts with backoff (evidence: `app/consumer/webhook.py`)
