All Projects → bencagri → Symfony4 Ddd

bencagri / Symfony4 Ddd

Licence: mit
Bootstrap Application for Symfony 4 with Domain Driven Design

Projects that are alternatives of or similar to Symfony4 Ddd

Php Ddd Example
🐘🎯 Hexagonal Architecture + DDD + CQRS in PHP using Symfony 5
Stars: ✭ 1,960 (+1455.56%)
Mutual labels:  doctrine, symfony, domain-driven-design
Msgphp
Reusable domain layers. Shipped with industry standard infrastructure.
Stars: ✭ 182 (+44.44%)
Mutual labels:  doctrine, symfony, domain-driven-design
Symfony Demo App
A Symfony demo application with basic user management
Stars: ✭ 122 (-3.17%)
Mutual labels:  doctrine, symfony, domain-driven-design
Php Sf Flex Webpack Encore Vuejs
A simple app skeleton to try to make every components work together : symfony 4 (latest stable at the date, but work with sf 3.3+ if you just change the versions in composer.json), symfony/flex, webpack-encore, vuejs 2.5.x, boostrap 4 sass
Stars: ✭ 118 (-6.35%)
Mutual labels:  doctrine, symfony
Schema Generator
PHP Model Scaffolding from Schema.org and other RDF vocabularies
Stars: ✭ 379 (+200.79%)
Mutual labels:  doctrine, symfony
Sonatadoctrineormadminbundle
Integrate Doctrine ORM into the SonataAdminBundle
Stars: ✭ 400 (+217.46%)
Mutual labels:  doctrine, symfony
Doctrinecachebundle
Symfony2 Bundle for Doctrine Cache
Stars: ✭ 2,813 (+2132.54%)
Mutual labels:  doctrine, symfony
Doctrine Json Odm
An object document mapper for Doctrine ORM using JSON types of modern RDBMS.
Stars: ✭ 420 (+233.33%)
Mutual labels:  doctrine, symfony
Doctrinebundle
Symfony Bundle for Doctrine ORM and DBAL
Stars: ✭ 4,225 (+3253.17%)
Mutual labels:  doctrine, symfony
Idea Php Symfony2 Plugin
IntelliJ IDEA / PhpStorm Symfony Plugin
Stars: ✭ 797 (+532.54%)
Mutual labels:  doctrine, symfony
Kimai2
Kimai v2 is a web-based multiuser time-tracking application. Free for everyone: freelancers, agencies, companies, organizations - all can track their times, generate invoices and more. SaaS version available at https://www.kimai.cloud
Stars: ✭ 1,216 (+865.08%)
Mutual labels:  doctrine, symfony
Doctrinemigrationsbundle
Symfony integration for the doctrine/migrations library
Stars: ✭ 3,782 (+2901.59%)
Mutual labels:  doctrine, symfony
Fossdroid Core
Fossdroid Core is a web frontend of F-Droid: an alternative software repository comprising only free, open source software for Android. This repo is the open source version of fossdroid.com.
Stars: ✭ 329 (+161.11%)
Mutual labels:  doctrine, symfony
Doctrine Stats
Get Doctrine stats : managed entities, lazy loaded entities, hydration time etc.
Stars: ✭ 65 (-48.41%)
Mutual labels:  doctrine, symfony
Search
PHP search-systems made possible
Stars: ✭ 101 (-19.84%)
Mutual labels:  doctrine, symfony
Translationformbundle
Ease translations with some dedicated Symfony form types
Stars: ✭ 289 (+129.37%)
Mutual labels:  doctrine, symfony
Doctrineenumbundle
📦 Provides support of ENUM type for Doctrine in Symfony applications.
Stars: ✭ 410 (+225.4%)
Mutual labels:  doctrine, symfony
user
A domain layer providing basic user management
Stars: ✭ 14 (-88.89%)
Mutual labels:  doctrine, domain-driven-design
event-sourcing
A lightweight but also all-inclusive event sourcing library with a focus on developer experience and based on doctrine dbal
Stars: ✭ 65 (-48.41%)
Mutual labels:  doctrine, domain-driven-design
Forkcms
Fork is an easy to use open source CMS using Symfony Components.
Stars: ✭ 1,112 (+782.54%)
Mutual labels:  doctrine, symfony

Symfony 4 DDD Approach

Scrutinizer Code Quality Build Status

Article application with Symfony 4 and DDD Approach.

Advantages of Domain-Driven Design

  • Eases Communication: With an early emphasis on establishing a common and ubiquitous language related to the domain model of the project, teams will often find communication throughout the entire development life cycle to be much easier. Typically, DDD will require less technical jargon when discussing aspects of the application, since the ubiquitous language established early on will likely define simpler terms to refer to those more technical aspects.
  • Improves Flexibility: Since DDD is so heavily based around the concepts of object-oriented analysis and design, nearly everything within the domain model will be based on an object and will, therefore, be quite modular and encapsulated. This allows for various components, or even the entire system as a whole, to be altered and improved on a regular, continuous basis.
  • Emphasizes Domain Over Interface: Since DDD is the practice of building around the concepts of domain and what the domain experts within the project advise, DDD will often produce applications that are accurately suited for and representative of the domain at hand, as opposed to those applications which emphasize the UI/UX first and foremost. While an obvious balance is required, the focus on domain means that a DDD approach can produce a product that resonates well with the audience associated with that domain.

Read more about DDD

Folder Structure

