Giter VIP home page Giter VIP logo

dahromy / symfony-hexagonal-architecture Goto Github PK

View Code? Open in Web Editor NEW
56.0 1.0 12.0 1.34 MB

Example of a Symfony application using Domain-Driven Design (DDD) and Test Driver Development (TDD) principes keeping the code as simple as possible.

JavaScript 11.80% CSS 0.09% PHP 79.08% Twig 8.27% SCSS 0.76%
symfony architecture cqrs ddd doctrine domain-driven-design hexagonal hexagonal-architecture php phpunit

symfony-hexagonal-architecture's Introduction

👋 Hello, I'm Roméo Razafindrakoto!

Banner

🚀 About Me

Passionate PHP/Symfony developer with 4 years of experience. Backend expert, self-taught, and always eager to learn new technologies. Proud winner of HACK4PEACE 2021 with the "ZOTOMAHAY" project.

💻 Technical Skills

PHP Symfony JavaScript Vue.js SQL Docker Git RESTful APIs

🌟 Key Projects

  • ZOTOMAHAY - 1st place at HACK4PEACE 2021

🎓 Education

  • Bachelor's Degree in Computer Science - ESTI (École Supérieure des Technologies d'Information), 2021 Integration and Development Track (IDEV)

💼 Professional Experience

Web Developer at MyAgency (2020 - present)

  • Backend development with Symfony (versions 4.4 to 7.0)
  • Full-stack web application creation
  • Performance optimization and end-to-end project management

📫 How to Reach Me

Email LinkedIn


⭐️ From Roméo Razafindrakoto

symfony-hexagonal-architecture's People

Contributors

dahromy avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

symfony-hexagonal-architecture's Issues

Issue in hexagonal implementation for the controller.

Hey there.
In the UI web controller you are using symfony http response which goes against hexagonal architecture.
I would suggest to build a service in infrastructure where you implement the http response and then use its interface on your controller.
Example: In Domain create MyHttpResponseInterface and implement it in MySymfonyHttpResponse class (in infrastructure), then use this interface in your controller.

Here an example how I built a controller:

<?php

declare(strict_types=1);

namespace App\Product\Infrastructure\Controller;

use App\Product\Application\Query\GetProductQuery;
use App\Product\Domain\Dto\Product\ProductDto;
use App\Product\Domain\Dto\Uuid;
use App\Product\Domain\Exception\DomainExceptionInterface;
use App\Product\Domain\NormalizerAndSerializer\ModelNormalizerInterface;
use App\Product\Domain\Validator\ModelValidatorInterface;
use App\Product\Domain\Validator\JsonValidatorInterface;
use App\Shared\Domain\Bus\Query\QueryBus;
use App\Shared\Domain\Http\HttpResponseFactoryInterface;
use App\Shared\Domain\Http\HttpResponseInterface;
use App\Shared\Domain\Http\RequestInterface;
use App\Shared\Domain\Http\ResponseDataBuilderInterface;

class ProductController
{
    public function __construct(
        readonly HttpResponseFactoryInterface $httpResponseFactory,
        readonly ResponseDataBuilderInterface $responseDataBuilder,
        readonly QueryBus $queryBus,
        readonly ModelValidatorInterface $modelValidator,
        readonly ModelNormalizerInterface $normalizer,
        readonly JsonValidatorInterface $jsonValidator
    ) {}

    public function getSingle(string $productId, ?string $resourceType = null): HttpResponseInterface
    {
        try {
            $errors = $this->modelValidator->validate([new Uuid($productId)]);

            if ($errors) {
                throw new DomainBadRequestException($errors);
            }

            /** @var ProductDto $product */
            $product = $this->queryBus->ask(new GetProductQuery($productId));

            if (!$product) {
                throw new DomainNotFoundException([]);
            }
            return $this->httpResponseFactory->create(
                $this->responseDataBuilder->build($product, false, ''),
                200,
                $resourceType
            );
        } catch (DomainExceptionInterface $domainException) {
            return $this->httpResponseFactory->create(
                $this->responseDataBuilder->build($domainException->getData(), true, $domainException->getMessage()),
                $domainException->getStatusCode(),
                $resourceType
            );
        }
    }
    }

Let me know what you think :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.