Démarrage rapide

Ce guide vous accompagne pas à pas dans la création d’un projet utilisant HexaGlue. En quelques minutes, vous allez :

  • Créer un domaine métier simple (gestion de tâches)
  • Configurer HexaGlue pour analyser votre code
  • Découvrir comment HexaGlue classifie automatiquement vos éléments architecturaux

Prérequis

  • Java 17 ou supérieur
  • Maven 3.8 ou supérieur
  • Un IDE de votre choix (IntelliJ IDEA, VS Code, Eclipse…)

Ce que vous allez construire

Un domaine de gestion de tâches minimaliste avec :

ÉlémentType architecturalDescription
TaskAggregate RootL’entité principale du domaine
TaskIdValue ObjectL’identifiant unique d’une tâche
TaskUseCasesDriving PortLes cas d’utilisation exposés
TaskRepositoryDriven PortL’abstraction de la persistance

Étape 1 : Créer la structure du projet

Option rapide : Cloner l’exemple

Pour démarrer immédiatement, clonez uniquement le projet sample-basic :

# Cloner uniquement le dossier examples/sample-basic
git clone --depth 1 --filter=blob:none --sparse \
https://github.com/hexaglue/hexaglue.git hexaglue-sample
cd hexaglue-sample
git sparse-checkout set examples/sample-basic
cd examples/sample-basic
# Lancer le build
mvn clean verify

Option manuelle : Créer depuis zéro

Si vous préférez créer le projet vous-même, voici la structure :

mon-projet/
├── pom.xml
└── src/main/java/com/example/
├── domain/
│ ├── Task.java
│ └── TaskId.java
└── ports/
├── in/
│ └── TaskUseCases.java
└── out/
└── TaskRepository.java

Cette structure reflète l’architecture hexagonale :

  • domain/ contient les objets métier (agrégats, value objects)
  • ports/in/ contient les ports entrants (cas d’utilisation)
  • ports/out/ contient les ports sortants (abstractions d’infrastructure)

Étape 2 : Écrire le domaine

Task.java : L’agrégat racine

L’agrégat Task représente une tâche dans notre système. C’est l’entité principale que HexaGlue va identifier automatiquement.

package com.example.domain;
import java.time.Instant;
/**
* Task aggregate root.
* Represents a task in a simple task management system.
*/
public class Task {
private final TaskId id;
private String title;
private String description;
private boolean completed;
private final Instant createdAt;
public Task(TaskId id, String title, String description) {
this.id = id;
this.title = title;
this.description = description;
this.completed = false;
this.createdAt = Instant.now();
}
public TaskId getId() { return id; }
public String getTitle() { return title; }
public String getDescription() { return description; }
public boolean isCompleted() { return completed; }
public Instant getCreatedAt() { return createdAt; }
/** Marks the task as completed. */
public void complete() {
this.completed = true;
}
/** Reopens a completed task. */
public void reopen() {
this.completed = false;
}
}

Comment HexaGlue le reconnaît : La classe possède un champ id de type TaskId (value object), ce qui indique un agrégat racine.

TaskId.java : Le value object

Le TaskId encapsule l’identifiant unique. Utiliser un record Java le rend immutable par conception.

package com.example.domain;
import java.util.UUID;
/**
* Task identifier.
* This is a value object wrapping the task's unique identifier.
*/
public record TaskId(UUID value) {
public static TaskId generate() {
return new TaskId(UUID.randomUUID());
}
public static TaskId fromString(String id) {
return new TaskId(UUID.fromString(id));
}
}

Comment HexaGlue le reconnaît : C’est un record avec un seul champ primitif/wrapper, utilisé comme identifiant dans un agrégat.


Étape 3 : Définir les ports

TaskUseCases.java : Le port entrant (Driving)

Ce port définit les opérations que le monde extérieur peut invoquer sur notre domaine.

package com.example.ports.in;
import com.example.domain.Task;
import com.example.domain.TaskId;
import java.util.List;
import java.util.Optional;
/**
* Primary port for task management use cases.
* This is a driving port that defines the operations
* available to external actors (UI, API, etc.).
*/
public interface TaskUseCases {
Task createTask(String title, String description);
Optional<Task> getTask(TaskId id);
List<Task> listAllTasks();
void completeTask(TaskId id);
void deleteTask(TaskId id);
}

Comment HexaGlue le reconnaît : Interface dans un package ports.in ou ports/in, manipulant des objets du domaine.

TaskRepository.java : Le port sortant (Driven)

Ce port définit ce dont le domaine a besoin de l’infrastructure (ici, la persistance).

package com.example.ports.out;
import com.example.domain.Task;
import com.example.domain.TaskId;
import java.util.List;
import java.util.Optional;
/**
* Secondary port for task persistence.
* This is a driven port that defines the operations
* the domain needs from the persistence layer.
*/
public interface TaskRepository {
Task save(Task task);
Optional<Task> findById(TaskId id);
List<Task> findAll();
void delete(Task task);
}

