Skip to content

Hexagonal Architecture

Pau F. Grau edited this page Jan 10, 2021 · 2 revisions

🎯 Ports and Adapters / Hexagonal Architecture

This repository follow the Ports and Adapters / Hexagonal Architecture pattern.

We organize the code with the follow structure:

src
β”œβ”€β”€ Bounded Context
β”‚ β”œβ”€β”€ Application
β”‚ β”‚ β”œβ”€β”€ Command
β”‚ β”‚ └── Query
β”‚ β”œβ”€β”€ Domain
β”‚ β”‚ β”œβ”€β”€ Event // All Subscribers subscribed to events
β”‚ β”‚ └── Model
β”‚ └── Infrastructure
β”‚     β”œβ”€β”€ Ports And Adapters
β”‚     └── UI
β”‚         β”œβ”€β”€ Command // CLI commands
β”‚         └── Controller

Example of Quotes API:

src
β”œβ”€β”€ Api
β”‚ β”œβ”€β”€ Application
β”‚ β”‚ β”œβ”€β”€ Command
β”‚ β”‚ β”‚ β”œβ”€β”€ ImportAuthors
β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ ImportAuthorsCommand.php
β”‚ β”‚ β”‚ β”‚ └── ImportAuthorsCommandHandler.php
β”‚ β”‚ β”‚ └── ImportQuotes
β”‚ β”‚ β”‚     β”œβ”€β”€ ImportQuotesCommand.php
β”‚ β”‚ β”‚     └── ImportQuotesCommandHandler.php
β”‚ β”‚ └── Query
β”‚ β”‚     └── GetShoutsByAuthor
β”‚ β”‚         β”œβ”€β”€ GetShoutsByAuthorQuery.php
β”‚ β”‚         β”œβ”€β”€ GetShoutsByAuthorQueryHandler.php
β”‚ β”‚         └── GetShoutsByAuthorQueryResponse.php
β”‚ β”œβ”€β”€ Domain
β”‚ β”‚ β”œβ”€β”€ Event
β”‚ β”‚ β”‚ β”œβ”€β”€ Author
β”‚ β”‚ β”‚ β”‚ └── CreateAuthorSubscriber.php
β”‚ β”‚ β”‚ β”œβ”€β”€ Quote
β”‚ β”‚ β”‚ β”‚ └── CreateQuoteSubscriber.php
β”‚ β”‚ β”‚ └── Shout
β”‚ β”‚ β”‚     └── ShoutsByAuthorSubscriber.php
β”‚ β”‚ └── Model
β”‚ β”‚     β”œβ”€β”€ Author
β”‚ β”‚     β”‚ β”œβ”€β”€ Author.php
β”‚ β”‚     β”‚ β”œβ”€β”€ AuthorCreatedV1.php
β”‚ β”‚     β”‚ β”œβ”€β”€ AuthorNotFound.php
β”‚ β”‚     β”‚ β”œβ”€β”€ AuthorProjection.php
β”‚ β”‚     β”‚ └── AuthorRepository.php
β”‚ β”‚     β”œβ”€β”€ Quote
β”‚ β”‚     β”‚ β”œβ”€β”€ Quote.php
β”‚ β”‚     β”‚ β”œβ”€β”€ QuoteCreatedV1.php
β”‚ β”‚     β”‚ β”œβ”€β”€ QuoteProjection.php
β”‚ β”‚     β”‚ └── QuoteRepository.php
β”‚ β”‚     └── Shout
β”‚ β”‚         β”œβ”€β”€ Shout.php
β”‚ β”‚         β”œβ”€β”€ ShoutCollection.php
β”‚ β”‚         └── ShoutsByAuthorRequestedV1.php
β”‚ └── Infrastructure
β”‚     β”œβ”€β”€ Framework
β”‚     β”‚ └── Symfony
β”‚     β”‚     └── Kernel.php
β”‚     β”œβ”€β”€ Persistence
β”‚     β”‚ β”œβ”€β”€ Dbal
β”‚     β”‚ β”‚ β”œβ”€β”€ Author
β”‚     β”‚ β”‚ β”‚ └── DbalAuthorProjection.php
β”‚     β”‚ β”‚ └── Quote
β”‚     β”‚ β”‚     └── DbalQuoteProjection.php
β”‚     β”‚ └── Doctrine
β”‚     β”‚     β”œβ”€β”€ Author
β”‚     β”‚     β”‚ └── DoctrineAuhorRepository.php
β”‚     β”‚     β”œβ”€β”€ Quote
β”‚     β”‚     β”‚ └── DoctrineQuoteRepository.php
β”‚     β”‚     └── mapping
β”‚     β”‚         β”œβ”€β”€ Author.Author.orm.xml
β”‚     β”‚         └── Quote.Quote.orm.xml
β”‚     └── UI
β”‚         β”œβ”€β”€ Command
β”‚         β”‚ β”œβ”€β”€ Author
β”‚         β”‚ β”‚ └── ImportAuthorsCommand.php
β”‚         β”‚ └── Quote
β”‚         β”‚     └── ImportQuotesCommand.php
β”‚         └── Controller
β”‚             β”œβ”€β”€ GetQuotesByAuthor
β”‚             β”‚ └── GetQuotesByAuthorController.php
β”‚             └── Ping
β”‚                 └── PingController.php
└── Shared
    β”œβ”€β”€ Domain
    β”‚ └── Model
    β”‚     β”œβ”€β”€ Aggregate
    β”‚     β”‚ └── AggregateRoot.php
    β”‚     β”œβ”€β”€ Api
    β”‚     β”‚ └── ApiError.php
    β”‚     β”œβ”€β”€ Bus
    β”‚     β”‚ β”œβ”€β”€ CommandBus.php
    β”‚     β”‚ β”œβ”€β”€ EventBus.php
    β”‚     β”‚ └── QueryBus.php
    β”‚     β”œβ”€β”€ Cache
    β”‚     β”‚ └── CacheRepository.php
    β”‚     β”œβ”€β”€ Command.php
    β”‚     β”œβ”€β”€ Event
    β”‚     β”‚ β”œβ”€β”€ DomainEvent.php
    β”‚     β”‚ β”œβ”€β”€ DomainEventPublisher.php
    β”‚     β”‚ β”œβ”€β”€ DomainEventSubscriber.php
    β”‚     β”‚ β”œβ”€β”€ EventFailed.php
    β”‚     β”‚ β”œβ”€β”€ EventFailedNotFoundException.php
    β”‚     β”‚ β”œβ”€β”€ EventFailedStore.php
    β”‚     β”‚ β”œβ”€β”€ EventNotPublished.php
    β”‚     β”‚ β”œβ”€β”€ EventNotPublishedNotFoundException.php
    β”‚     β”‚ β”œβ”€β”€ EventNotPublishedStore.php
    β”‚     β”‚ β”œβ”€β”€ EventStore.php
    β”‚     β”‚ β”œβ”€β”€ PublishableDomainEvent.php
    β”‚     β”‚ β”œβ”€β”€ StoredEvent.php
    β”‚     β”‚ └── StoredEventNotFoundException.php
    β”‚     β”œβ”€β”€ Exception
    β”‚     β”‚ β”œβ”€β”€ BadRequestException.php
    β”‚     β”‚ β”œβ”€β”€ ConflictException.php
    β”‚     β”‚ β”œβ”€β”€ NotFoundException.php
    β”‚     β”‚ └── ProjectException.php
    β”‚     β”œβ”€β”€ Query.php
    β”‚     └── Serializer
    β”‚         └── Serializer.php
    └── Infrastructure
        β”œβ”€β”€ Bus
        β”‚ β”œβ”€β”€ Custom
        β”‚ β”‚ └── CustomEventBus.php
        β”‚ └── League
        β”‚     β”œβ”€β”€ CommandBus.php
        β”‚     β”œβ”€β”€ CommandBusFactory.php
        β”‚     β”œβ”€β”€ CommandBusProvider.php
        β”‚     β”œβ”€β”€ DbalTransactionMiddleware.php
        β”‚     β”œβ”€β”€ QueryBus.php
        β”‚     β”œβ”€β”€ QueryBusFactory.php
        β”‚     └── QueryBusProvider.php
        β”œβ”€β”€ MessageBroker
        β”‚ β”œβ”€β”€ Dispatcher.php
        β”‚ β”œβ”€β”€ RabbitMq
        β”‚ β”‚ β”œβ”€β”€ RabbitMqConfigurer.php
        β”‚ β”‚ β”œβ”€β”€ RabbitMqConnection.php
        β”‚ β”‚ β”œβ”€β”€ RabbitMqDomainEventsConsumer.php
        β”‚ β”‚ β”œβ”€β”€ RabbitMqExchangeNameFormatter.php
        β”‚ β”‚ β”œβ”€β”€ RabbitMqFactoryConfigurer.php
        β”‚ β”‚ β”œβ”€β”€ RabbitMqFactoryConnection.php
        β”‚ β”‚ └── RabbitMqPublisher.php
        β”‚ └── SubscriberMapper.php
        β”œβ”€β”€ Persistence
        β”‚ β”œβ”€β”€ Dbal
        β”‚ β”‚ └── Event
        β”‚ β”‚     β”œβ”€β”€ DbalEventFailedStore.php
        β”‚ β”‚     β”œβ”€β”€ DbalEventNotPublishedStore.php
        β”‚ β”‚     └── DbalEventStore.php
        β”‚ β”œβ”€β”€ FakeCacheRepository.php
        β”‚ └── Redis
        β”‚     └── Cache
        β”‚         └── RedisCacheRepository.php
        β”œβ”€β”€ Serializer
        β”‚ └── PhpSerializer.php
        └── UI
            └── Command
                └── MessageBroker
                    β”œβ”€β”€ RabbitMqConfigureCommand.php
                    β”œβ”€β”€ RabbitMqConsumeDomainEventsCommand.php
                    └── RabbitMqUpDomainEventsConsumers.php
Clone this wiki locally