Reputation: 1445
I understand how and why to structure a Symfony project. I just wonder if is there any preferred structure under the /src
direcotry. Beside the Controller
, DependencyInjection
, Entity
etc. how do you organize your source code?
Just crowd everything under Model
? Group larger logical bulks into dirs like Service
, Model
, Job
etc? Some group their files by functionality like:
Order
, Product
, PopupManager
etc. What is the most useful?
Upvotes: 0
Views: 2100
Reputation: 3105
There are many answers to this question. I think it highly depends on what your application involves. The following are some suggestion but keep in mind that you need to imagine the structure of your application by yourself.
Little project (less than 6months and a not too much of maintenance):
.
├── Controller
├── Entity
├── Factory
├── Provider
├── Repository
├── Security
└── YourCustomThing
Or if you prefer a domain approach (I do) you can have more something like this:
.
├── Product
│ ├── DTO
│ └── Model
└── User
├── Model
├── Provider
└── Security
If you have a more complex application, then you should probably learn about DDD or CQRS. Here is a little DDD example inspired by the DDD Cargo Sample (but there is a lot more to tell about DDD apps, as well as CQRS ones).
.
├── Application
│ ├── Booking
│ │ └── Dto
│ └── Exception
├── Http
│ └── Action
├── Infrastructure
│ ├── Persistence
│ └── Product
│ ├── ActionFactory
│ └── BookingFactory
└── Model
└── Shop
Hope it helps.
Upvotes: 1