# thiagogenez/labflow architecture

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

- Interactive diagram: https://gitdiagram.com/thiagogenez/labflow
- Repository: https://github.com/thiagogenez/labflow

## Overview

LabFlow is an event-driven shop application, currently implementing checkout, order storage, payments, and a simulated card provider. The primary workflow is browser tokenization, order checkout and payment, then publishing an order event through an outbox to a broker. The README also describes future reconciliation and event consumers; those are shown as planned or target-design components, not inspected implementations. Edges reflect the excerpts and explicit README relationships; some documented target-flow links are marked dashed because they are not yet implemented.

Main entry points: [`services/order-api/main.go`](https://github.com/thiagogenez/labflow/blob/main/services/order-api/main.go) (Order API), [`libs/go/outbox/outbox.go`](https://github.com/thiagogenez/labflow/blob/main/libs/go/outbox/outbox.go) (Outbox Relay), [`services/order-api/internal/order/handler.go`](https://github.com/thiagogenez/labflow/blob/main/services/order-api/internal/order/handler.go) (Order Routes), [`services/payment-api/main.go`](https://github.com/thiagogenez/labflow/blob/main/services/payment-api/main.go) (Payment API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_checkout["Checkout and Orders"]
  node_order_api["Order API<br/>[main.go]"]
  node_order_routes["Order Routes<br/>[handler.go]"]
  node_pricing["Catalogue and Pricing<br/>[pricing.go]"]
  node_order_domain["Order Service<br/>[service.go]"]
  node_order_store[("Order Store<br/>[store.go]")]
  node_order_tokens["Order Access Tokens<br/>[token.go]"]
  node_shipping["Shipping Quotes"]
end

subgraph group_payments["Payments"]
  node_payment_api["Payment API<br/>[main.go]"]
  node_payment_service["Payment Service<br/>[service.go]"]
  node_payment_provider["Provider Client<br/>[provider.go]"]
  node_payment_store[("Payment Store<br/>[store.go]")]
  node_psp["PSP Simulator<br/>[main.go]"]
  node_psp_routes["PSP API and Cards<br/>[handler.go]"]
  node_psp_store[("PSP Store<br/>[store.go]")]
  node_payment_reconciler["Payment Reconciliation"]
end

subgraph group_events["Events and Consumers"]
  node_outbox["Outbox Relay<br/>[outbox.go]"]
  node_broker["RabbitMQ Broker"]
  node_event_contracts["Event Contracts"]
  node_future_consumers["Inventory, Email, Analytics"]
end

subgraph group_platform["Shared Runtime"]
  node_http_server["HTTP Server<br/>[httpserver.go]"]
  node_idempotency["Idempotency Middleware<br/>[idempotency.go]"]
  node_postgres[("PostgreSQL")]
end

node_shopper(("Shopper / Browser"))

node_shopper -->|"requests token"| node_psp
node_shopper -->|"submits checkout"| node_order_api
node_order_api -->|"registers routes"| node_order_routes
node_order_routes -.->|"handles orders"| node_order_domain
node_order_domain -.->|"prices items"| node_pricing
node_order_domain -.->|"stores orders"| node_order_store
node_order_routes -.->|"validates access"| node_order_tokens
node_order_api -->|"serves routes"| node_http_server
node_order_api -->|"connects database"| node_postgres
node_order_api -->|"creates store"| node_idempotency
node_order_routes -.->|"uses middleware"| node_idempotency
node_order_api -->|"charges order"| node_payment_api
node_order_api -.->|"requests quote"| node_shipping
node_order_api -.->|"reconciles charges"| node_payment_reconciler
node_order_api -->|"starts relay"| node_outbox
node_order_store -->|"writes events"| node_outbox
node_outbox -->|"publishes events"| node_broker
node_outbox -->|"reads pending events"| node_postgres
node_outbox -.->|"publishes order event"| node_event_contracts
node_broker -.->|"delivers events"| node_future_consumers
node_payment_api -->|"constructs service"| node_payment_service
node_payment_api -->|"serves routes"| node_http_server
node_payment_api -->|"connects database"| node_postgres
node_payment_service -.->|"calls provider"| node_payment_provider
node_payment_service -.->|"stores payments"| node_payment_store
node_payment_provider -.->|"charges token"| node_psp
node_psp -->|"registers API"| node_psp_routes
node_psp_routes -.->|"creates charges"| node_psp_store
node_psp_routes -.->|"persists provider state"| node_postgres
node_psp_routes -.->|"returns token"| node_shopper

click node_order_api "https://github.com/thiagogenez/labflow/blob/main/services/order-api/main.go"
click node_order_routes "https://github.com/thiagogenez/labflow/blob/main/services/order-api/internal/order/handler.go"
click node_pricing "https://github.com/thiagogenez/labflow/blob/main/services/order-api/internal/order/pricing.go"
click node_order_domain "https://github.com/thiagogenez/labflow/blob/main/services/order-api/internal/order/service.go"
click node_order_store "https://github.com/thiagogenez/labflow/blob/main/services/order-api/internal/order/store.go"
click node_order_tokens "https://github.com/thiagogenez/labflow/blob/main/services/order-api/internal/order/token.go"
click node_payment_api "https://github.com/thiagogenez/labflow/blob/main/services/payment-api/main.go"
click node_payment_service "https://github.com/thiagogenez/labflow/blob/main/services/payment-api/internal/payment/service.go"
click node_payment_provider "https://github.com/thiagogenez/labflow/blob/main/services/payment-api/internal/payment/provider.go"
click node_payment_store "https://github.com/thiagogenez/labflow/blob/main/services/payment-api/internal/payment/store.go"
click node_psp "https://github.com/thiagogenez/labflow/blob/main/services/psp-simulator/main.go"
click node_psp_routes "https://github.com/thiagogenez/labflow/blob/main/services/psp-simulator/internal/psp/handler.go"
click node_psp_store "https://github.com/thiagogenez/labflow/blob/main/services/psp-simulator/internal/psp/store.go"
click node_outbox "https://github.com/thiagogenez/labflow/blob/main/libs/go/outbox/outbox.go"
click node_event_contracts "https://github.com/thiagogenez/labflow/tree/main/contracts/events"
click node_future_consumers "https://github.com/thiagogenez/labflow/tree/main/services"
click node_payment_reconciler "https://github.com/thiagogenez/labflow/tree/main/services/order-api"
click node_http_server "https://github.com/thiagogenez/labflow/blob/main/libs/go/httpserver/httpserver.go"
click node_idempotency "https://github.com/thiagogenez/labflow/blob/main/libs/go/idempotency/idempotency.go"
click node_shipping "https://github.com/thiagogenez/labflow/tree/main/services"

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_order_api,node_order_routes,node_pricing,node_order_domain,node_order_store,node_order_tokens,node_shipping,node_shopper toneBlue
class node_payment_api,node_payment_service,node_payment_provider,node_payment_store,node_psp,node_psp_routes,node_psp_store,node_payment_reconciler toneAmber
class node_outbox,node_broker,node_event_contracts,node_future_consumers toneMint
class node_http_server,node_idempotency,node_postgres toneRose
```

## Components

### Checkout and Orders

- [Order API](https://github.com/thiagogenez/labflow/blob/main/services/order-api/main.go): `services/order-api/main.go`
- [Order Routes](https://github.com/thiagogenez/labflow/blob/main/services/order-api/internal/order/handler.go): `services/order-api/internal/order/handler.go`
- [Catalogue and Pricing](https://github.com/thiagogenez/labflow/blob/main/services/order-api/internal/order/pricing.go): `services/order-api/internal/order/pricing.go`
- [Order Service](https://github.com/thiagogenez/labflow/blob/main/services/order-api/internal/order/service.go): `services/order-api/internal/order/service.go`
- [Order Store](https://github.com/thiagogenez/labflow/blob/main/services/order-api/internal/order/store.go): `services/order-api/internal/order/store.go`
- [Order Access Tokens](https://github.com/thiagogenez/labflow/blob/main/services/order-api/internal/order/token.go): `services/order-api/internal/order/token.go`
- [Shipping Quotes](https://github.com/thiagogenez/labflow/tree/main/services): `services`

### Payments

- [Payment API](https://github.com/thiagogenez/labflow/blob/main/services/payment-api/main.go): `services/payment-api/main.go`
- [Payment Service](https://github.com/thiagogenez/labflow/blob/main/services/payment-api/internal/payment/service.go): `services/payment-api/internal/payment/service.go`
- [Provider Client](https://github.com/thiagogenez/labflow/blob/main/services/payment-api/internal/payment/provider.go): `services/payment-api/internal/payment/provider.go`
- [Payment Store](https://github.com/thiagogenez/labflow/blob/main/services/payment-api/internal/payment/store.go): `services/payment-api/internal/payment/store.go`
- [PSP Simulator](https://github.com/thiagogenez/labflow/blob/main/services/psp-simulator/main.go): `services/psp-simulator/main.go`
- [PSP API and Cards](https://github.com/thiagogenez/labflow/blob/main/services/psp-simulator/internal/psp/handler.go): `services/psp-simulator/internal/psp/handler.go`
- [PSP Store](https://github.com/thiagogenez/labflow/blob/main/services/psp-simulator/internal/psp/store.go): `services/psp-simulator/internal/psp/store.go`
- [Payment Reconciliation](https://github.com/thiagogenez/labflow/tree/main/services/order-api): `services/order-api`

### Events and Consumers

- [Outbox Relay](https://github.com/thiagogenez/labflow/blob/main/libs/go/outbox/outbox.go): `libs/go/outbox/outbox.go`
- **RabbitMQ Broker**
- [Event Contracts](https://github.com/thiagogenez/labflow/tree/main/contracts/events): `contracts/events`
- [Inventory, Email, Analytics](https://github.com/thiagogenez/labflow/tree/main/services): `services`

### Shared Runtime

- [HTTP Server](https://github.com/thiagogenez/labflow/blob/main/libs/go/httpserver/httpserver.go): `libs/go/httpserver/httpserver.go`
- [Idempotency Middleware](https://github.com/thiagogenez/labflow/blob/main/libs/go/idempotency/idempotency.go): `libs/go/idempotency/idempotency.go`
- **PostgreSQL**

### Other components

- **Shopper / Browser**

## Connections

- Shopper / Browser → PSP Simulator: requests token (evidence: `README.md`)
- Shopper / Browser → Order API: submits checkout (evidence: `README.md`)
- Order API → Order Routes: registers routes (evidence: `services/order-api/main.go`)
- Order Routes → Order Service: handles orders
- Order Service → Catalogue and Pricing: prices items
- Order Service → Order Store: stores orders
- Order Routes → Order Access Tokens: validates access
- Order API → HTTP Server: serves routes (evidence: `services/order-api/main.go`)
- Order API → PostgreSQL: connects database (evidence: `services/order-api/main.go`)
- Order API → Idempotency Middleware: creates store (evidence: `services/order-api/main.go`)
- Order Routes → Idempotency Middleware: uses middleware
- Order API → Payment API: charges order (evidence: `README.md`)
- Order API → Shipping Quotes: requests quote (evidence: `README.md`)
- Order API → Payment Reconciliation: reconciles charges (evidence: `README.md`)
- Order API → Outbox Relay: starts relay (evidence: `services/order-api/main.go`)
- Order Store → Outbox Relay: writes events (evidence: `services/order-api/internal/order/store.go`)
- Outbox Relay → RabbitMQ Broker: publishes events (evidence: `libs/go/outbox/outbox.go`)
- Outbox Relay → PostgreSQL: reads pending events (evidence: `libs/go/outbox/outbox.go`)
- Outbox Relay → Event Contracts: publishes order event (evidence: `README.md`)
- RabbitMQ Broker → Inventory, Email, Analytics: delivers events (evidence: `README.md`)
- Payment API → Payment Service: constructs service (evidence: `services/payment-api/main.go`)
- Payment API → HTTP Server: serves routes (evidence: `services/payment-api/main.go`)
- Payment API → PostgreSQL: connects database (evidence: `services/payment-api/main.go`)
- Payment Service → Provider Client: calls provider
- Payment Service → Payment Store: stores payments
- Provider Client → PSP Simulator: charges token (evidence: `README.md`)
- PSP Simulator → PSP API and Cards: registers API (evidence: `services/psp-simulator/main.go`)
- PSP API and Cards → PSP Store: creates charges
- PSP API and Cards → PostgreSQL: persists provider state
- PSP API and Cards → Shopper / Browser: returns token (evidence: `README.md`)