Comment HexaGlue le reconnaît : Interface dans un package ports.out ou ports/out, avec des méthodes de type repository (save, findById, delete).


Étape 4 : Configurer HexaGlue

Créez votre pom.xml avec la configuration HexaGlue :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>mon-projet</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<java.version>17</java.version>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<!-- HexaGlue Maven Plugin -->
<plugin>
<groupId>io.hexaglue</groupId>
<artifactId>hexaglue-maven-plugin</artifactId>
<version>4.0.0</version>
<extensions>true</extensions>
<configuration>
<basePackage>com.example</basePackage>
</configuration>
<dependencies>
<!-- Plugin Living Documentation -->
<dependency>
<groupId>io.hexaglue.plugins</groupId>
<artifactId>hexaglue-plugin-living-doc</artifactId>
<version>2.0.0</version>
</dependency>
<!-- Plugin Audit DDD -->
<dependency>
<groupId>io.hexaglue.plugins</groupId>
<artifactId>hexaglue-plugin-audit</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

Comprendre la configuration

ParamètreDescription
basePackageLe package racine à analyser
hexaglue-plugin-living-docGénère une documentation vivante de l’architecture
hexaglue-plugin-auditVérifie la conformité aux principes DDD et hexagonaux

Étape 5 : Lancer l’analyse

Exécutez la compilation Maven :

mvn clean compile

HexaGlue analyse votre code et affiche sa progression :

mvn clean compile
[INFO] --- hexaglue:4.0.0:generate (default-hexaglue-generate) @ minimal ---
[INFO] HexaGlue analyzing: com.example
[INFO] Loading plugin configurations from: hexaglue.yaml
[INFO] Loaded configurations for 3 plugin(s)
[INFO] Building semantic model for base package: com.example
[INFO] Semantic model built: 5 types
[INFO] Building application graph
[INFO] Graph built: 35 nodes, 51 edges
[INFO] Classifying types
[INFO] Classification complete: 2 domain types, 2 ports, 0 conflicts
[INFO] Building ArchitecturalModel
[INFO] Executing plugins
[INFO] Discovered 2 plugins
[INFO] Filtered to 1 plugins matching enabled categories: [GENERATOR]
[INFO] Executing plugin: io.hexaglue.plugin.livingdoc
[INFO] [io.hexaglue.plugin.livingdoc] Generating living documentation in: living-doc
[INFO] [io.hexaglue.plugin.livingdoc] Generated architecture overview
[INFO] [io.hexaglue.plugin.livingdoc] Generated domain model documentation
[INFO] [io.hexaglue.plugin.livingdoc] Generated ports documentation
[INFO] [io.hexaglue.plugin.livingdoc] Generated architecture diagrams
[INFO] [io.hexaglue.plugin.livingdoc] Living documentation complete: 1 aggregate roots, 0 entities, 1 value objects, 1 driving ports, 1 driven ports
[INFO] Plugin io.hexaglue.plugin.livingdoc completed in 11ms, generated 4 files
[INFO] Plugins executed: 1 plugins, 4 files generated
[INFO] Analysis complete in 404ms
[INFO] Analysis complete: 5 types, 4 classified, 2 ports in 404ms
[INFO] Generated 4 files

Que signifie ce résultat ?

HexaGlue a analysé 5 types Java et en a classifié 4 automatiquement :

ClasseClassificationRaison
TaskAGGREGATE_ROOTPossède un identifiant de type value object
TaskIdVALUE_OBJECTRecord immutable utilisé comme identifiant
TaskUseCasesDRIVING_PORTInterface dans ports.in
TaskRepositoryDRIVEN_PORTInterface dans ports.out avec pattern repository

Le 5ème type (MinimalApplication) n’est pas classifié car c’est une classe Spring Boot de démarrage, sans rôle architectural.


Étape 6 : Explorer les résultats

Après la compilation, explorez le dossier target/hexaglue/reports/living-doc/ :

target/hexaglue/reports/living-doc/
├── README.md # Vue d'ensemble de l'architecture
├── domain.md # Modèle du domaine (agrégats, entités, value objects)
├── ports.md # Documentation des ports (driving et driven)
└── diagrams.md # Diagrammes d'architecture (Mermaid)

Documentation vivante

Ces fichiers Markdown contiennent une documentation complète de votre architecture, générée automatiquement et mise à jour à chaque compilation :

  • README.md : Vue d’ensemble du système
  • domain.md : Agrégats, entités et value objects
  • ports.md : Ports entrants et sortants
  • diagrams.md : Diagrammes de composants et de flux au format Mermaid

Lancer l’audit

Pour vérifier la conformité aux principes DDD et hexagonaux, exécutez :

mvn verify

Le plugin audit s’exécute automatiquement en phase verify et affiche un rapport complet :

