# microservices-demo/payment architecture

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

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

## Overview

#### Purpose and lifecycle
This deprecated Go microservice exposes payment authorization for the microservices-demo system. It runs as a standalone HTTP process or container, listens on port 8080 internally (mapped to 8082 by Compose), and returns a simple authorization result rather than integrating with a real payment processor.

Entry point: `cmd/paymentsvc/main.go`.

#### Process composition
Application dependencies are assembled through explicit wiring, separating startup/configuration from business behavior and HTTP delivery:
- `cmd/paymentsvc/main.go`
- `wiring.go`
- `service.go`

Startup constructs the service, transport, and logging, then starts the HTTP server. This is a single-process, stateless service with no persistence layer evident in the repository.

#### Payment domain service
The core payment authorization behavior belongs behind the service layer. HTTP handlers should depend on this interface/implementation boundary rather than embed authorization logic directly.
- `service.go`
- `service_test.go`

The primary operation accepts a payment request containing an amount and produces an authorization decision. The README example indicates successful authorization is returned as `{"authorised":true}`.

#### HTTP transport and API boundary
The HTTP adapter owns routing, JSON request decoding/response encoding, and health exposure. It is the external boundary consumed by other demo services and clients.
- `transport.go`
- `endpoints.go`
- `api-spec/payment.json`

Key public endpoints are `POST /paymentAuth` and `GET /health`. The OpenAPI-style contract in `api-spec/payment.json` is the authoritative API-facing artifact; `api-spec/hooks.js` supports API-contract test behavior.

#### Endpoint layer
Endpoints sit between transport and domain service, adapting HTTP-facing request/response shapes to service calls and centralizing endpoint-level error/result handling.
- `endpoints.go`
- `service.go`
- `transport.go`

Control flow is: incoming HTTP request → route/transport decode → endpoint invocation → payment service → encoded HTTP response. Health requests remain operational concerns at the transport/endpoint boundary rather than payment authorization flow.

#### Observability
Structured logging is configured as a cross-cutting concern and used during startup and request/service execution.
- `logging.go`
- `cmd/paymentsvc/main.go`

No metrics, tracing client, database, message broker, or external payment gateway implementation is represented. `docker-compose-zipkin.yml` suggests optional Zipkin-oriented local infrastructure, but the core service remains independently runnable.

#### Delivery and runtime packaging
The service targets native Go execution and Docker deployment. Compose provides local service exposure; production/release images are separately defined.
- `docker-compose.yml`
- `docker/payment/Dockerfile`
- `docker/payment/Dockerfile-release`

CI is defined in `.github/workflows/main.yml` and legacy Travis configuration. Contract/integration testing is container-oriented under `test/`, including Dredd API-spec validation, while Go tests validate service/component behavior.

