Modular Architecture Hexagonal Demo Project

repository·main·Indexed 20 days ago

https://github.com/alicanakkus/modular-architecture-hexagonal-demo-project

A demonstration project for implementing Hexagonal Architecture (Ports and Adapters) using Java 11 and Spring Boot 2. The project focuses on modularity, test-driven development, and microservices within a Gradle mono-repo structure, utilizing MySQL, Redis, and Kafka.

Tokens
1K
Snippets
2
Records
5
Agent score
21%

What's inside modular-architecture-hexagonal-demo-project

  1. Overview of the Hexagonal Architecture Demo Project

    main

    This project is a production-ready sample implementation of Hexagonal Architecture (also known as the Ports and Adapters pattern) using Java. It is designed to demonstrate how to write clean, maintainable, and well-defined boundary contexts by isolating business logic from technical concerns and external integration points.

    Key learning objectives include:

    • Designing APIs using hexagonal architecture.
    • Implementing microservices with Spring Boot.
    • Using Ports and Adapters to separate business logic from integration points.
    • Implementing various testing styles: Unit tests (domain-focused), Integration tests (infra-focused), Consumer-driven contract tests, and Acceptance tests.
    • Managing multiple microservices in a single Git repository using a Mono-repo structure with Gradle.
  2. Run the demo infrastructure with Docker Compose

    main

    This project uses Docker Compose to orchestrate the required infrastructure services (MySQL, Redis, Zookeeper, and Kafka). To start the environment, ensure you have Docker and Docker Compose installed, then run the following command in the root directory of the project.

    Note that the MySQL service is configured to initialize using DDL scripts located in ./docs/ddl.

    docker-compose up
  3. Reference: Infrastructure service configurations

    main

    The following services are defined in the docker-compose.yml file. Use these details for connecting your application to the infrastructure.

    MySQL

    • Image: mysql
    • Port: 3306
    • Root Password: password (via MYSQL_ROOT_PASSWORD)
    • Initialization: DDL scripts from ./docs/ddl are mounted to /docker-entrypoint-initdb.d.

    Redis

    • Image: redis:alpine
    • Port: 6379
    • Password: redisPassword (set via --requirepass command)

    Zookeeper

    • Image: confluentinc/cp-zookeeper:latest
    • Client Port: 2181 (via ZOOKEEPER_CLIENT_PORT)
    • Tick Time: 2000 (via ZOOKEEPER_TICK_TIME)

    Kafka

    • Image: confluentinc/cp-kafka:latest
    • Ports: 9092 (PLAINTEXT), 29092 (External/Broker)
    • Zookeeper Connection: zookeeper:2181 (via KAFKA_ZOOKEEPER_CONNECT)
    • Advertised Listener: PLAINTEXT://localhost:9092 (via KAFKA_ADVERTISED_LISTENERS)
    services:
      mysql:
        image: mysql
        environment:
          MYSQL_ROOT_PASSWORD: password
        ports:
          - 3306:3306
    
      redis:
        image: "redis:alpine"
        command: redis-server --requirepass redisPassword
        ports:
          - "6379:6379"
    
      zookeeper:
        image: confluentinc/cp-zookeeper:latest
        environment:
          ZOOKEEPER_CLIENT_PORT: 2181
          ZOOKEEPER_TICK_TIME: 2000
    
      kafka:
        image: confluentinc/cp-kafka:latest
        ports:
          - 29092:29092
          - 9092:9092
        environment:
          KAFKA_BROKER_ID: 1
          KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
          KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
          KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1