HexaGen

The Architecture Guardian for Phoenix: Build clean ecosystems, not spaghetti code.

HexaGen is a standardized Hexagonal Architecture scaffolding tool that extends the default Phoenix generators. It enforces a strict separation of concerns using the Ports and Adapters pattern, ensuring your business logic remains pure and entirely decoupled from technical details like databases or external APIs.

Why HexaGen?

Standard Phoenix contexts often grow organically, inevitably mixing Ecto logic, web presentation, and business rules into tightly coupled monoliths. HexaGen prevents this by enforcing a directory structure that follows SOLID principles out of the box.

More than just a generator, HexaGen is a strict architectural guardian. By automating infrastructure, tests, and monitoring—and strictly decoupling the domain from the web layer—HexaGen allows development teams to save up to 40% of setup and refactoring time, letting developers focus exclusively on what matters: the core business rules.

The Architecture

Hexagonal Architecture Diagram

Features

Getting Started

1. Installation

Add hexagen to your mix.exs:

def deps do
  [
    {:hexagen, "~> 0.1.3", only: :dev}
  ]
end

2. Setup

Run the setup task to prepare the project folders:

mix hexagen.setup

3. Generate a Hexagonal Context

mix hexagen.gen.context Accounts User users name:string age:integer

4. Generate Web Layers

mix hexagen.gen.html Accounts User users name:string
mix hexagen.gen.json Accounts User users name:string
mix hexagen.gen.live Accounts User users name:string

SOLID Compliance

Contributing

Contributions are welcome. If you have suggestions for improving the scaffolding or adding new adapters, please open an issue or pull request.