├── bin
├── config
│   ├── packages
│   │   ├── dev
│   │   ├── prod
│   │   └── test
│   └── routes
│       └── dev
├── public
├── src
│   ├── Authorization
│   │   ├── Console
│   │   ├── Controller
│   │   └── Entity
│   │       └── Oauth2
│   ├── DataFixtures
│   └── Project
│       ├── App
│       │   ├── EventListener
│       │   ├── Interface
│       │   ├── Support
│       │   └── Trait
│       ├── Console
│       ├── Domain
│       │   ├── Article
│       │   │   └── Entity
│       │   └── User
│       │       ├── Contract
│       │       └── Entity
│       ├── Http
│       │   └── Controller
│       ├── Infrastructure
│       │   ├── Article
│       │   └── User
│       └── Resources
│            ├── config
│            ├── doctrine
│            │   └── mapping
│            └── routing
├── templates
├── tests
│   ├── functional
│   ├── integration
│   └── unit
├── translations
└── var
    ├── cache
    └── log

Lets make it work

git clone https://github.com/bencagri/symfony4-ddd-skeleton.git
cd symfony4-ddd-skeleton
composer install
bin/console doctrine:database:create
bin/console doctrine:schema:update --force
bin/console doctrine:fixtures:load 
php -S 127.0.0.1:9002 -t public

then visit 127.0.0.1:9002/api/doc you should see the documentation now.

With Docker

# Start the application
docker-compose up -d

# View logs to monitor installation progress
docker-compose logs -f

# Stop the application
docker-compose down

Making Request

When you try to make a request you will get an error. Because to make a request you need Access Token.

Lets try making a request;

curl -X GET "http://127.0.0.1:9002/api/articles?page=1&per_page=10" -H "accept: application/json"

It should say;

{
  "success": false,
  "error": {
    "code": 0,
    "message": "A Token was not found in the TokenStorage.",
    
    ...

This project is using Oauth2. So, first you need is to create a client. For this, it also has a command to create a oauth client.

bin/console oauth:client:create 

you should see something like;

Added a new client with  public id 6_2x0l2r8t6e2o4sggww08wwk88gs8sggsog0wk8cow4w0gso0s0.

Go and check your oauth_client table on database. you will see your secret also. Basically we have Authorization code, Password, Client Credentials and Refresh Token grant types. You can read more on Oauth Grant Types.

In this case, I prefer to go with Client Credentials grant type. For this, I need client_id and client_secret

I already know client id, it produced a client and told me the ID when I run the command. And my secret is on database.

So, lets take an Access Token to make a request to api.

curl -X GET \
  'http://127.0.0.1:9002/oauth/v2/token?client_id=6_2x0l2r8t6e2o4sggww08wwk88gs8sggsog0wk8cow4w0gso0s0&client_secret=4biwdp70w2yog4gs0s0c0808kww0c88sowoggggsg0swk48w08&grant_type=client_credentials' \
  -H 'cache-control: no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F client_id=1_4v0w0kiec9s0osgs8w40og8o4okc4ws08cos84c0gw4csoc8ws \
  -F client_secret=4biwdp70w2yog4gs0s0c0808kww0c88sowoggggsg0swk48w08 \
  -F grant_type=client_credentials
  

And The Response

{
    "access_token": "OWUyMTMxYzJjN2I5Nzg0ZTQ1N2NlZDNkMWYxZjFiZGE5N2RjMTA4ZmI1ZTU4ZGE0YWI4NmU3YmQxZjgyNTJkZg",
    "expires_in": 3600,
    "token_type": "bearer",
    "scope": null
}

great. I have an access token to make a request.

lets try to get an article now.

curl -X GET \
  http://127.0.0.1:9002/api/article/1 \
  -H 'authorization: Bearer OWUyMTMxYzJjN2I5Nzg0ZTQ1N2NlZDNkMWYxZjFiZGE5N2RjMTA4ZmI1ZTU4ZGE0YWI4NmU3YmQxZjgyNTJkZg' \
  -H 'cache-control: no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -H 'postman-token: 8635975a-6197-b8c6-c055-907a4668c503' \
  -F client_id=1_4v0w0kiec9s0osgs8w40og8o4okc4ws08cos84c0gw4csoc8ws \
  -F client_secret=4biwdp70w2yog4gs0s0c0808kww0c88sowoggggsg0swk48w08 \
  -F grant_type=client_credentials

And the response is;

{
    "success": true,
    "data": {
        "type": "article",
        "id": "1",
        "attributes": {
            "title": "My Test Article 0",
            "body": "lorem ipsum dolor sit amet.lorem ipsum dolor sit amet.lorem ipsum dolor sit amet.lorem ipsum dolor sit amet.lorem ipsum dolor sit amet.lorem ipsum dolor sit amet.lorem ipsum dolor sit amet.lorem ipsum dolor sit amet.lorem ipsum dolor sit amet.lorem ipsum dolor sit amet.",
            "tags": {},
            "createdAt": "2018-03-29"
        },
        "links": {
            "self": "http://127.0.0.1:9002/api/article/1"
        }
    }
}

Great, I got the article information with a request to GET /api/article/1

This package was built around JSON API to take advantage of its features around efficiently caching responses, sometimes eliminating network requests entirely.

Packages

  • Symfony Flex
  • Doctrine ORM Bundle
  • Doctrine Fixtures
  • Twig Bundle
  • Fos Oauth Server Bundle
  • Nelmio Doc Bundle
  • Symfony Profiler (dev)
  • Framework Extra Bundle
  • Fractal (PhpLeague)
  • PagerFanta for Doctrine
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].