2

General Context

I started reading about layer based architectures like DDD, Onion, Clean Architecture etc. I am considering switching, but am currently unclear about how strict the "first level division" into layers is.

Current State of the App

For the app we are working on, imagine a mix between a webshop and the video game The Sims: The user is placing and configuring products in a 3D environment, but the end goal is to present them with a bill for all these products.

At the top level, the app is divided into floors, window decorations, users etc. Each of these "categories" has their own views, their own business rules etc. and does not interact with the other categories. They implement common interfaces where they need to be brought to a common standard, e.g. the price calculation.

So, our app is currently primarily divided into what would probably be called "subdomains".

What's unclear

I understand that views belong in a UI layer, but what I am unclear about is if there is supposed to be only one, or if the layer structure can exist for every sub-domain.

I never found this stated explicitly, but I think I am supposed to take e.g. all the views out of all those domains and put them into one common UI layer. I think it can be summarized as the primary concern is not what part of the business the code is about, but what the code does in a technical sense.

The Question

Do layered architectures condone separation first by "subdomains" and then by layers? Is this maybe even handled differently in different types of layered architecture?

  • What you're calling "subdomains" I could simply call sections of your domain. If these sections are very independent, and potentially even use a ubiquitous language of their own, then these might actually be Bounded Contexts. But, from your example, it sounds like you have one Domain, one Bounded Context, and a bunch of item categories within them. – MetaFight May 8 '18 at 15:08
1

Both approaches are valid.

1: Single app which covers more than one domain

enter image description here

2: App per domain

enter image description here

enter image description here

| improve this answer | |
  • I think this is the other way around... I was talking about one app all the time. So, for example, one app with 2 domains like example 1 here, but also with 2 UI layers and 2 data layers. – R. Schmitz May 8 '18 at 10:59
  • 1
    how would it be possible to have 2 ui layers in one app? – Ewan May 8 '18 at 11:16
  • For example, there's a view showing a type of floor with all it's details, and this is currently closer to all the other code concerning floors than to the UI code working with e.g. window decorations. I am assuming it wouldn't be called one layer if it's actually spread around like that. Each "category" has their complete own set of layers, pretty much. – R. Schmitz May 8 '18 at 11:28
  • 'closer'? the separation between business and ui or data layer is defined by whether and how the classes are coupled. Assuming you have separated them out then the 'view layer' for an app is all the classes in the app which are 'view classes' you cant have two view/data/business layers or have view/data classes in the business/domain layer although you can split them amongst many projects/namespaces/assemblies if you want – Ewan May 8 '18 at 11:35
  • So theoretically, I could have one single solution with a single folder with all the code files in it - it would still be DDD/etc, as long as none of the code touches the layers it shouldn't touch? It might just have been a misunderstanding, because every tutorial I found created different projects in a solution for different layers. – R. Schmitz May 8 '18 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.