Skip to main content

Hexagonal Coherence Check

This project checks if the dependency flow between the layers of the Hexagonal architecture defined for this project was respected.

How to install

It can be easily installed via pip: pip install hexagonal-py

How to configure your project

There are two ways to configure hexagonal-py:

  1. Using pyproject.toml (recommended)
  2. Using hexagonal_config.py, which is expected to be on your main source folder.

It's necessary to define your hexagonal layers and their order. Given for example, the project structure below:

pyproject.toml (Optinal)
. src
├── __init__.py
├── hexagonal_config.py (Optional)
├── domain
│   ├── __init__.py
│   ├── __pycache__
│   └── person.py
├── infrastructure
│   ├── __init__.py
│   └── person_mysql_repository.py
├── main.py
├── services
│   ├── __init__.py
│   └── person_repository.py
└── usecases
    ├── __init__.py
    └── create_person_usecase.py
.tests    

General aspects:

  1. Existing layers: domain, infrastructure, services, usecases.
  2. Which should respect the following dependency flow: infrastructure -> usecases -> services -> domain
  3. Exclude tests from checks

If you are using pyproject.toml, you would have this:

[tool.hexagonalpy]
excluded_dirs = ['/tests']

[tool.hexagonalpy.layer.1]
name = 'Domain'
directories_groups = [['/domain']]

[tool.hexagonalpy.layer.2]
name = 'Services'
directories_groups = [['/services']]

[tool.hexagonalpy.layer.3]
name = 'Use Cases'
directories_groups = [['/usecases']]

[tool.hexagonalpy.layer.4]
name = 'Infrastructure'
directories_groups = [['/infrastructure']]

If you are using hexagonal_config.py:

from hexagonal.hexagonal_config import hexagonal_config

hexagonal_config.add_inner_layer_with_dirs(layer_name='infrastructure', directories=['/infrastructure'])
hexagonal_config.add_inner_layer_with_dirs(layer_name='use_cases', directories=['/use_cases'])
hexagonal_config.add_inner_layer_with_dirs(layer_name='services', directories=['/services'])
hexagonal_config.add_inner_layer_with_dirs(layer_name='domain', directories=['/domain'])

hexagonal_config.excluded_dirs = ['/tests']

Extra content

  1. excluded_dirs
    List of directories that you want to exclude from the hexagonal-py validation.
    Syntax: excluded_dirs = ['/tests', '/another_folder', '/another_folder2']

  2. Layers
    List of layers you defined in your project. There are 3 aspects you need to fill in for a layer: layer order, name, directories_groups.

2.1. Layer order: The number of the layers tells the order of the dependency flow between them. Where the most inner layer is 1 and the most outer layer is the greater number. Example:

[tool.hexagonalpy.layer.1] # Layer 1, as it's the most inner layer, and it can't point to any other layer but all the 
                           # other layers can point to it.
name = 'domain'
directories_groups = [['/domain']]

2.2. Name: The readable name of the layer, that will be used for documentation, internal messages etc.

2.3. Directories_groups: It's a list of a list. You can specify which folders belong to the given layer, and you can also define that some folders can't point to other folders inside the same layer. For instance, the MySql and Postgres components belongs to Infrastructure Layer but can't refer to each other.

[tool.hexagonalpy.layer.4] 
name = 'Infrastructure'
directories_groups = [['/Infrastructure/MySql'],['Infrastructure/Postgres']]

Generating the Project Diagram

This command generate a visual diagram show the composition of your hexagonal layers.

Pre requisites

To generate the Hexagonal Diagram of the project, it's necessary to have Graphviz installed in the machine.
For Mac you can brew install graphviz.
For other, check the documentation https://graphviz.org/download/.

CMD

hexagonal diagram --project_path ./ --source_path ./src

Checking Project's Hexagonal Integrity

This checks if the correct flow of the dependencies -from outer to inner layer- was respected.

CMD

hexagonal check --project_path ./ --source_path ./src

Metadata

Release files for hexagonal-py 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hexagonal-py 0.1.5
File Size Uploaded Provenance Actions
hexagonal-py-0.1.5.tar.gz 12.9 kB Without provenance Details for hexagonal-py-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hexagonal-py 0.1.5
File Interpreter ABI Platform Actions
hexagonal_py-0.1.5-py3-none-any.whl Python 3 none any Details for hexagonal_py-0.1.5-py3-none-any.whl

Total release size: 31.4 kB

Release files / hexagonal-py-0.1.5.tar.gz

Download URL hexagonal-py-0.1.5.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c06d60e396fa6a0288342e3f066d51e6dd7956221e73a5b42a1d90e3605d838b
BLAKE2b-256 checksum
How to use checksums
db09dc4d38e08df17c53ef9d2ed3ee0901eee4fb70d8cd557dd320bf10eaaf7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.9.10 Linux/5.11.0-1027-azure

Release files / hexagonal_py-0.1.5-py3-none-any.whl

Download URL hexagonal_py-0.1.5-py3-none-any.whl
Size 18.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
03998cf1086e845e5a31efc656b0867abb62bcbc4babe998ec907c275728c669
BLAKE2b-256 checksum
How to use checksums
91e623015ba2bfc15008a4d5af9652bb52d7a48441da8269da332b69096414b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.9.10 Linux/5.11.0-1027-azure

Security for hexagonal-py 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page