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

╄→гoц情女王★ 提交于 2019-12-12 08:02:48

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/7001405/organizing-the-directory-structure-of-my-ddd-based-web-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!