Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Organizing the directory structure of my DDD-based web application?

I have started to look away from the normal MVC way of creating my web applications and have had a look at Domain Driven Design - DDD.

From having Models alone, I now have Collections, Entities, DataMappers & Repositories in my application to work with. Full-fledged separation and modularity for sure, but now my directory structure is nothing but a complete mess!

As I have never worked with a DDD-application in the past, I have little idea on how to organize my file structure.

Would below be an appropriate directory structure?
Note: I am using PHP5, but I reckon this question to be close to language-agnostic.

/application
    /common
        /libraries
        /helpers
    /temp
        /cache
    /domain
        /collections
        /entities
        /datamappers
        /repositories
    /ui
        /controllers
        /view
like image 880
Industrial Avatar asked Aug 09 '11 18:08

Industrial


1 Answers

I would think that makes sense, but, that is going to separate your modules into what layer they are at, rather then what they do. For example, in this structure, if you wanted an Authentication and printing modules, you would have probably something like this:

    /common
        /helpers
             /Authentication
                 /AuthenticationService.php
             /Printing
                 /PrintingService.php
    /domain
        /entities
             /Authentication
                 /Identity.php
             /Printing
                 /Printer.php
        /datamappers
             /Authentication
                 /IdentityDataMap.php
             /Printing
                 /PrinterDataMap.php

Having worked in a system like this, I can say for one thing, it gets very hard to keep the boundaries between modules from inter-meshing, just because humans are working in the layers, and thinking of the layers as 'all together'. Just from an organizational standpoint, I don't really like having to have three root level directories open to work with a particular module. We organize projects into directories to make it easier for us to deal with, not the compiler.

If I was doing it again, I would separate some things by layer, say UI code, on one level, and business code on another, but then by module under that. More of a hybrid I suppose, but perhaps better for it.

    /domain
        /Printing
            /entities
            /datamappers
            /repositories
        /Auth
            /entities
            /datamappers
            /repositories
    /ui
        /controllers
        /view
like image 126
Steve Avatar answered Oct 25 '22 20:10

Steve