Back to book

Entity Diagram Basics

This article will go over the basic terminologies and teaches how to interact with the diagram editor


An entity is an object that exists and is distinguishable from other objects. An entity may be concrete (a person or a book, for example) or abstract (like a holiday or a concept). In software development, entities are used to plan the database structure and gain insight into the system's architecture. To keep it simple, think of entities as a table in the database.

In Codebots, the Entity Diagram captures the layout and relationships between the different entities. You can create an entity by clicking the New Entity button.

Once you have created an entity you will be prompted with some properties that you can then configure. The properties in the Build section are constantly improving and being updated. To learn more about the latest properties available, please see the tooltips alongside them (the question mark icon next to the title).


Relationships describes the connection between the two entities. There are three kinds of relationships:

  • one to one
  • one to many, and
  • many to many.

You can set a relationship between two entities using the Entity Diagram. Start by hovering over the edge of entity until you see a green border appear. From here, simply click and drag a line to the edge of the entity you wish to create the relationship for. Once you release the mouse click you will be prompted to chose one of the three types of relationships. Now that the relationship is formed you can use the properties panel to further customise the relationship.

Relationships Dependencies

The properties panel includes the switches Target Optional and Source Optional. These properties allow you to toggle relationship dependencies between two entities.

What is a relationship dependency?

A relationship dependency describes whether an entity is dependent on or independent of an associated entity.

Let's explore three different scenarios that use relationship dependencies.

Scenario 1: Target Optional

Let's assume we have a diagram where a "Person" can own many "Cars", denoted in the diagram below.

In our fictional scenario we have a rule that any car must have an owner. This would mean that a Car has a dependent relationship with a Person. In other words, a Person may or may not own a Car but a Car must be owned a Person.

If we say the source is a Person and the Car is the target, the relationship would be target optional and would resemble the image below.

Scenario 2: Source Optional

This time, the rule is that a Car is not required to be owned by a Person but everyone must own a Car. This would mean that a Car has an independent relationship with a Person. In other words, a Person must own a Car but a Car may be owned a Person.

This relationship would be source optional as the Person is still the source, and would resemble the image below.

Scenario 3: Source and Target Optional

In the final scenario, Cars are not required to be owned by a Person and a Person is not required to own a Car. This means that a Person and a Car have an independent relationship to each other. A Person may or may not own a Car and a Car may or may not belong to a Person. The relationship dependency in this situation would be both target optional and source optional and would be represented by the image below.


Attributes belong to an entity, and describe characteristics. For example, an employee entity might have the attributes 'name', 'height' and 'DOB'. So, if entities are tables in a database, attributes are the columns within the table. In software development, an attribute is characterised by its datatype. For example, age can only be a number (or integer) and DOB can only be a date.

Codebots contains the most popular attributes: Boolean, date, datetime, decimal, enum, integer and string.

Using the Entity Diagram, you can add an attribute to an entity by first selecting the entity, then clicking on New Attribute and selecting one of the datatypes. After adding the attribute, you can use the properties to define its values.


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

Consider validators as the validation messages that appear when submitting a form.

To add a validator to attribute just simply select the attribute, click 'validators' and choose the appropriate validation.


Enumeration or enums are a type of attribute that contains a predefined set of options that are unlikely to change. Enum Literals or literals are the individual options that the enum can be. For example, an enum might be used to define the days of the week, with the enum literals being Monday, Tuesday, Wednesday and so on.

To create an enum in the Entity Diagram, click 'New Enum' and edit the properties. To start adding in your literals, select New Literal and add the values in the properties.

Now we have created the enum, we need to create a relationship between it and the entity. Select your entity, then click New Attribute and choose the enum datatype. Hover on the edge of the enum attribute inside the entity until the blue border appears, then click and drag a line to the edge of the enum you created earlier. This will successfully add the enum to the project.


Behaviours are the cool things that a codebot can do. You can learn more about behaviours and read about the six common behaviours identified by us. What is a behaviour?