create account

Aurora - An Article Project with Symfony 4 and Domain Driven Design by bencagri

View this thread on: hive.blogpeakd.comecency.com
· @bencagri · (edited)
$66.50
Aurora - An Article Project with Symfony 4 and Domain Driven Design
<p align="center"><img src="http://oi66.tinypic.com/296gq6h.jpg"></p>

### Symfony 4 DDD Approach

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](https://airbrake.io/blog/software-design/domain-driven-design)

#### Folder Structure

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



#### Lets make it work 

```bash
git clone https://github.com/bencagri/symfony4-ddd.git
cd symfony4-ddd
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.

### 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;
```bash
curl -X GET "http://127.0.0.1:9002/api/articles?page=1&per_page=10" -H "accept: application/json"
```

It should say;
```bash
{
  "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.

```bash
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](https://oauth.net/2/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.

```bash

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
```bash
{
    "access_token": "OWUyMTMxYzJjN2I5Nzg0ZTQ1N2NlZDNkMWYxZjFiZGE5N2RjMTA4ZmI1ZTU4ZGE0YWI4NmU3YmQxZjgyNTJkZg",
    "expires_in": 3600,
    "token_type": "bearer",
    "scope": null
}
```

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

> Tip: You can use also postman. 

lets try to get an article now.

```bash 
curl -X GET \
  http://127.0.0.1:9002/api/article/1 \
  -H 'authorization: Bearer OWUyMTMxYzJjN2I5Nzg0ZTQ1N2NlZDNkMWYxZjFiZGE5N2RjMTA4ZmI1ZTU4ZGE0YWI4NmU3YmQxZjgyNTJkZg' \
  -H 'cache-control: no-cache' 
```

And the response is;
```bash
{
    "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](http://jsonapi.org/) to take advantage of its features around efficiently caching responses, sometimes eliminating network requests entirely.

<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@bencagri/aurora-an-article-project-with-symfony-4-and-domain-driven-design">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorbencagri
permlinkaurora-an-article-project-with-symfony-4-and-domain-driven-design
categoryutopian-io
json_metadata"{"community":"utopian","app":"utopian/1.0.0","format":"markdown","repository":{"id":124685277,"name":"symfony4-ddd","full_name":"bencagri/symfony4-ddd","html_url":"https://github.com/bencagri/symfony4-ddd","fork":false,"owner":{"login":"bencagri"}},"pullRequests":[],"platform":"github","type":"development","tags":["utopian-io","php","symfony4","domain-driven-design"],"users":["bencagri"],"links":["https://airbrake.io/blog/software-design/domain-driven-design","https://oauth.net/2/grant-types/","http://jsonapi.org/"],"moderator":{"account":"decebal2dac","time":"2018-03-30T12:07:27.704Z","reviewed":true,"pending":false,"flagged":false},"questions":[{"question":"Is the project description formal?","answers":[{"value":"Yes it’s straight to the point","selected":true,"score":10},{"value":"Need more description ","selected":false,"score":5},{"value":"Not too descriptive","selected":false,"score":0}],"selected":0},{"question":"Is the language / grammar correct?","answers":[{"value":"Yes","selected":true,"score":20},{"value":"A few mistakes","selected":false,"score":10},{"value":"It's pretty bad","selected":false,"score":0}],"selected":0},{"question":"Was the template followed?","answers":[{"value":"Yes","selected":false,"score":10},{"value":"Partially","selected":true,"score":5},{"value":"No","selected":false,"score":0}],"selected":1},{"question":"How do you rate the amount of work?","answers":[{"value":"Very High","selected":false,"score":20},{"value":"High","selected":false,"score":16},{"value":"Medium","selected":true,"score":12},{"value":"Low","selected":false,"score":7},{"value":"Very Low","selected":false,"score":3}],"selected":2},{"question":"How do you rate the impact on the Project?","answers":[{"value":"Very High","selected":false,"score":20},{"value":"High","selected":false,"score":16},{"value":"Medium","selected":true,"score":12},{"value":"Low","selected":false,"score":7},{"value":"Very Low","selected":false,"score":3}],"selected":2}],"score":50}"
created2018-03-29 16:24:21
last_update2018-03-30 12:07:27
depth0
children7
last_payout2018-04-05 16:24:21
cashout_time1969-12-31 23:59:59
total_payout_value46.250 HBD
curator_payout_value20.247 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6,420
author_reputation2,013,507,940,383
root_title"Aurora - An Article Project with Symfony 4 and Domain Driven Design"
beneficiaries
0.
accountutopian.pay
weight2,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id47,305,499
net_rshares27,203,330,075,432
author_curate_reward""
vote details (54)
@cheetah ·
Hi! I am a robot. I just upvoted you! I found similar content that readers might be interested in:
https://airbrake.io/blog/software-design/domain-driven-design
properties (22)
authorcheetah
permlinkcheetah-re-bencagriaurora-an-article-project-with-symfony-4-and-domain-driven-design
categoryutopian-io
json_metadata""
created2018-03-29 16:24:36
last_update2018-03-29 16:24:36
depth1
children0
last_payout2018-04-05 16:24:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length160
author_reputation942,693,160,055,713
root_title"Aurora - An Article Project with Symfony 4 and Domain Driven Design"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id47,305,527
net_rshares0
@decebal2dac ·
$1.01
Thank you for the contribution. It has been approved.

I am a big fan of DDD, here is one of the packages we use at my work place: https://github.com/funeralzone/valueobjects .
really helpful and friendly ValueObjects package.

There are a few suggestions I would make to your project however: try and not commit your IDE preference folder to git anymore (.idea), as it is not an actual contribution and it hardens collaboration while when practicing DDD you shouldn't need getters and setters in particular on your entities and your architecture should illustrate your bounded contexts first. 

All of that, this is a nice first step into educating yourself and helping others grasp some of the concepts useful with DDD.

You can contact us on [Discord](https://discord.gg/uTyJkNm).
**[[utopian-moderator]](https://utopian.io/moderators)**
👍  
properties (23)
authordecebal2dac
permlinkre-bencagri-aurora-an-article-project-with-symfony-4-and-domain-driven-design-20180330t121136404z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-03-30 12:11:39
last_update2018-03-30 12:11:39
depth1
children2
last_payout2018-04-06 12:11:39
cashout_time1969-12-31 23:59:59
total_payout_value0.762 HBD
curator_payout_value0.252 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length840
author_reputation13,975,053,566,819
root_title"Aurora - An Article Project with Symfony 4 and Domain Driven Design"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id47,444,108
net_rshares335,548,703,712
author_curate_reward""
vote details (1)
@bencagri ·
Hello @decebal2dac

This is kinda workshop project with my team. We are also still DDD learners. Yeah, that .idea folder is missed. =/ 

Your comment and suggestions were highly appreciated. 
I will share the getters and setters situation. 

thanks.
properties (22)
authorbencagri
permlinkre-decebal2dac-re-bencagri-aurora-an-article-project-with-symfony-4-and-domain-driven-design-20180330t141558271z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["decebal2dac"],"app":"steemit/0.1"}
created2018-03-30 14:14:39
last_update2018-03-30 14:14:39
depth2
children0
last_payout2018-04-06 14:14:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length249
author_reputation2,013,507,940,383
root_title"Aurora - An Article Project with Symfony 4 and Domain Driven Design"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id47,460,997
net_rshares0
@utopian.tip ·
Hey @decebal2dac, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!
properties (22)
authorutopian.tip
permlinkre-re-bencagri-aurora-an-article-project-with-symfony-4-and-domain-driven-design-20180330t121136404z-20180331t014137
categoryutopian-io
json_metadata""
created2018-03-31 01:41:36
last_update2018-03-31 01:41:36
depth2
children0
last_payout2018-04-07 01:41:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length161
author_reputation238,310,597,885
root_title"Aurora - An Article Project with Symfony 4 and Domain Driven Design"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id47,544,557
net_rshares0
@decebal2dac · (edited)
I would be interested to see if you could further improve the current architecture to show a little bit more domain. One task that I always struggle within my projects as well.
properties (22)
authordecebal2dac
permlinkre-bencagri-aurora-an-article-project-with-symfony-4-and-domain-driven-design-20180330t121327766z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-03-30 12:13:30
last_update2018-03-30 12:13:48
depth1
children1
last_payout2018-04-06 12:13:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length176
author_reputation13,975,053,566,819
root_title"Aurora - An Article Project with Symfony 4 and Domain Driven Design"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id47,444,338
net_rshares0
@bencagri ·
This project will be a real project for who needs. So commits will continue, I will, of course, try to improve the architecture.

Thanks again.
properties (22)
authorbencagri
permlinkre-decebal2dac-re-bencagri-aurora-an-article-project-with-symfony-4-and-domain-driven-design-20180330t141713461z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-03-30 14:15:54
last_update2018-03-30 14:15:54
depth2
children0
last_payout2018-04-06 14:15:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length143
author_reputation2,013,507,940,383
root_title"Aurora - An Article Project with Symfony 4 and Domain Driven Design"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id47,461,177
net_rshares0
@utopian-io ·
### Hey @bencagri I am @utopian-io. I have just upvoted you!
#### Achievements
- You have less than 500 followers. Just gave you a gift to help you succeed!
- Seems like you contribute quite often. AMAZING!
#### Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. <a href="https://discord.gg/zTrEMqB">Participate on Discord</a>. Lets GROW TOGETHER!
- <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for my Witness With SteemConnect</a>
- <a href="https://v2.steemconnect.com/sign/account-witness-proxy?proxy=utopian-io&approve=1">Proxy vote to Utopian Witness with SteemConnect</a>
- Or vote/proxy on <a href="https://steemit.com/~witnesses">Steemit Witnesses</a>

[![mooncryption-utopian-witness-gif](https://steemitimages.com/DQmYPUuQRptAqNBCQRwQjKWAqWU3zJkL3RXVUtEKVury8up/mooncryption-s-utopian-io-witness-gif.gif)](https://steemit.com/~witnesses)

**Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x**
properties (22)
authorutopian-io
permlinkre-bencagri-aurora-an-article-project-with-symfony-4-and-domain-driven-design-20180331t001851567z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-03-31 00:18:51
last_update2018-03-31 00:18:51
depth1
children0
last_payout2018-04-07 00:18:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,084
author_reputation152,955,367,999,756
root_title"Aurora - An Article Project with Symfony 4 and Domain Driven Design"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id47,536,839
net_rshares0