The original post: /r/php by /u/samuelgfeller on 2025-01-02 13:21:26.

I’m looking to improve the architecture of the slim-example-project (follow up of this post 2 weeks ago) and would love to hear inputs on my thoughts.

Currently I have 3 main layers below src/:

  • Application (containing Middlewares, Responders and Actions of all Modules)
  • Domain (containing Services, DTOs, and also Repository classes even if they’re part of the infrastructure layer for the benefits of the Vertical Slice Architecture)
  • Infrastructure (containing the Query Factory and other shared Utilities that belong to the Infrastructure layer)

The things that bug me with the current implementation are:

  • Half-hearted implementation of the Vertical Slice Architecture as the Actions of each module are still kept outside of the module bundle.
  • It’s weird that Repository classes are a child of “Domain”

The following proposal would fix those two concerns and put all the layers inside each module folder which makes the application highly modular and practical to work on specific features.

├── src
│   ├── Core
│   │   ├── Application
│   │   │   ├── Middleware
│   │   │   └── Responder
│   │   ├── Domain
│   │   │   ├── Exception
│   │   │   └── Utility
│   │   └── Infrastructure
│   │       ├── Factory
│   │       └── Utility
│   └── Module
│       ├── {ModuleX}
│       │   ├── Action # Application/Action - or short Action
│       │   ├── Data # DTOs
│       │   ├── Domain
│       │   │   ├── Service
│       │   │   └── Exception
│       │   └── Repository # Infrastructure/Repository - short: Repository

The Action folder in the {Module} is part of the Application layer but to avoid unnecessary nesting I would put Action as a direct child of the module. The same is with Repository which is part of the infrastructure layer and not necessary to put it in an extra “infrastructure” folder as long as there are no other elements of that layer in this module.

There was a suggestion to put the shared utilities (e.g. middlewares, responder, query factory) in a “Shared” module folder and put every module right below /src but I’m concerned it would get lost next to all the modules and I feel like they should have a more central place than in the “module” pool. That’s why I’d put them in a Core folder.

Edit: I started refactoring work.