mvn verify
[INFO] --- hexaglue:4.0.0:audit (default-hexaglue-audit) @ minimal ---
[INFO] HexaGlue auditing: com.example
[INFO] Building semantic model for base package: com.example
[INFO] Semantic model built: 5 types
[INFO] Building application graph
[INFO] Graph built: 35 nodes, 51 edges
[INFO] Classifying types
[INFO] Classification complete: 2 domain types, 2 ports, 0 conflicts
[INFO] Building ArchitecturalModel
[INFO] Executing plugins
[INFO] Discovered 2 plugins
[INFO] Filtered to 1 plugins matching enabled categories: [AUDIT]
[INFO] Executing plugin: io.hexaglue.plugin.audit.ddd
[INFO] [io.hexaglue.plugin.audit.ddd] Audit complete: 2 violations, 7 metrics
[INFO] [io.hexaglue.plugin.audit.ddd]
────────────────────────────────────────────────────────────────────────────────
│ HexaGlue Audit Report │
────────────────────────────────────────────────────────────────────────────────
Project: Minimal HexaGlue Example
Timestamp: 2026-01-18 13:36:55
Duration: 7ms
HexaGlue Version: 1.0.0
Status: PASSED
Summary:
Total Violations: 2
Blockers: 0
Criticals: 0
Majors: 2
Minors: 0
Infos: 0
================================================================================
VIOLATIONS
================================================================================
1. WARNING - hexagonal:port-coverage
Message: Port 'TaskUseCases' has no adapter implementation
Location: com.example.ports.in.TaskUseCases:1:1
2. WARNING - hexagonal:port-coverage
Message: Port 'TaskRepository' has no adapter implementation
Location: com.example.ports.out.TaskRepository:1:1
================================================================================
METRICS
================================================================================
code.boilerplate.ratio 45.45 % max 50.00 OK
domain.purity 100.00 % min 100.00 OK
aggregate.boundary 100.00 % OK
domain.coverage 50.00 % min 30.00 OK
port.coverage 100.00 % min 100.00 OK
aggregate.avgSize 8.00 methods max 20.00 OK
────────────────────────────────────────────────────────────────────────────────
[INFO] [io.hexaglue.plugin.audit.ddd] Generated JSON report
[INFO] [io.hexaglue.plugin.audit.ddd] Generated HTML report
[INFO] [io.hexaglue.plugin.audit.ddd] Generated MARKDOWN report
[INFO] [io.hexaglue.plugin.audit.ddd] v4 Model: 1 aggregates, 0 entities, 1 value objects, 1 driving ports, 1 driven ports
[INFO] Plugin io.hexaglue.plugin.audit.ddd completed in 32ms
[INFO] ────────────────────────────────────────────────────────────────────────────────
[INFO] AUDIT SUMMARY
[INFO] ────────────────────────────────────────────────────────────────────────────────
[INFO] Total Violations: 2
[INFO] Errors: 0
[INFO] Warnings: 2
[INFO] Info: 0
[INFO] Status: PASSED
[INFO] ────────────────────────────────────────────────────────────────────────────────
[INFO] Audit completed: PASSED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

Comprendre le rapport d’audit

  • Status: PASSED : Le build ne bloque pas (aucune violation bloquante ou critique)
  • 2 violations WARNING : Les ports TaskUseCases et TaskRepository n’ont pas d’implémentation (adapter). C’est normal à ce stade car nous n’avons pas encore créé les adapters.
  • Métriques : HexaGlue mesure la qualité de votre architecture (pureté du domaine, couverture des ports, ratio de boilerplate…)

Structure complète des fichiers générés

Après mvn verify, le dossier target/hexaglue/reports/ contient :

target/hexaglue/reports/
├── living-doc/
│ ├── README.md # Vue d'ensemble de l'architecture
│ ├── domain.md # Modèle du domaine
│ ├── ports.md # Documentation des ports
│ └── diagrams.md # Diagrammes d'architecture
└── audit/
├── audit-report.json # Format JSON pour CI/CD
├── audit-report.html # Rapport HTML navigable
└── AUDIT-REPORT.md # Format Markdown

Prochaines étapes

Vous avez configuré HexaGlue avec succès. Voici comment aller plus loin :

Ajouter la génération JPA

Pour générer automatiquement les entités JPA et repositories Spring Data :

<dependency>
<groupId>io.hexaglue.plugins</groupId>
<artifactId>hexaglue-plugin-jpa</artifactId>
<version>2.0.0</version>
</dependency>

Activer la validation stricte

Pour échouer la compilation si des types restent non classifiés :

<configuration>
<basePackage>com.example</basePackage>
<failOnUnclassified>true</failOnUnclassified>
</configuration>

Explorer les exemples

Rejoindre la communauté


Résumé

En quelques minutes, vous avez :

  1. Créé un domaine métier suivant l’architecture hexagonale
  2. Configuré HexaGlue pour analyser automatiquement votre code
  3. Obtenu une classification de vos éléments architecturaux
  4. Généré une documentation vivante de votre architecture
  5. Exécuté un audit architectural avec métriques de qualité

HexaGlue transforme votre code en un modèle architectural exploitable, sans annotations invasives ni configuration complexe.