EP7: 5 Tips for Using ChatGPT in Domain-Driven Design

EP7: 5 Tips for Using ChatGPT in Domain-Driven Design

I'm back! During my absence from the newsletter these past months, I've been working very hard and learning a lot along the way. In particular, I've improved the way I leverage tools like ChatGPT in complex areas like Domain-Driven Design (DDD).

In this episode, I'll share with you 5 tips that will allow you to generate good quality domain model diagrams. I really advise you to have a look, even if you don't practice DDD, because you might be able to leverage the same approaches in your craft! If you have more tips in mind or disagree with something, make sure to use the comment section on my website!

You also find the context of this episode as a video on my YouTube channel.

Provide Context

The first and most important step is to provide context to the AI.

We need to achieve three goals with the first prompt:

  • Describe the domain as clearly as possible
  • Define few concrete use cases that the domain is meant to support
  • Set expectations
First Prompt to ChatGPT in a DDD brainstorming

Above there is one example showcasing the first prompt I used to kickstart a brainstorming session with ChatGPT. Notice how I took the time to present the problem rather than just asking a direct question without context.

This is because the quality of the AI’s response depends heavily on the clarity and completeness of our prompt.

When we provide clear and specific details, we help the AI understand our goals and focus. By outlining our expectations, we guide the AI towards generating responses that meet our needs.

Finally, when we describe the domain, use cases, or context clearly, we minimize ambiguity, which reduces the potential of errors in the response.

Ask for Diagrams as Code

The second tip is to ask ChatGPT to create diagrams as code. Tools like Mermaid or PlantUML are ideal for visualizing domains with clear representations of entities, value objects, and their relationships.

ChatGPT generated Diagram

They also allow ChatGPT to leverage its coding capabilities to generate accurate diagrams, instead of relying on tools like DALL·E or ASCII, which tend to produce poor results.

While native diagram rendering in OpenAI would be great, it's just one click to copy the code into your editor. From there, you can refine the diagram and use it in your software architecture documentation.

If you don't have a favorite editor yet, try out Mermaid Live!

Iterate And Itemize Your Feedback

The third tip is to iterate and itemize your feedback.

ChatGPT won't generate a perfect domain model on the first try—it needs your input and guidance over several iterations to get it right. While I spend time providing as much context as possible in the first prompt, I keep my feedback concise and itemized in follow-up prompts.

Follow-up prompt with itemized feedback

The goal is to guide the AI in addressing specific issues or concerns without overwhelming it. This prevents ChatGPT from introducing new problems while trying to fix existing ones. Sometimes, the AI can get off track and start producing lower-quality responses. Once that happens, there's no way to recover, and you'll have to restart the brainstorming session.

By keeping your feedback concise and itemized, you help avoid this and reduce the number of iterations needed to complete the domain model.

Use o1-preview

The fourth tip is to use the o1-preview ChatGPT model.

After comparing 4o and o1-preview on the same domain modeling exercises multiple times, I found that o1-preview consistently produces better results with fewer iterations. For instance, it only took four iterations for o1-preview to generate this diagram.

ChatGPT o1-preview introduced in September 2024

This happens because o1-preview takes more time to 'think' before responding, breaking down the reasoning process into stages we can access once the response is complete. This works perfectly with our itemized feedback approach, guiding the AI to consider multiple angles before answering.

Released just a month ago, OpenAI claims o1-preview can reason through complex tasks and solve harder problems, performing on par with PhD students in areas like science, coding, and math.

There's also the new GPT-4o with canvas, but I haven’t had the chance to fully experiment with it yet. I’ll update you in the coming weeks. 

Translate the Domain Model to Code

Can you guess the final tip? This one’s simple—once you’ve finished designing the domain model, ask ChatGPT to translate it into your favorite programming language.

ChatGPT translating a domain model to Java code

This can save you time, though keep in mind that the generated code won’t be exceptional. It usually produces stubs, but they’re a great starting point for implementing business logic in your entities and value objects without having to define everything from scratch.

I suspect that the canvas feature might offer an even better experience, but as I mentioned earlier, I’ll cover that in a separate video once I’ve had more time to experiment with it. 

Conclusion

To sum it all up, we’ve seen just how far AI has come, even in complex areas like Domain-Driven Design.

Will we lose our jobs? That’s hard to say. But one thing is certain—we need to adapt to a new way of working with these tools and create new ones around them. That’s why I’m sharing these tips with you.

The capabilities of the o1-preview model are already incredible, but let me clarify: o1-preview isn’t ChatGPT 5, as some might think. According to many, a new model is in development, and its size will dwarf even ChatGPT 4. This likely means even more accuracy and the ability to solve more complex problems.

I hope you enjoyed this issue video. If you like my content, share it with your colleagues, , so that everyone can learn something new!

Ciao!