luddinus's avatar

Domain Driver Design, directory help

Hi.

I'm trying to follow this pattern, based a little bit on this project: https://github.com/spatie/attended.io/tree/master/app

This is my directory structure (more or less)

app
---...
---Domain
------User
---------Actions
------------UpdatePasswordAction.php
---------Models
------------User.php
------------Guest.php
---Http
------Controllers
---------Api
------------UsersController.php
-------------...
------Resources?
---------...

I want to make an api using Laravel Resources.

By default Laravel saves the Resources (via artisan) in the Http/Resources directory. Is it "more correct", in this case (UserListResource), to save in Domain/User/Resources directory? Or resources "belong" to Http?

At this time I think it fits better in Http/Resources directory because it's and "entry" point to the app.

Suggestions welcome!

0 likes
3 replies
bobbybouwmann's avatar

I would personally place this in the Http directory as well. The Domain layer should be defining how your domain looks like and not what the entry point is. Your domain services, models and classes should be used in the resource to fetch the data. The resource class should then return the correct format for that data.

You're already on the right track! Keep it up :D

1 like
luddinus's avatar

@BOBBYBOUWMANN - @bobbybouwmann Thanks.

Now I'm having asking my self what about "Actions". Should be the action classes cares about the validation, or I would have to "presuppose" that always when I run that actions the data is validated?

I was thinking to "extend" the Actions to FormRequest class, because of the validation helpers (and authorization), but I have the same problem with the other question. A Request that not belongs to the Domain directory.

On the other hand, I "know" that a special validation rule should be placed in Domain/Rules directory... (or similar)

bobbybouwmann's avatar

It depends a bit on the action and what you definition is of validation. For example validation can mean user input from a form, but validation can also mean that the user needs to be in a specific state.

For example an action for activating someones account can only be done whenever the account is not active right. it doesn't make sense to do this twice. So you can validate that as well. You don't have to throw an exception for that, you can simply return in the action and continue with the next step.

Please or to participate in this conversation.