Build StatusHex.pmDocumentationCoverage Status

Elixir Structure Manager

Elixir plugin to create an elixir application based on Clean Architecture following our best practices.

Install

HexDocs

mix archive.install hex elixir_structure_manager <version>

Tasks

mix help | grep "mix ca."
TaskDescription
mix ca.new.structureCreates a new clean architecture application.
mix ca.new.modelCreates a new model with empty properties
mix ca.new.usecaseCreates a new usecase
mix ca.new.daCreates a new driven adapter
mix ca.new.epCreates a new entry point
mix ca.apply.configApplies some project configuration

Task detail

mix <task> -h

Example

mix ca.new.structure -h
Creates a new Clean architecture scaffold
$ mix ca.new.structure [application_name]
$ mix ca.new.structure [application_name] --metrics --distillery
$ mix ca.new.structure [application_name] -m -d

Generate Project

The ca.new.structure task will generate a clean architecture structure in your project.

mix ca.new.structure <project-name>
mix ca.new.structure <project-name> --metrics --distillery
mix ca.new.structure <project-name> -m -d

The structure will look like this

app
├── config
├── config.exs
├── dev.exs
├── prod.exs
└── test.exs
├── lib
├── application.ex
├── config
├── app_config.ex
└── config_holder.ex
├── domain
├── behaviours
├── model
└── use_cases
├── infrastructure
├── driven_adapters
└── entry_points
├── api_rest.ex
└── health_check.ex
└── utils
├── certificates_admin.ex
├── custom_telemetry.ex
└── data_type_utils.ex
├── mix.exs
├── mix.lock
└── rel
├── config.exs
├── plugins
└── vm.args

Generate Model

Creates a new model for the clean architecture project

mix ca.new.model <model_name>
mix ca.new.model <model_name> --behaviour
mix ca.new.model <model_name> -b
mix ca.new.model <model_name> --behaviour-name <behaviour_name>
mix ca.new.model <model name> -n <behaviour_name>

This task will generate something like that:

domain
├── behaviours
└── model_behaviour.ex
└── model
└── model.ex

Generate Use Case

Creates a new usecase for the clean architecture project

mix ca.new.usecase <name_usecase>

This task will generate something like that:

domain
└── use_cases
└── use_case.ex

Generate Driven Adapter

Creates a new driven adapter for the clean architecture project.

mix ca.new.da --type <driven_adapter_name>

Type param options:

NameDescription
asynceventbusRabbitMQ message sender
dynamoAWS Dynamo DB client
genericEmpty structure for an adapter
redisRedis client
repositoryEcto repository setup
restconsumerHTTP(S) Client
secrestsmanagerAWS Secrets Manager client
mix ca.new.da --type <driven_adapter_name> --name <my_adapter>
mix ca.new.da -t driven_adapter_name -n <my_adapter>

This task will generate something like that:

infrastructure
└── driven_adapters
└── rest_consumer
└── <name>
├── data
├── <name>_request.ex
└── <name>_response.ex
└── <name>_adapter.ex

Generate Entry Point

Creates a new driven adapter for the clean architecture project

mix ca.new.ep --type <entry_point_name>

Type param options:

NameDescription
asynceventhandlerRabbitMQ message listener
mix ca.new.ep --type <entry_point_name> --name <my_entry_point>
mix ca.new.ep -t entry_point_name -n <my_entry_point>

This task will generate something like that:

infrastructure
└── entry_points
└── async_messages
└── async_message_handlers.ex

Apply a Project Configuration

Applies a configuration for the clean architecture project

mix ca.apply.config -t <config_type>

Type param options:

NameDescription
metricsAdd metrics setup for adapters and exporter
distilleryConfigures releases with distillery (will be deprecated)
sonarConfigures some snoar dependencies for analysis and reports

Metrics

This configuration type will instrument the application and their supporter adapters and entry points When the project is instrumented by passing the flag -m or by running this task every new adapter will be generated with instrumentation by default if supported.

The curren status of instrumentation

AdapterMetricsTraces
api_rest (default)
asynceventhandler
redis
asynceventbus
x aws (any request)
repository
restconsumer

Distillery

Creates distillery configuration for the clean architecture project.

It generates the next project files:

rel
├── plugins
| └── .gitignore
└── config.exs

It also injects the rel/config.exs file with the next config_providers for prod env

set config_providers: [{Distillery.Releases.Config.Providers.Elixir, ["${RELEASE_ROOT_DIR}/etc/config.exs"]}] # Use config file at runtime

Sonar

If you are using sonar, you can autogenerate the configuration files, these files will help you to:


Uninstall

Get version

mix archive
mix archive.uninstall elixir_structure_manager-<version>

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/elixir_structure_manager.