# victorm0nteiro/payrouter architecture

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

- Interactive diagram: https://gitdiagram.com/victorm0nteiro/payrouter
- Repository: https://github.com/victorm0nteiro/payrouter

## Overview

Payrouter is an early-stage payment-instruction API. Its implemented user workflow authenticates a client, accepts an instruction idempotently, persists its initial event, and serves an authoritative read reconstructed from that event history. The README also describes reconciliation, outbox, Kafka, and projections as design goals or future work; they are not shown as running components because the README says they do not yet exist. Connections below are limited to source excerpts and explicit README statements.

Main entry points: [`cmd/api/main.go`](https://github.com/victorm0nteiro/payrouter/blob/main/cmd/api/main.go) (API composition), [`internal/app/accept_instruction.go`](https://github.com/victorm0nteiro/payrouter/blob/main/internal/app/accept_instruction.go) (Accept instruction), [`internal/adapters/http/server.go`](https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/http/server.go) (HTTP routes), [`internal/app/get_instruction.go`](https://github.com/victorm0nteiro/payrouter/blob/main/internal/app/get_instruction.go) (Get instruction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API and client access"]
  node_api["API composition<br/>[main.go]"]
  node_http["HTTP routes<br/>[server.go]"]
  node_http_auth["Bearer middleware<br/>[auth.go]"]
  node_clientctl["Client administration<br/>[main.go]"]
  node_accept_handler["Accept handler<br/>[accept.go]"]
  node_token_handler["Token handler<br/>[auth.go]"]
  node_get_handler["Instruction handler<br/>[get.go]"]
  node_signer["JWT signer<br/>[signer.go]"]
end

subgraph group_application["Application and domain"]
  node_accept_uc["Accept instruction"]
  node_auth_uc["Client authentication<br/>[auth.go]"]
  node_get_uc["Get instruction<br/>[get_instruction.go]"]
  node_domain["Instruction state<br/>[instruction.go]"]
  node_ports["Storage contracts<br/>[ports.go]"]
end

subgraph group_persistence["Postgres persistence"]
  node_uow["Transaction boundary<br/>[unitofwork.go]"]
  node_eventstore["Event store<br/>[eventstore.go]"]
  node_idempotency["Idempotency store<br/>[idempotency.go]"]
  node_clientstore["Client store<br/>[clientstore.go]"]
  node_postgres[("Postgres<br/>[000001_init.up.sql]")]
end

node_merchant(("API client"))
node_operator(("Client operator"))

node_merchant -->|"sends requests"| node_http
node_operator -->|"manages clients"| node_clientctl
node_api -->|"starts server"| node_http
node_api -->|"constructs"| node_accept_uc
node_api -->|"constructs"| node_get_uc
node_api -->|"constructs"| node_auth_uc
node_api -->|"configures"| node_signer
node_api -->|"constructs"| node_uow
node_api -->|"constructs"| node_eventstore
node_api -->|"constructs"| node_clientstore
node_http -->|"routes to"| node_accept_handler
node_http -->|"routes to"| node_token_handler
node_http -->|"routes to"| node_get_handler
node_merchant -->|"submits instruction"| node_accept_handler
node_merchant -->|"requests token"| node_token_handler
node_merchant -->|"queries instruction"| node_get_handler
node_accept_handler -->|"calls"| node_accept_uc
node_token_handler -->|"calls"| node_auth_uc
node_get_handler -->|"calls"| node_get_uc
node_http_auth -->|"verifies token"| node_signer
node_http -->|"protects routes"| node_http_auth
node_accept_uc -->|"creates instruction"| node_domain
node_accept_uc -->|"runs transaction"| node_uow
node_accept_uc -->|"claims key"| node_idempotency
node_accept_uc -->|"appends event"| node_eventstore
node_get_uc -->|"loads history"| node_eventstore
node_get_uc -->|"rehydrates state"| node_domain
node_accept_uc -->|"uses contracts"| node_ports
node_get_uc -->|"uses contract"| node_ports
node_clientctl -->|"creates or deactivates"| node_clientstore
node_eventstore -->|"reads and writes events"| node_postgres
node_idempotency -->|"reads and writes keys"| node_postgres
node_clientstore -->|"reads and writes clients"| node_postgres
node_auth_uc -.->|"issues token"| node_signer
node_auth_uc -.->|"looks up client"| node_clientstore

click node_api "https://github.com/victorm0nteiro/payrouter/blob/main/cmd/api/main.go"
click node_http "https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/http/server.go"
click node_http_auth "https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/http/auth.go"
click node_clientctl "https://github.com/victorm0nteiro/payrouter/blob/main/cmd/clientctl/main.go"
click node_accept_handler "https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/http/accept.go"
click node_token_handler "https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/http/auth.go"
click node_get_handler "https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/http/get.go"
click node_accept_uc "https://github.com/victorm0nteiro/payrouter/blob/main/internal/app/accept_instruction.go"
click node_auth_uc "https://github.com/victorm0nteiro/payrouter/blob/main/internal/app/auth.go"
click node_get_uc "https://github.com/victorm0nteiro/payrouter/blob/main/internal/app/get_instruction.go"
click node_domain "https://github.com/victorm0nteiro/payrouter/blob/main/internal/domain/instruction.go"
click node_ports "https://github.com/victorm0nteiro/payrouter/blob/main/internal/app/ports.go"
click node_signer "https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/jwt/signer.go"
click node_uow "https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/postgres/unitofwork.go"
click node_eventstore "https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/postgres/eventstore.go"
click node_idempotency "https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/postgres/idempotency.go"
click node_clientstore "https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/postgres/clientstore.go"
click node_postgres "https://github.com/victorm0nteiro/payrouter/blob/main/migrations/000001_init.up.sql"

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_http,node_http_auth,node_clientctl,node_accept_handler,node_token_handler,node_get_handler,node_signer,node_merchant,node_operator toneBlue
class node_accept_uc,node_auth_uc,node_get_uc,node_domain,node_ports toneAmber
class node_uow,node_eventstore,node_idempotency,node_clientstore,node_postgres toneMint
```

## Components

### API and client access

- [API composition](https://github.com/victorm0nteiro/payrouter/blob/main/cmd/api/main.go): `cmd/api/main.go`
- [HTTP routes](https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/http/server.go): `internal/adapters/http/server.go`
- [Bearer middleware](https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/http/auth.go): `internal/adapters/http/auth.go`
- [Client administration](https://github.com/victorm0nteiro/payrouter/blob/main/cmd/clientctl/main.go): `cmd/clientctl/main.go`
- [Accept handler](https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/http/accept.go): `internal/adapters/http/accept.go`
- [Token handler](https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/http/auth.go): `internal/adapters/http/auth.go`
- [Instruction handler](https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/http/get.go): `internal/adapters/http/get.go`
- [JWT signer](https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/jwt/signer.go): `internal/adapters/jwt/signer.go`

### Application and domain

- [Accept instruction](https://github.com/victorm0nteiro/payrouter/blob/main/internal/app/accept_instruction.go): `internal/app/accept_instruction.go`
- [Client authentication](https://github.com/victorm0nteiro/payrouter/blob/main/internal/app/auth.go): `internal/app/auth.go`
- [Get instruction](https://github.com/victorm0nteiro/payrouter/blob/main/internal/app/get_instruction.go): `internal/app/get_instruction.go`
- [Instruction state](https://github.com/victorm0nteiro/payrouter/blob/main/internal/domain/instruction.go): `internal/domain/instruction.go`
- [Storage contracts](https://github.com/victorm0nteiro/payrouter/blob/main/internal/app/ports.go): `internal/app/ports.go`

### Postgres persistence

- [Transaction boundary](https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/postgres/unitofwork.go): `internal/adapters/postgres/unitofwork.go`
- [Event store](https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/postgres/eventstore.go): `internal/adapters/postgres/eventstore.go`
- [Idempotency store](https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/postgres/idempotency.go): `internal/adapters/postgres/idempotency.go`
- [Client store](https://github.com/victorm0nteiro/payrouter/blob/main/internal/adapters/postgres/clientstore.go): `internal/adapters/postgres/clientstore.go`
- [Postgres](https://github.com/victorm0nteiro/payrouter/blob/main/migrations/000001_init.up.sql): `migrations/000001_init.up.sql`

### Other components

- **API client**
- **Client operator**

## Connections

- API client → HTTP routes: sends requests (evidence: `README.md`)
- Client operator → Client administration: manages clients (evidence: `README.md`)
- API composition → HTTP routes: starts server (evidence: `cmd/api/main.go`)
- API composition → Accept instruction: constructs (evidence: `cmd/api/main.go`)
- API composition → Get instruction: constructs (evidence: `cmd/api/main.go`)
- API composition → Client authentication: constructs (evidence: `cmd/api/main.go`)
- API composition → JWT signer: configures (evidence: `cmd/api/main.go`)
- API composition → Transaction boundary: constructs (evidence: `cmd/api/main.go`)
- API composition → Event store: constructs (evidence: `cmd/api/main.go`)
- API composition → Client store: constructs (evidence: `cmd/api/main.go`)
- HTTP routes → Accept handler: routes to (evidence: `internal/adapters/http/server.go`)
- HTTP routes → Token handler: routes to (evidence: `internal/adapters/http/server.go`)
- HTTP routes → Instruction handler: routes to (evidence: `internal/adapters/http/server.go`)
- API client → Accept handler: submits instruction (evidence: `README.md`)
- API client → Token handler: requests token (evidence: `README.md`)
- API client → Instruction handler: queries instruction (evidence: `README.md`)
- Accept handler → Accept instruction: calls (evidence: `internal/adapters/http/accept.go`)
- Token handler → Client authentication: calls (evidence: `internal/adapters/http/auth.go`)
- Instruction handler → Get instruction: calls (evidence: `internal/adapters/http/get.go`)
- Bearer middleware → JWT signer: verifies token (evidence: `internal/adapters/http/auth.go`)
- HTTP routes → Bearer middleware: protects routes (evidence: `internal/adapters/http/server.go`)
- Accept instruction → Instruction state: creates instruction (evidence: `internal/app/accept_instruction.go`)
- Accept instruction → Transaction boundary: runs transaction (evidence: `internal/app/accept_instruction.go`)
- Accept instruction → Idempotency store: claims key (evidence: `internal/app/accept_instruction.go`)
- Accept instruction → Event store: appends event (evidence: `internal/app/accept_instruction.go`)
- Get instruction → Event store: loads history (evidence: `internal/app/get_instruction.go`)
- Get instruction → Instruction state: rehydrates state (evidence: `internal/app/get_instruction.go`)
- Accept instruction → Storage contracts: uses contracts (evidence: `internal/app/accept_instruction.go`)
- Get instruction → Storage contracts: uses contract (evidence: `internal/app/get_instruction.go`)
- Client administration → Client store: creates or deactivates (evidence: `cmd/clientctl/main.go`)
- Event store → Postgres: reads and writes events (evidence: `internal/adapters/postgres/eventstore.go`)
- Idempotency store → Postgres: reads and writes keys (evidence: `internal/adapters/postgres/idempotency.go`)
- Client store → Postgres: reads and writes clients (evidence: `internal/adapters/postgres/clientstore.go`)
- Client authentication → JWT signer: issues token
- Client authentication → Client store: looks up client
