×
Back to book

What is an entity diagram?

A non-technical description of the wonderful entity diagram; if you can read a map, you can build an entity diagram for your app!

Entity diagrams are the software maps of the world.

When you first set out to build software it can be a daunting task, but thankfully there is a special tool called the entity diagram editor to help you map and organise how the data that you collect will be stored.
Whether you like to pronounce it day-taa or daa-taa, data are individual units of information like a type of car, a measurement of distance, an event or any number of things. Data can be stored in a filing cabinet, a spreadsheet, a vehicles odometer, or even in the pile of papers on your desk!

In business, databases are commonly used to keep track of customer information and underpin most software systems. At first glance a database can look similar to a spreadsheet – but on steroids. A database can store much more data than spreadsheets, it typically stores data values in tables rather than cells, and can create relationships between records in different tables.

But how do you design a database for your software application?

This is where the Entity Diagram comes into play.

Think of an entity diagram as a software map that represents the logic and structure of the database that underpins your application.

A map is not meant to be literal, it is a set of symbols and words to understand a landscape and looks nothing like the actual geography. Your diagram is also a simplified, high level map of the complex data it represents.
The magic of maps is that once you understand some simple rules and symbols, you can read almost any map in the world. Entity diagrams are like software maps. Let's unlock the code for understanding and creating them.

6 keys for unlocking entity diagrams

1. Entities – unique landmarks of your map

An entity is something with a unique existence, it could be an object, a person or something abstract like a travel log. Let's use the example of a Climate Action Car Calculator app that calculates carbon emissions for each journey. The main entities would be a customer, a car and a travel log. Once you create an entity, you then have options for how you configure them.

2. Relationships – how things connect

This is where databases get powerful, as you can set the relationship between different entities in your diagram. Relationships can be:

  • one to one;
  • one to many; or,
  • many to many.

In our Climate Action Car Calculator example, a person can have many cars, but a car can only have one owner so the relationship between a customer and a car is one to many. A car can have one travel log and a travel log can only have one car so the relationship from car to travel log is one to one.

3. Attributes - information for a map to make sense

Within each entity we can add attributes that help us categorise and capture data for that entity. There are lots of different kinds of attributes, like integers, decimals and strings. To calculate the carbon emissions of our entity, the car, we need to know the fuel type and the car size – these would be string attributes, which means a sequence of words. For the customer entity, we need to collect the string attributes of first name, last name, email and address, plus the integer attribute of postcode.

4. Validators - the traffic cop enforcing the rules

Validators are placed on attributes to ensure that the data entered conforms to a specific rule set. For example, an attribute with the integer 'datatype' can be a positive or negative number by default. However, a person's postcode can only be positive. In this situation, you would use a validator to constrain the integer attribute to positive numbers.

5. Enumeration – symbols or colours of a map

Enumeration or 'enums' are a type of attribute that contains a predefined set of options that are unlikely to change. For example, an enum might be used to define car size. Enum literals or literals are the individual options that the enum can be, so for the enum of car size the enum literals are compact, medium-size, SUV or Minivan. These can appear as a drop down list of options that a customer can select from.

6. Behaviours – pre-set journeys you can apply to a map

We saved the best until last! Behaviours can be dragged onto any entity within the entity diagram. This small step can save a techie from writing hundreds of lines of mind-numbing code by giving your diagram common functionality with just a few clicks. For our Climate Action Car Calculator, it's likely that we would need the common functionality of user administration, so the User behaviour can be dragged onto an Admin entity. This ensures that each user within the system, can log onto the system, be added to groups and have security restrictions applied to them.

Now that you have the six keys to entity diagrams I recommend that you have a go at creating one of your own. Check out this academy lesson (insert link) to put it all into practice.

But wait, what makes the Entity Diagram in Codebots so powerful?

Well imagine for a moment that the relationship between two entities needs to change. It may sound like a simple task, but using traditional methods, the resulting work to update this relationship could take a techie a couple of days. Codebots eliminates this effort, as the bots can update the code to reflect this change in seconds, not days.

By letting the bots do the heavy-lifting on labour intensive tasks like this, it gives your team the opportunity and time to focus on the things they love to do, like nutting out the creative and complex parts of the application.

If you love to nerd out on this stuff, I can highly recommend the book Data & Reality by William Kent in the 1970s and updated by Steve Hoberman. Another good read is Database Design by Adrienne Watt and Nelson Eng, a free e-book under Creative Commons license with practical examples.