Architectures
An architecture defines your project’s structure, dependency rules, and base files.
Hexagonal (Ports & Adapters)
Section titled “Hexagonal (Ports & Adapters)”The hexagonal architecture separates your application into layers with strict dependency direction — inner layers never import from outer layers.
domain/ → Pure business logic, no external dependenciesport/ → Interfaces (inbound use cases, outbound repositories)service/ → Use case implementationsadapter/ → External integrations (HTTP, DB, messaging)config/ → Configuration loading (via platform capability)platform/ → Cross-cutting concerns (via platform capability)internal/bootstrap/ → Dependency wiring (via bootstrap capability)cmd/<name>/ → Entry pointDependency Rules
Section titled “Dependency Rules”| Component | May Depend On |
|---|---|
| domain | nothing |
| ports | domain |
| service | domain, ports |
| adapters | ports, domain |
These rules are enforced by verikt check. If your adapter code imports from another adapter, or your domain imports from service — it’s caught immediately.
When to Use
Section titled “When to Use”Use hexagonal for production APIs and microservices where business logic is complex and you need strict separation of concerns. It’s especially valuable when multiple teams contribute to the same service — the enforced boundaries prevent the accidental coupling that tends to accumulate in flat or layered structures.
A single-package structure with just main.go and go.mod.
main.gogo.modWhen to Use
Section titled “When to Use”Use flat for CLI tools, simple scripts, and quick prototypes where layered structure would add friction without adding value.
Layered
Section titled “Layered”The most common architecture pattern — handler, service, and repository layers with a shared model package.
cmd/<name>/ → Entry pointinternal/handler/ → HTTP handlers (request/response)internal/service/ → Business logicinternal/repository/ → Data accessinternal/model/ → Shared types and domain modelsDependency Rules
Section titled “Dependency Rules”| Component | May Depend On |
|---|---|
| model | nothing |
| repository | model |
| service | repository, model |
| handler | service, model |
When to Use
Section titled “When to Use”Use layered when hexagonal feels like overkill — standard CRUD APIs with straightforward business logic, or teams already fluent in the traditional three-tier pattern who don’t need the port/adapter indirection.
Clean Architecture
Section titled “Clean Architecture”Uncle Bob’s Clean Architecture — entities at the core, use cases orchestrate, interfaces adapt.
cmd/<name>/ → Entry pointinternal/entity/ → Core business entities (no dependencies)internal/usecase/ → Application use casesinternal/interface/handler/ → HTTP handlers, adaptersinternal/infrastructure/ → Database, external services, configDependency Rules
Section titled “Dependency Rules”| Component | May Depend On |
|---|---|
| entity | nothing |
| usecase | entity |
| interface | usecase, entity |
| infrastructure | interface, usecase, entity |
When to Use
Section titled “When to Use”Use clean architecture when use cases are the central organizing concept and dependency discipline matters at scale. It’s a good fit for teams already fluent in Uncle Bob’s conventions, or large codebases where strict layering pays for itself.