Main entry points: [`transport.go`](https://github.com/microservices-demo/payment/blob/master/transport.go) (HTTP transport), [`wiring.go`](https://github.com/microservices-demo/payment/blob/master/wiring.go) (Dependency wiring), [`cmd/paymentsvc/main.go`](https://github.com/microservices-demo/payment/blob/master/cmd/paymentsvc/main.go) (HTTP server), [`endpoints.go`](https://github.com/microservices-demo/payment/blob/master/endpoints.go) (Endpoint layer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_main["Service entrypoint<br/>Go main<br/>[main.go]"]
  node_wiring["Dependency wiring<br/>composition<br/>[wiring.go]"]
  node_logging["Structured logging<br/>observability<br/>[logging.go]"]
  node_http_server{{"HTTP server<br/>HTTP runtime<br/>[main.go]"}}
end

subgraph group_application["Application"]
  node_endpoints["Endpoint layer<br/>endpoint adapter<br/>[endpoints.go]"]
  node_payment_service["Payment service<br/>domain service<br/>[service.go]"]
end

subgraph group_api["HTTP API"]
  node_transport["HTTP transport<br/>HTTP adapter<br/>[transport.go]"]
  node_payment_route["POST /paymentAuth<br/>route<br/>[transport.go]"]
  node_health_route["GET /health<br/>route<br/>[transport.go]"]
  node_api_contract["Payment API contract<br/>OpenAPI contract<br/>[payment.json]"]
end

subgraph group_delivery["Delivery"]
  node_compose["Compose deployment<br/>local runtime<br/>[docker-compose.yml]"]
  node_docker_image["Service image<br/>Docker build"]
  node_release_image["Release image<br/>Docker build"]
  node_ci["CI workflow<br/>CI pipeline<br/>[main.yml]"]
end

node_main -->|"initializes"| node_wiring
node_wiring -->|"configures"| node_logging
node_wiring -->|"constructs"| node_payment_service
node_wiring -->|"constructs"| node_transport
node_main -->|"starts"| node_http_server
node_http_server -->|"serves"| node_transport
node_transport -->|"routes"| node_payment_route
node_transport -->|"routes"| node_health_route
node_payment_route -->|"invokes"| node_endpoints
node_endpoints -->|"authorizes payment"| node_payment_service
node_health_route -->|"checks health"| node_endpoints
node_api_contract -.->|"defines API boundary"| node_transport
node_compose -->|"builds or runs"| node_docker_image
node_docker_image -.->|"packages"| node_http_server
node_release_image -.->|"packages"| node_http_server
node_ci -.->|"validates"| node_api_contract

click node_main "https://github.com/microservices-demo/payment/blob/master/cmd/paymentsvc/main.go"
click node_wiring "https://github.com/microservices-demo/payment/blob/master/wiring.go"
click node_logging "https://github.com/microservices-demo/payment/blob/master/logging.go"
click node_http_server "https://github.com/microservices-demo/payment/blob/master/cmd/paymentsvc/main.go"
click node_transport "https://github.com/microservices-demo/payment/blob/master/transport.go"
click node_payment_route "https://github.com/microservices-demo/payment/blob/master/transport.go"
click node_health_route "https://github.com/microservices-demo/payment/blob/master/transport.go"
click node_endpoints "https://github.com/microservices-demo/payment/blob/master/endpoints.go"
click node_payment_service "https://github.com/microservices-demo/payment/blob/master/service.go"
click node_api_contract "https://github.com/microservices-demo/payment/blob/master/api-spec/payment.json"
click node_compose "https://github.com/microservices-demo/payment/blob/master/docker-compose.yml"
click node_docker_image "https://github.com/microservices-demo/payment/tree/master/docker/payment/Dockerfile"
click node_release_image "https://github.com/microservices-demo/payment/tree/master/docker/payment/Dockerfile-release"
click node_ci "https://github.com/microservices-demo/payment/blob/master/.github/workflows/main.yml"

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_main,node_wiring,node_logging,node_http_server toneBlue
class node_endpoints,node_payment_service toneAmber
class node_transport,node_payment_route,node_health_route,node_api_contract toneMint
class node_compose,node_docker_image,node_release_image,node_ci toneRose
```

## Components

### Runtime

- [Service entrypoint](https://github.com/microservices-demo/payment/blob/master/cmd/paymentsvc/main.go): Go main · Starts the standalone HTTP process. · `cmd/paymentsvc/main.go`
- [Dependency wiring](https://github.com/microservices-demo/payment/blob/master/wiring.go): composition · Assembles service, transport, and logging. · `wiring.go`
- [Structured logging](https://github.com/microservices-demo/payment/blob/master/logging.go): observability · `logging.go`
- [HTTP server](https://github.com/microservices-demo/payment/blob/master/cmd/paymentsvc/main.go): HTTP runtime · Listens on port 8080 in the container. · `cmd/paymentsvc/main.go`

### Application

- [Endpoint layer](https://github.com/microservices-demo/payment/blob/master/endpoints.go): endpoint adapter · Adapts API requests and centralizes results and errors. · `endpoints.go`
- [Payment service](https://github.com/microservices-demo/payment/blob/master/service.go): domain service · Authorizes a payment amount and returns an authorization decision. · `service.go`

### HTTP API

- [HTTP transport](https://github.com/microservices-demo/payment/blob/master/transport.go): HTTP adapter · Owns routes, JSON decoding, and response encoding. · `transport.go`
- [POST /paymentAuth](https://github.com/microservices-demo/payment/blob/master/transport.go): route · `transport.go`
- [GET /health](https://github.com/microservices-demo/payment/blob/master/transport.go): route · Operational health endpoint. · `transport.go`
- [Payment API contract](https://github.com/microservices-demo/payment/blob/master/api-spec/payment.json): OpenAPI contract · Authoritative public API artifact. · `api-spec/payment.json`

### Delivery

- [Compose deployment](https://github.com/microservices-demo/payment/blob/master/docker-compose.yml): local runtime · Maps the service container to port 8082. · `docker-compose.yml`
- [Service image](https://github.com/microservices-demo/payment/tree/master/docker/payment/Dockerfile): Docker build · Container packaging for local deployment. · `docker/payment/Dockerfile`
- [Release image](https://github.com/microservices-demo/payment/tree/master/docker/payment/Dockerfile-release): Docker build · Production or release image definition. · `docker/payment/Dockerfile-release`
- [CI workflow](https://github.com/microservices-demo/payment/blob/master/.github/workflows/main.yml): CI pipeline · `.github/workflows/main.yml`

## Connections

- Service entrypoint → Dependency wiring: initializes
- Dependency wiring → Structured logging: configures
- Dependency wiring → Payment service: constructs
- Dependency wiring → HTTP transport: constructs
- Service entrypoint → HTTP server: starts
- HTTP server → HTTP transport: serves
- HTTP transport → POST /paymentAuth: routes
- HTTP transport → GET /health: routes
- POST /paymentAuth → Endpoint layer: invokes
- Endpoint layer → Payment service: authorizes payment
- GET /health → Endpoint layer: checks health
- Payment API contract → HTTP transport: defines API boundary
- Compose deployment → Service image: builds or runs
- Service image → HTTP server: packages
- Release image → HTTP server: packages
- CI workflow → Payment API contract: validates
