423

I'm learning about Domain Driven Design, however there are some practical issues that are confusing to me that I think seeing some good samples might clear up.

Does anyone know of some good working code samples that do a good job of modelling basic DDD concepts?

Particularly interested in

  • An illustrative Domain Model
  • Repositories
  • Use of Domain/Application Services
  • Value Objects
  • Aggregate Roots
Nick N.
  • 12,902
  • 7
  • 57
  • 75
jlembke
  • 13,217
  • 11
  • 42
  • 56
  • 48
    IHMO such debates will help a lot. Sometimes more than a simple question. E.g. we could change this in a question: "Where do i find some good examples for DDD?" and it works with the Q&A format. – Gizzmo Oct 10 '14 at 07:30
  • 2
    i have found the "agile management project" example from Vaughn Vernon's book very instructive. it illustrates practical implementation of the building blocks you enumerate, as well as dealing with different bounded contexts, you can find the code here: https://github.com/VaughnVernon/IDDD_Samples – Mehdi. Jun 02 '15 at 19:25
  • 1
    I would recommend this example: https://github.com/vkhorikov/DddInAction – Vladimir Jul 21 '16 at 21:09
  • 1
    You can have a look here: https://dzone.com/storage/assets/1216461-dzone-rc-domain-driven-design.pdf – Arefe Apr 11 '18 at 12:36
  • Got one here: https://github.com/appie2go/steal-this-code – Clark Kent May 06 '20 at 14:25
  • feel free to check this: youtu.be/MfEpw2WXXyk – Alireza Rahmani Khalili Apr 29 '22 at 14:47

7 Answers7

223

The difficulty with DDD samples is that they're often very domain specific and the technical implementation of the resulting system doesn't always show the design decisions and transitions that were made in modelling the domain, which is really at the core of DDD. DDD is much more about the process than it is the code. (as some say, the best DDD sample is the book itself!)

That said, a well commented sample app should at least reveal some of these decisions and give you some direction in terms of matching up your domain model with the technical patterns used to implement it.

You haven't specified which language you're using, but I'll give you a few in a few different languages:

DDDSample - a Java sample that reflects the examples Eric Evans talks about in his book. This is well commented and shows a number of different methods of solving various problems with separate bounded contexts (ie, the presentation layer). It's being actively worked on, so check it regularly for updates.

dddps - Tim McCarthy's sample C# app for his book, .NET Domain-Driven Design with C#

S#arp Architecture - a pragmatic C# example, not as "pure" a DDD approach perhaps due to its lack of a real domain problem, but still a nice clean approach.

With all of these sample apps, it's probably best to check out the latest trunk versions from SVN/whatever to really get an idea of the thinking and technology patterns as they should be updated regularly.

Matteo Tosato
  • 185
  • 3
  • 15
Michael Hart
  • 5,109
  • 3
  • 22
  • 21
  • 5
    As mentionned @Mehdi in the original question comment you should add the wonderful example from Vaughn Vernon. It is the best implementation of DDD pattern so far I have ever seen: github.com/VaughnVernon/IDDD_Samples – Sylvain Lecoy Mar 25 '17 at 14:13
  • I know this is old, but the example from `dddps` appears to be fully anemic and counter to OOP actually. None of the domain objects have any behavior, and the service layer classes are basically a 1:1 delegation to the repositories. I'm not sure if this should be considered a "good" example of DDD? I'm still learning myself, but the samples in S#arp Architecture seem to be a better example for those learning DDD as it emcompasses both state and behavior, which is good OOP design. – David Anderson Jan 21 '18 at 17:56
  • You should now add the excellent sample of Vaugnh Vernon the author of Implementing Domain Driven Design (IDDD): https://github.com/VaughnVernon/IDDD_Samples – Sylvain Lecoy Jan 24 '18 at 12:12
  • Any project for c++/c or golang user? – hunter_tech Sep 06 '20 at 23:47
25

Not source projects per say but I stumbled upon Parleys.com which has a few good videos that cover DDD quite well (requires flash):

I found these much more helpful than the almost non-existent DDD examples that are currently available.

Todd Smith
  • 17,084
  • 11
  • 59
  • 78
15

.NET DDD Sample from Domain-Driven Design Book by Eric Evans can be found here: http://dddsamplenet.codeplex.com

Cheers,

Jakub G

Gutek
  • 701
  • 7
  • 24
11

Check out Project Silk. Not only does it demonstrate DDD but other cutting edge patterns. This is an excellent resource for any Web Developer. A full overview of the project can be found on MSDN.

user996985
  • 119
  • 1
  • 2
6

ddd-cqrs-sample is also a good resource. Written with Java, Spring and JPA.

Updated link: https://github.com/BottegaIT/ddd-leaven-v2

Zaki
  • 6,997
  • 6
  • 37
  • 53
Rafał Wicha
  • 101
  • 2
  • 5
6

This is a good example based on domain driven design and explains why it is important to have separate domain layer.
Microsoft spain - DDD N Layer Architecture

prab2112
  • 1,024
  • 10
  • 36
Thurein
  • 6,645
  • 5
  • 22
  • 23
  • 2
    I can't vote this down but go to Ayende's blog to see why he thinks this is not a good example. http://ayende.com/blog/19457/review-microsoft-n-layer-app-sample-part-i – Chris Mar 01 '13 at 07:08
  • 2
    the link you provide doesn't work, message error: 'Project 'microsoftnlayerapp' was not found' – Omar AMEZOUG Mar 28 '19 at 08:10
5

Code Camp Server, Jeffrey Palermo's sample code for the book ASP.NET MVC in Action. While the book is focused on the presentation layer, the application is modeled using DDD.

Peter Tate
  • 2,178
  • 1
  • 21
  • 32