# ironbats/golanc-clean-arch architecture

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

- Interactive diagram: https://gitdiagram.com/ironbats/golanc-clean-arch
- Repository: https://github.com/ironbats/golanc-clean-arch

## Overview

1. **Overall shape**
   - This repo is a Go clean-architecture template organized around three domain areas: **user**, **contact**, and **address**.
   - The code is split into outer delivery/adapters, inner business logic, and infrastructure boundaries so the same use cases can be driven by either HTTP or messaging.

2. **Process entrypoints**
   - `cmd/web/main.go` starts the **HTTP API server**.
   - `cmd/worker/main.go` starts the **background worker/consumer process**.
   - Both entrypoints likely compose the same internal layers but expose different delivery mechanisms.

3. **Configuration and bootstrapping**
   - `internal/config` centralizes runtime wiring for **Fiber**, **GORM**, **Kafka**, **Viper**, **Logrus**, and **validator**.
   - `config.json` is the main runtime config source.
   - This layer is the main place where external dependencies are instantiated and injected into the app.

4. **HTTP delivery layer**
   - `internal/delivery/http` contains controllers for `user`, `contact`, and `address`.
   - `internal/delivery/http/route/route.go` defines the HTTP routing structure.
   - `internal/delivery/http/middleware/auth_middleware.go` provides request protection/authentication at the edge.
   - HTTP handlers convert incoming requests into internal models before calling use cases.

5. **Messaging delivery layer**
   - `internal/delivery/messaging` contains Kafka consumers for `user`, `contact`, and `address`.
   - These consumers represent the asynchronous inbound path for the same business domains.
   - The worker binary is the natural host for this side of the architecture.

6. **Use case layer**
   - `internal/usecase` contains the domain application logic for each aggregate: `user`, `contact`, and `address`.
   - This layer orchestrates validation, entity creation, repository access, and event/gateway interactions.
   - It is the core boundary where business rules live, independent of HTTP, Kafka, or MySQL.

7. **Domain and data shape separation**
   - `internal/entity` holds persistence/business entities used by repositories and use cases.
   - `internal/model` holds transport-facing models such as API payloads, auth structures, and event DTOs.
   - `internal/model/converter` bridges models and entities, showing a deliberate separation between external contract shape and internal domain shape.

8. **Persistence layer**
   - `internal/repository` contains repository implementations for `user`, `contact`, and `address`.
   - The repo uses **GORM** against **MySQL**, with schema managed by `db/migrations`.
   - Migrations exist for the three main tables: users, contacts, and addresses.

9. **Outbound messaging/gateway layer**
   - `internal/gateway/messaging` contains Kafka producers for the same three domains.
   - This is the outbound integration boundary used by use cases to publish events to external systems or downstream consumers.
   - The architecture therefore supports both synchronous CRUD-style flows and asynchronous event publication.

10. **Data flow through the system**
   - External request enters via **HTTP controller** or **Kafka consumer**.
   - Delivery layer maps request/event data into models.
   - Use case converts models to entities, applies business rules, and calls repositories.
   - Repositories persist to MySQL.
   - Use cases may also emit outbound models through Kafka producers via the gateway layer.

11. **Domain boundaries**
   - Each of the three domains is implemented consistently across the stack: controller/consumer, use case, repository, producer, converter, entity, and model.
   - This suggests a modular monolith rather than microservices, with clear per-domain packaging but shared runtime and infrastructure.

12. **API and documentation assets**
   - `api/api-spec.json` documents the HTTP API contract.
   - `architecture.excalidraw` and the README diagram are design references, not runtime components.
   - `test/` contains integration-style tests and manual HTTP tooling for validating the HTTP surface.

13. **Primary external systems**
   - **MySQL** is the persistence store.
   - **Apache Kafka** is the async messaging backbone.
   - **Fiber** handles HTTP, **GORM** handles ORM/database access, and **Viper/Logrus/Validator** support configuration, logging, and input validation.

14. **Architecture takeaway**
   - The repo is a layered clean-architecture backend with two delivery entrypoints, three domain modules, and explicit inbound/outbound adapters.
   - If you draw the diagram, center the use cases, place HTTP and Kafka consumers on the left as inbound adapters, and MySQL/Kafka producers on the right as outbound dependencies.

