# enercity/protoflow architecture

> Architecture diagram of the GitHub repository enercity/protoflow, 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/enercity/protoflow
- Repository: https://github.com/enercity/protoflow

## Overview

Protoflow is a Watermill-based event-processing library. The principal workflow is to configure and construct a Service, select a transport, register typed JSON/Protobuf or raw handlers, then start the router to consume messages and publish handler outputs. The README also documents middleware for validation, outbox, tracing, metrics, retries, poison queues, and recovery. Evidence is strongest for service wiring, handler conversion, publishing, and AWS/channel transports; several middleware capabilities are documented but their implementations were not excerpted.

Main entry points: [`internal/runtime/service.go`](https://github.com/enercity/protoflow/blob/main/internal/runtime/service.go) (Service and router), [`libapi.go`](https://github.com/enercity/protoflow/blob/main/libapi.go) (Public API), [`internal/runtime/handlers/json.go`](https://github.com/enercity/protoflow/blob/main/internal/runtime/handlers/json.go) (JSON handlers), [`internal/runtime/handlers_proto.go`](https://github.com/enercity/protoflow/blob/main/internal/runtime/handlers_proto.go) (Protobuf registration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_setup["Service setup"]
  node_api["Public API<br/>[libapi.go]"]
  node_config["Configuration<br/>[config.go]"]
  node_service["Service and router<br/>[service.go]"]
end

subgraph group_handlers["Message handling"]
  node_typedproto["Protobuf handlers<br/>[proto.go]"]
  node_typedjson["JSON handlers<br/>[json.go]"]
  node_protoentry["Protobuf registration<br/>[handlers_proto.go]"]
  node_jsonentry["JSON registration<br/>[handlers_json.go]"]
  node_rawentry["Raw registration<br/>[handlers_raw.go]"]
  node_metadata["Message metadata<br/>[metadata.go]"]
  node_jsoncodec["JSON codec<br/>[jsoncodec.go]"]
end

subgraph group_messaging["Transport and publishing"]
  node_publisher["Event publishing<br/>[publisher.go]"]
  node_factory["Transport factory<br/>[factory.go]"]
  node_aws["AWS SNS/SQS<br/>[aws.go]"]
  node_channel["Go channel<br/>[channel.go]"]
end

subgraph group_crosscut["Cross-cutting runtime"]
  node_middleware["Middleware stack<br/>[middleware.go]"]
  node_logging["Logging adapters<br/>[logging.go]"]
  node_webui["Runtime web UI<br/>[webui.go]"]
end

node_developer(("Application developer"))
node_broker["Message broker"]
node_outbox[("Outbox store")]
node_validator["Payload validator"]

node_developer -->|"configures and registers"| node_api
node_api -->|"constructs service"| node_service
node_service -->|"uses config"| node_config
node_service -->|"builds transport"| node_factory
node_factory -->|"dispatches AWS"| node_aws
node_factory -->|"dispatches channel"| node_channel
node_aws -->|"publishes and consumes"| node_broker
node_channel -->|"publishes and consumes"| node_broker
node_api -->|"registers protobuf"| node_protoentry
node_api -->|"registers JSON"| node_jsonentry
node_api -->|"registers raw handler"| node_rawentry
node_protoentry -->|"builds handler"| node_typedproto
node_jsonentry -->|"builds handler"| node_typedjson
node_typedproto -->|"converts metadata"| node_metadata
node_typedjson -->|"converts metadata"| node_metadata
node_typedjson -->|"encodes payloads"| node_jsoncodec
node_protoentry -->|"registers handler"| node_service
node_jsonentry -->|"registers handler"| node_service
node_rawentry -->|"adds router handler"| node_service
node_service -->|"registers middleware"| node_middleware
node_service -->|"adapts logger"| node_logging
node_service -.->|"starts web UI"| node_webui
node_api -->|"exposes publishing"| node_publisher
node_publisher -->|"sets message metadata"| node_metadata
node_publisher -->|"publishes event"| node_broker
node_service -->|"accepts optional store"| node_outbox
node_service -->|"accepts optional validator"| node_validator
node_developer -->|"starts service"| node_service

click node_api "https://github.com/enercity/protoflow/blob/main/libapi.go"
click node_config "https://github.com/enercity/protoflow/blob/main/internal/runtime/config/config.go"
click node_service "https://github.com/enercity/protoflow/blob/main/internal/runtime/service.go"
click node_middleware "https://github.com/enercity/protoflow/blob/main/internal/runtime/middleware.go"
click node_typedproto "https://github.com/enercity/protoflow/blob/main/internal/runtime/handlers/proto.go"
click node_typedjson "https://github.com/enercity/protoflow/blob/main/internal/runtime/handlers/json.go"
click node_protoentry "https://github.com/enercity/protoflow/blob/main/internal/runtime/handlers_proto.go"
click node_jsonentry "https://github.com/enercity/protoflow/blob/main/internal/runtime/handlers_json.go"
click node_rawentry "https://github.com/enercity/protoflow/blob/main/internal/runtime/handlers_raw.go"
click node_metadata "https://github.com/enercity/protoflow/blob/main/internal/runtime/metadata/metadata.go"
click node_jsoncodec "https://github.com/enercity/protoflow/blob/main/internal/runtime/jsoncodec/jsoncodec.go"
click node_publisher "https://github.com/enercity/protoflow/blob/main/internal/runtime/publisher.go"
click node_factory "https://github.com/enercity/protoflow/blob/main/internal/runtime/transport/factory.go"
click node_aws "https://github.com/enercity/protoflow/blob/main/internal/runtime/transport/aws.go"
click node_channel "https://github.com/enercity/protoflow/blob/main/internal/runtime/transport/channel.go"
click node_logging "https://github.com/enercity/protoflow/blob/main/internal/runtime/logging/logging.go"
click node_webui "https://github.com/enercity/protoflow/blob/main/internal/runtime/webui.go"

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_config,node_service toneBlue
class node_typedproto,node_typedjson,node_protoentry,node_jsonentry,node_rawentry,node_metadata,node_jsoncodec,node_outbox toneAmber
class node_publisher,node_factory,node_aws,node_channel toneMint
class node_middleware,node_logging,node_webui toneRose
class node_developer,node_broker,node_validator toneIndigo
```

## Components

### Service setup

- [Public API](https://github.com/enercity/protoflow/blob/main/libapi.go): `libapi.go`
- [Configuration](https://github.com/enercity/protoflow/blob/main/internal/runtime/config/config.go): `internal/runtime/config/config.go`
- [Service and router](https://github.com/enercity/protoflow/blob/main/internal/runtime/service.go): `internal/runtime/service.go`

### Message handling

- [Protobuf handlers](https://github.com/enercity/protoflow/blob/main/internal/runtime/handlers/proto.go): `internal/runtime/handlers/proto.go`
- [JSON handlers](https://github.com/enercity/protoflow/blob/main/internal/runtime/handlers/json.go): `internal/runtime/handlers/json.go`
- [Protobuf registration](https://github.com/enercity/protoflow/blob/main/internal/runtime/handlers_proto.go): `internal/runtime/handlers_proto.go`
- [JSON registration](https://github.com/enercity/protoflow/blob/main/internal/runtime/handlers_json.go): `internal/runtime/handlers_json.go`
- [Raw registration](https://github.com/enercity/protoflow/blob/main/internal/runtime/handlers_raw.go): `internal/runtime/handlers_raw.go`
- [Message metadata](https://github.com/enercity/protoflow/blob/main/internal/runtime/metadata/metadata.go): `internal/runtime/metadata/metadata.go`
- [JSON codec](https://github.com/enercity/protoflow/blob/main/internal/runtime/jsoncodec/jsoncodec.go): `internal/runtime/jsoncodec/jsoncodec.go`

### Transport and publishing

- [Event publishing](https://github.com/enercity/protoflow/blob/main/internal/runtime/publisher.go): `internal/runtime/publisher.go`
- [Transport factory](https://github.com/enercity/protoflow/blob/main/internal/runtime/transport/factory.go): `internal/runtime/transport/factory.go`
- [AWS SNS/SQS](https://github.com/enercity/protoflow/blob/main/internal/runtime/transport/aws.go): `internal/runtime/transport/aws.go`
- [Go channel](https://github.com/enercity/protoflow/blob/main/internal/runtime/transport/channel.go): `internal/runtime/transport/channel.go`

### Cross-cutting runtime

- [Middleware stack](https://github.com/enercity/protoflow/blob/main/internal/runtime/middleware.go): `internal/runtime/middleware.go`
- [Logging adapters](https://github.com/enercity/protoflow/blob/main/internal/runtime/logging/logging.go): `internal/runtime/logging/logging.go`
- [Runtime web UI](https://github.com/enercity/protoflow/blob/main/internal/runtime/webui.go): `internal/runtime/webui.go`

### Other components

- **Application developer**
- **Message broker**
- **Outbox store**
- **Payload validator**

## Connections

- Application developer → Public API: configures and registers (evidence: `README.md`)
- Public API → Service and router: constructs service (evidence: `libapi.go`)
- Service and router → Configuration: uses config (evidence: `internal/runtime/service.go`)
- Service and router → Transport factory: builds transport (evidence: `internal/runtime/service.go`)
- Transport factory → AWS SNS/SQS: dispatches AWS (evidence: `internal/runtime/transport/factory.go`)
- Transport factory → Go channel: dispatches channel (evidence: `internal/runtime/transport/factory.go`)
- AWS SNS/SQS → Message broker: publishes and consumes (evidence: `internal/runtime/transport/aws.go`)
- Go channel → Message broker: publishes and consumes (evidence: `internal/runtime/transport/channel.go`)
- Public API → Protobuf registration: registers protobuf (evidence: `libapi.go`)
- Public API → JSON registration: registers JSON (evidence: `libapi.go`)
- Public API → Raw registration: registers raw handler (evidence: `libapi.go`)
- Protobuf registration → Protobuf handlers: builds handler (evidence: `internal/runtime/handlers_proto.go`)
- JSON registration → JSON handlers: builds handler (evidence: `internal/runtime/handlers_json.go`)
- Protobuf handlers → Message metadata: converts metadata (evidence: `internal/runtime/handlers/proto.go`)
- JSON handlers → Message metadata: converts metadata (evidence: `internal/runtime/handlers/json.go`)
- JSON handlers → JSON codec: encodes payloads (evidence: `internal/runtime/handlers/json.go`)
- Protobuf registration → Service and router: registers handler (evidence: `internal/runtime/handlers_proto.go`)
- JSON registration → Service and router: registers handler (evidence: `internal/runtime/handlers_json.go`)
- Raw registration → Service and router: adds router handler (evidence: `internal/runtime/handlers_raw.go`)
- Service and router → Middleware stack: registers middleware (evidence: `internal/runtime/service.go`)
- Service and router → Logging adapters: adapts logger (evidence: `internal/runtime/service.go`)
- Service and router → Runtime web UI: starts web UI
- Public API → Event publishing: exposes publishing (evidence: `libapi.go`)
- Event publishing → Message metadata: sets message metadata (evidence: `internal/runtime/publisher.go`)
- Event publishing → Message broker: publishes event (evidence: `internal/runtime/publisher.go`)
- Service and router → Outbox store: accepts optional store (evidence: `internal/runtime/service.go`)
- Service and router → Payload validator: accepts optional validator (evidence: `internal/runtime/service.go`)
- Application developer → Service and router: starts service (evidence: `README.md`)
