Giter VIP home page Giter VIP logo

clean-architecture's Introduction

clean-architecture

Code Climate Build Status

Package for isolate your domain code from framework dependency

What are Domain,Application and Infrastructure layer? Click here for a resume.

Why?

Why did you code this package?

When I code, I usually isolate the Domain layer from Application layer and Infrastructure layer, and every time I do it I need to re-build a set of objects that helps me doing this.

Those objects often are a Request, a Response and some Errors.

This package is born for me, to avoid re-building such set of objects, also avoiding some copy/paste from different projects.

Why should you isolate your domain code from Application and Infrastructure dependencies?

Imagine that your PHP application is currently built on top of Laravel framework.

And use a modern frameworks (such Laravel, Symfony or Slim) is a very good thing. Helps you to write a better code without reinvent the wheel.

But what if you want/must switch your current framework for performance, architectural or other reasons to an another one?

Usually this is very painful, and you are despondent to change it. This choose bind you to a tool that might not be as good as before for your project.

And this is only an example. There can be a lot of more reasons why you want to change framework.

How can I isolate it?

Using some DDD concepts, you can totally (or almost) isolate your domain code from the Application layer (Laravel for example) and from the Infrastructure layer (Postgresql or Mysql for example).

So the Domain of my application is not relegated to a particular framework/package/database, and can be "easily" switched.

What hepls me to realize this package?

There are some books that helped me to "think" in this way. Here some of them:

Clean PHP

DDD in PHP

DDD by Evans

A Minimal Documentation

  • Common

    • Collections

      • Collection

        An interface to use instead an array of objects.

      • ArrayCollection

        An implementation of Collection using php array.

    • Enum

      • Enum

        Used for give Enum support on PHP.

      • ReflectionEnum

        An implementation of Enum using reflection.

  • Mapper

    • Mapper

      An interface to use for transform object into array and viceversa.

    • UserMapper

      An interface to use for transform User instances into array and viceversa.

  • Persistence

    • Transaction

      An interface to use for transaction cross Bounded Contexts.

  • Use Cases

    • UseCase

      An interface to use for isolate the use case from the request (CLI,HTTP...).

    • Error

      • Error

        A representation of a generic error in the domain. The error it will be specified using type & code.

      • AbstractError

        An abstract implementation of ErrorInterface.

      • ErrorType

        An interface that extends Enum, used for specify all the error type of your domain.

      • AbstractErrorType

        An implementation of ErrorType.

    • Request

      • Request

        An interface used as DTO for pass data from the infrastructure/application to the domain.

      • CollectionRequest

        An implementation of the Request using Collection.

    • Response

      • Response

        An interface used for pass data from the domain to the infrastructure/application, it uses two main properties Errors: pass all "errors" Data: pass all other "data/information"

      • CollectionResponse

        An implementation of Response using Collection.

    • Validation

      • ValidableRequest

        An interface used for the validate request's data inside the self request

      • ValidableUseCase

        An interface used for the validate request's data inside the UseCase

A Practical Example

  • Slim

    This is a simple example of a TODO list of users, using slim microframework and clean architecture package. For any doubt or info add an issue.

Changelog

[0.4] 2018-06-01

  • [BC] added a type-hing to Enum interface. You need to adapt equals method in your class implementing such inteface (or extending ReflectionEnum class)

clean-architecture's People

Contributors

damianopetrungaro avatar bigfoot90 avatar garak avatar

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.