Main entry points: [`internal/delivery/http/route/route.go`](https://github.com/ironbats/golanc-clean-arch/blob/main/internal/delivery/http/route/route.go) (HTTP Routes), [`internal/config`](https://github.com/ironbats/golanc-clean-arch/tree/main/internal/config) (Config), [`internal/usecase/user_usecase.go`](https://github.com/ironbats/golanc-clean-arch/blob/main/internal/usecase/user_usecase.go) (User Usecase), [`internal/usecase/contact_usecase.go`](https://github.com/ironbats/golanc-clean-arch/blob/main/internal/usecase/contact_usecase.go) (Contact Usecase)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtimes"]
  node_cmd_web["Web API<br/>entrypoint<br/>[main.go]"]
  node_cmd_worker["Worker<br/>entrypoint<br/>[main.go]"]
end

subgraph group_delivery["Delivery"]
  node_http_routes["HTTP Routes<br/>router<br/>[route.go]"]
  node_http_mw["Auth Middleware<br/>[auth_middleware.go]"]
  node_http_user["User API<br/>controller<br/>[user_controller.go]"]
  node_http_contact["Contact API<br/>controller"]
  node_http_address["Address API<br/>controller"]
  node_msg_user["User Consumer<br/>[user_consumer.go]"]
  node_msg_contact["Contact Consumer"]
  node_msg_address["Address Consumer"]
end

subgraph group_core["Core"]
  node_usecase_user{{"User Usecase<br/>use case<br/>[user_usecase.go]"}}
  node_usecase_contact{{"Contact Usecase<br/>use case<br/>[contact_usecase.go]"}}
  node_usecase_address{{"Address Usecase<br/>use case<br/>[address_usecase.go]"}}
  node_converter["Converters<br/>mapper"]
  node_models["Models<br/>dto"]
  node_entities["Entities<br/>domain"]
end

subgraph group_infra["Infrastructure"]
  node_config["Config<br/>bootstrap"]
  node_repository[("Repositories<br/>persistence")]
  node_mysql[("MySQL<br/>database")]
  node_kafka_out["Kafka Producer<br/>gateway"]
  node_kafka_in["Kafka Backbone<br/>broker"]
  node_api_spec["API Spec<br/>documentation<br/>[api-spec.json]"]
end

node_cmd_web -->|"builds"| node_config
node_cmd_worker -->|"builds"| node_config
node_cmd_web -->|"hosts"| node_http_routes
node_http_routes -->|"uses"| node_http_mw
node_http_routes -->|"maps"| node_http_user
node_http_routes -->|"maps"| node_http_contact
node_http_routes -->|"maps"| node_http_address
node_http_user -->|"calls"| node_usecase_user
node_http_contact -->|"calls"| node_usecase_contact
node_http_address -->|"calls"| node_usecase_address
node_cmd_worker -->|"hosts"| node_msg_user
node_cmd_worker -->|"hosts"| node_msg_contact
node_cmd_worker -->|"hosts"| node_msg_address
node_msg_user -->|"calls"| node_usecase_user
node_msg_contact -->|"calls"| node_usecase_contact
node_msg_address -->|"calls"| node_usecase_address
node_usecase_user -->|"maps"| node_converter
node_usecase_contact -->|"maps"| node_converter
node_usecase_address -->|"maps"| node_converter
node_converter -->|"uses"| node_models
node_converter -->|"uses"| node_entities
node_usecase_user -->|"persists"| node_repository
node_usecase_contact -->|"persists"| node_repository
node_usecase_address -->|"persists"| node_repository
node_repository -->|"stores"| node_mysql
node_usecase_user -->|"publishes"| node_kafka_out
node_usecase_contact -->|"publishes"| node_kafka_out
node_usecase_address -->|"publishes"| node_kafka_out
node_kafka_in -->|"feeds"| node_msg_user
node_kafka_in -->|"feeds"| node_msg_contact
node_kafka_in -->|"feeds"| node_msg_address
node_config -->|"configures"| node_mysql
node_config -->|"configures"| node_kafka_in
node_config -->|"configures"| node_kafka_out
node_config -->|"wires"| node_http_routes
node_http_routes -.->|"documents"| node_api_spec

click node_cmd_web "https://github.com/ironbats/golanc-clean-arch/blob/main/cmd/web/main.go"
click node_cmd_worker "https://github.com/ironbats/golanc-clean-arch/blob/main/cmd/worker/main.go"
click node_http_routes "https://github.com/ironbats/golanc-clean-arch/blob/main/internal/delivery/http/route/route.go"
click node_http_mw "https://github.com/ironbats/golanc-clean-arch/blob/main/internal/delivery/http/middleware/auth_middleware.go"
click node_http_user "https://github.com/ironbats/golanc-clean-arch/blob/main/internal/delivery/http/user_controller.go"
click node_http_contact "https://github.com/ironbats/golanc-clean-arch/blob/main/internal/delivery/http/contact_controller.go"
click node_http_address "https://github.com/ironbats/golanc-clean-arch/blob/main/internal/delivery/http/address_controller.go"
click node_msg_user "https://github.com/ironbats/golanc-clean-arch/blob/main/internal/delivery/messaging/user_consumer.go"
click node_msg_contact "https://github.com/ironbats/golanc-clean-arch/blob/main/internal/delivery/messaging/contact_consumer.go"
click node_msg_address "https://github.com/ironbats/golanc-clean-arch/blob/main/internal/delivery/messaging/address_consumer.go"
click node_usecase_user "https://github.com/ironbats/golanc-clean-arch/blob/main/internal/usecase/user_usecase.go"
click node_usecase_contact "https://github.com/ironbats/golanc-clean-arch/blob/main/internal/usecase/contact_usecase.go"
click node_usecase_address "https://github.com/ironbats/golanc-clean-arch/blob/main/internal/usecase/address_usecase.go"
click node_converter "https://github.com/ironbats/golanc-clean-arch/tree/main/internal/model/converter"
click node_models "https://github.com/ironbats/golanc-clean-arch/tree/main/internal/model"
click node_entities "https://github.com/ironbats/golanc-clean-arch/tree/main/internal/entity"
click node_config "https://github.com/ironbats/golanc-clean-arch/tree/main/internal/config"
click node_repository "https://github.com/ironbats/golanc-clean-arch/tree/main/internal/repository"
click node_mysql "https://github.com/ironbats/golanc-clean-arch/tree/main/db/migrations"
click node_kafka_out "https://github.com/ironbats/golanc-clean-arch/tree/main/internal/gateway/messaging"
click node_kafka_in "https://github.com/ironbats/golanc-clean-arch/tree/main/internal/delivery/messaging"
click node_api_spec "https://github.com/ironbats/golanc-clean-arch/blob/main/api/api-spec.json"

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_cmd_web,node_cmd_worker toneBlue
class node_http_routes,node_http_mw,node_http_user,node_http_contact,node_http_address,node_msg_user,node_msg_contact,node_msg_address toneAmber
class node_usecase_user,node_usecase_contact,node_usecase_address,node_converter,node_models,node_entities toneMint
class node_config,node_repository,node_mysql,node_kafka_out,node_kafka_in,node_api_spec toneRose
```

## Components

### Runtimes

Process entrypoints that assemble and run the application

- [Web API](https://github.com/ironbats/golanc-clean-arch/blob/main/cmd/web/main.go): entrypoint · HTTP server entrypoint · `cmd/web/main.go`
- [Worker](https://github.com/ironbats/golanc-clean-arch/blob/main/cmd/worker/main.go): entrypoint · Background consumer entrypoint · `cmd/worker/main.go`

### Delivery

Inbound adapters for HTTP and messaging

- [HTTP Routes](https://github.com/ironbats/golanc-clean-arch/blob/main/internal/delivery/http/route/route.go): router · HTTP route wiring · `internal/delivery/http/route/route.go`
- [Auth Middleware](https://github.com/ironbats/golanc-clean-arch/blob/main/internal/delivery/http/middleware/auth_middleware.go): middleware · Request protection at the edge · `internal/delivery/http/middleware/auth_middleware.go`
- [User API](https://github.com/ironbats/golanc-clean-arch/blob/main/internal/delivery/http/user_controller.go): controller · HTTP controller for user flows · `internal/delivery/http/user_controller.go`
- [Contact API](https://github.com/ironbats/golanc-clean-arch/blob/main/internal/delivery/http/contact_controller.go): controller · HTTP controller for contact flows · `internal/delivery/http/contact_controller.go`
- [Address API](https://github.com/ironbats/golanc-clean-arch/blob/main/internal/delivery/http/address_controller.go): controller · HTTP controller for address flows · `internal/delivery/http/address_controller.go`
- [User Consumer](https://github.com/ironbats/golanc-clean-arch/blob/main/internal/delivery/messaging/user_consumer.go): consumer · Kafka consumer for user events · `internal/delivery/messaging/user_consumer.go`
- [Contact Consumer](https://github.com/ironbats/golanc-clean-arch/blob/main/internal/delivery/messaging/contact_consumer.go): consumer · Kafka consumer for contact events · `internal/delivery/messaging/contact_consumer.go`
- [Address Consumer](https://github.com/ironbats/golanc-clean-arch/blob/main/internal/delivery/messaging/address_consumer.go): consumer · Kafka consumer for address events · `internal/delivery/messaging/address_consumer.go`

### Core

Domain entities, models, use cases, and conversion boundaries

- [User Usecase](https://github.com/ironbats/golanc-clean-arch/blob/main/internal/usecase/user_usecase.go): use case · User business logic · `internal/usecase/user_usecase.go`
- [Contact Usecase](https://github.com/ironbats/golanc-clean-arch/blob/main/internal/usecase/contact_usecase.go): use case · Contact business logic · `internal/usecase/contact_usecase.go`
- [Address Usecase](https://github.com/ironbats/golanc-clean-arch/blob/main/internal/usecase/address_usecase.go): use case · Address business logic · `internal/usecase/address_usecase.go`
- [Converters](https://github.com/ironbats/golanc-clean-arch/tree/main/internal/model/converter): mapper · Bridges transport models and entities · `internal/model/converter`
- [Models](https://github.com/ironbats/golanc-clean-arch/tree/main/internal/model): dto · Transport-facing payloads and event DTOs · `internal/model`
- [Entities](https://github.com/ironbats/golanc-clean-arch/tree/main/internal/entity): domain · Persistence and domain entities · `internal/entity`

### Infrastructure

Configuration, persistence, and outbound integrations

- [Config](https://github.com/ironbats/golanc-clean-arch/tree/main/internal/config): bootstrap · Runtime wiring for app dependencies · `internal/config`
- [Repositories](https://github.com/ironbats/golanc-clean-arch/tree/main/internal/repository): persistence · GORM-backed repository implementations · `internal/repository`
- [MySQL](https://github.com/ironbats/golanc-clean-arch/tree/main/db/migrations): database · Primary persistence store · `db/migrations`
- [Kafka Producer](https://github.com/ironbats/golanc-clean-arch/tree/main/internal/gateway/messaging): gateway · Outbound event publication · `internal/gateway/messaging`
- [Kafka Backbone](https://github.com/ironbats/golanc-clean-arch/tree/main/internal/delivery/messaging): broker · Inbound messaging transport · `internal/delivery/messaging`
- [API Spec](https://github.com/ironbats/golanc-clean-arch/blob/main/api/api-spec.json): documentation · HTTP contract reference · `api/api-spec.json`

## Connections

- Web API → Config: builds · Web server bootstraps shared dependencies
- Worker → Config: builds · Worker bootstraps shared dependencies
- Web API → HTTP Routes: hosts · HTTP entrypoint serves routes
- HTTP Routes → Auth Middleware: uses · Routes apply authentication middleware
- HTTP Routes → User API: maps · Routes wire user controller endpoints
- HTTP Routes → Contact API: maps · Routes wire contact controller endpoints
- HTTP Routes → Address API: maps · Routes wire address controller endpoints
- User API → User Usecase: calls · HTTP user requests reach user business logic
- Contact API → Contact Usecase: calls · HTTP contact requests reach contact business logic
- Address API → Address Usecase: calls · HTTP address requests reach address business logic
- Worker → User Consumer: hosts · Worker runs user consumer
- Worker → Contact Consumer: hosts · Worker runs contact consumer
- Worker → Address Consumer: hosts · Worker runs address consumer
- User Consumer → User Usecase: calls · Consumed user messages trigger user use cases
- Contact Consumer → Contact Usecase: calls · Consumed contact messages trigger contact use cases
- Address Consumer → Address Usecase: calls · Consumed address messages trigger address use cases
- User Usecase → Converters: maps · User use cases translate between models and entities
- Contact Usecase → Converters: maps · Contact use cases translate between models and entities
- Address Usecase → Converters: maps · Address use cases translate between models and entities
- Converters → Models: uses · Converters consume transport DTOs
- Converters → Entities: uses · Converters produce domain entities
- User Usecase → Repositories: persists · User use cases access repositories
- Contact Usecase → Repositories: persists · Contact use cases access repositories
- Address Usecase → Repositories: persists · Address use cases access repositories
- Repositories → MySQL: stores · Repositories persist through GORM to MySQL
- User Usecase → Kafka Producer: publishes · User use cases emit events
- Contact Usecase → Kafka Producer: publishes · Contact use cases emit events
- Address Usecase → Kafka Producer: publishes · Address use cases emit events
- Kafka Backbone → User Consumer: feeds · Kafka delivers messages to user consumer
- Kafka Backbone → Contact Consumer: feeds · Kafka delivers messages to contact consumer
- Kafka Backbone → Address Consumer: feeds · Kafka delivers messages to address consumer
- Config → MySQL: configures · Configuration instantiates database wiring
- Config → Kafka Backbone: configures · Configuration instantiates inbound Kafka wiring
- Config → Kafka Producer: configures · Configuration instantiates producer wiring
- Config → HTTP Routes: wires · Configuration assembles HTTP routes
- HTTP Routes → API Spec: documents · HTTP surface is described by API spec
