Skip to main content
This website uses Cookies to provide necessary site functionality and improve your experience.
By using our website, you agree to our Privacy Policy and our Cookies Policy
OK

CATEGORY:BlogPressSolutionsTech
READ TIME 3 minutes

Introduction   

In this article, I want to demonstrate how easily and quickly you can create an entity relationship model in your chosen development language using tools like ChatGPT and Mermaid. For this example, I’ll also create a very simple C# example, but the same principles can be applied to most software development languages, such as C++ or Python. 

This article isn’t focused on best practices for Domain-Driven Design or Entity Relationships. Instead, it aims to showcase how quickly you can get something up and running using modern tools and all output from the tooling remains unedited.  Also, I don’t have any affiliations with any of the products mentioned. 

Before we begin, let’s briefly discuss the tooling. Unless you’ve been living under a rock for the past couple of years, you’re likely familiar with ChatGPT. For the visual element, I’ll use Mermaid.   So, what is Mermaid? 

Asking ChatGPT ..  

Mermaid is a JavaScript-based diagramming and charting tool that uses a simple, human-readable syntax to generate diagrams dynamically. It is often used to create and visualize complex diagrams directly within markdown or code repositories without the need for graphic design tools.” 

It’s an excellent tool that you can try for free at https://mermaid.js.org/. It also includes an AI element, which I haven’t explored yet. For this example, I’ll use ChatGPT instead, as it offers versatility in creating not only Mermaid diagrams but also code based on the context of my requests. 

ER?

I’m not going to dive into the details of an Entity-Relationship (ER) Model, as there’s plenty of information available online. In summary, an ER Model is a conceptual framework used to describe and represent the relationships between interrelated objects or concepts within a specific domain of knowledge. 

A basic ER Model consists of entity types (the “things” of interest) and defines the relationships that can exist between individual instances of those “things.” Each “thing” typically has attributes

Relationships can take various forms, including one-to-one, one-to-many, many-to-one, and many-to-many

Example

A very simple example would be a library, where a Member (with attributes like Name and MembershipId) borrows a Book (which has attributes like Title, Author, and ISBN). Each Book is authored by an Author, who has attributes such as Name and Bio. An Author can author many books. 

This forms a relationship between the entities where the Member can borrow the Book which has been authored by an Author. 

In software engineering, an ER model is often used to represent the key things a business needs to track to carry out its operations.  The ER model becomes an abstract data model that defines the data structure that can be implemented in a persistence store, for example a database. 

Time to create stuff 

Using ChatGPT and the example above I’m going to create an ER Diagram which is a type of flowchart that illustrates how “entities” relate to each other. 

Open ChatGPT and type in “Create a Mermaid ER Diagram based on a library, where a Member (with attributes like Name and MembershipId) borrows a Book (which has attributes like Title, Author, and ISBN). Each Book is authored by an Author, who has attributes such as Name and Bio. An Author can author many books.” 

The result from ChatGPT is: 

Now using Mermaid copy and paste in the ER Diagram

Which then creates a pretty cool diagram outlining the relationship between the different entities. 

In my opinion, one of the great advantages of using a text-driven diagram tool like Mermaid is that the “script” can be easily stored and versioned in a source code repository, such as GitHub or Azure DevOps. Additionally, the diagrams images can then be included in README.md files.  I guess you could even create a DevOps pipeline task to actually create all of this for you on the fly. 

Now that the entities and relationships have been defined, it’s time to take it a step further. Using “our good friend” (as we call it at arrt HQ), ChatGPT, we’ll generate code classes to represent the domain entities, using C# as an example. 

In ChatGPT you can simply use a request like: 

“Using C# and a domain driven design create classes to represent the entities and the relationships. Also give an example of how they could be used.”   

The result can be seen below. 

As well as an example of how to use the entities.

If you’d like to quickly experiment with the code, I’ve created a simple Visual Studio project, which can be found in our ARRT GitHub repository here.

Final thoughts?

As you can see, in a very short amount of time, we’ve created a working example of our Library domain, providing some quick wins when you need to build a functional demo rapidly.
In a future article, we’ll explore how to persist and even test our domain – all without writing a single line of code!

As a closing comment, I’d just say don’t rely solely on tools like ChatGPT. While it often provides good guidance, it can occasionally provide incorrect information – but at least it apologises when it’s caught out!

.. and finally no I didn’t get ChatGPT to write this article .. but it did give me a helping “virtual” hand. 😊

Whether you’re a seasoned tech professional, an aspiring innovator, or simply curious about the digital frontier, Tech Tuesday is here to keep you informed and inspired.

Let us know in the comments what topics you’d love to see us cover next!

Stephen Gray
Head of Product Development

1

request a free consultation with us.

and find out how we can harness the power of integration to improve your business.
request a consultation

follow us

subscribe for updates