How ironbats/golanc-clean-arch works
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: route.go HTTP Routes · config Config · user_usecase.go User Usecase · contact_usecase.go Contact Usecase
Components 22
Runtimes
Process entrypoints that assemble and run the application
Delivery
Inbound adapters for HTTP and messaging
- HTTP Routes · HTTP route wiring
internal/delivery/http/route/route.go - Auth Middleware · Request protection at the edge
internal/delivery/http/middleware/auth_middleware.go - User API · HTTP controller for user flows
internal/delivery/http/user_controller.go - Contact API · HTTP controller for contact flows
internal/delivery/http/contact_controller.go - Address API · HTTP controller for address flows
internal/delivery/http/address_controller.go - User Consumer · Kafka consumer for user events
internal/delivery/messaging/user_consumer.go - Contact Consumer · Kafka consumer for contact events
internal/delivery/messaging/contact_consumer.go - Address Consumer · Kafka consumer for address events
internal/delivery/messaging/address_consumer.go
Core
Domain entities, models, use cases, and conversion boundaries
- User Usecase · User business logic
internal/usecase/user_usecase.go - Contact Usecase · Contact business logic
internal/usecase/contact_usecase.go - Address Usecase · Address business logic
internal/usecase/address_usecase.go - Converters · Bridges transport models and entities
internal/model/converter - Models · Transport-facing payloads and event DTOs
internal/model - Entities · Persistence and domain entities
internal/entity
Infrastructure
Configuration, persistence, and outbound integrations
- Config · Runtime wiring for app dependencies
internal/config - Repositories · GORM-backed repository implementations
internal/repository - MySQL · Primary persistence store
db/migrations - Kafka Producer · Outbound event publication
internal/gateway/messaging - Kafka Backbone · Inbound messaging transport
internal/delivery/messaging - API Spec · HTTP contract reference
api/api-spec.json
Connections 36
- 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