After some thought and consideration, I have decided to restructure my existing directory structure of an app I have which is currently sliced Horizontally (in layers), into a Vertical Sliced approach.
To match the desired structure I changed my project files in this question to match the below linked example and make things clear.
- Controllers [Based on Request Method, GET, POST, PUT, calls appropriate service method]
- ProductsController.php
- Data
- DAL [Data Access Layer - Specific Read / Write Queries]
- Products
- Mapper [Maps parameter array to object]
- ProductsMapper.php
- Model [Contains classes matching table structure]
- Product.php
- Service [Business Logic]
- ProductsService.php
- Provider [Database Connection Class]
- Database.php
So, after some research, I came to conclude that it would make things easier if I model my application structure using Vertical Slices and found a clarifying example.
Out with the Onion, in With The Vertical Slices
- Features
- Products
- AddFavoriteProduct
- AddFavoriteProductController.php
- AddFavoriteProductCommand.php
- AddFavoriteProductResponse.php
- AddFavoriteProductCommandHandler.php
- AddFavoriteProductContainer.js
- AddFavoriteProduct.js
- AddFavoriteProduct.css
- GetProductList
- GetProductListController.php
- GetProductListQuery.php
- GetProductListResponse.php
- GetProductListCommandHandler.php
- GetProductListContainer.js
- GetProductList.js
- GetProductList.css
The problem I face is what do I delegate to each of these four files.
My general understanding is as follows.
Controller - Handles the request and calls command/query, or is this CommandHandler?
Command/Query - This has insert/update commands, or database queries which in my case will be facilitated through an Object Relational Mapping framework like Doctrine
Response - Returns to the user the desired information, or command status result as a JSON
CommandHandler - Unclear what goes in here...
Looking for some example snippet, or some clarification to start. Description of the function of each of the four components would be helpful.