# TypeDB crash course: Conceptual modeling

_Implement a conceptual model of a real supply chain directly in TypeDB_

## [](#_who_this_course_is_for)Who this course is for

This course is for people who already think in conceptual models: entity-relationship (ER and EER) diagrams, Object-Role Modeling (ORM), UML class diagrams, or ontology-driven approaches such as OntoUML. It assumes no knowledge of TypeDB.

Usually, a conceptual model has to be mapped to tables or a property graph before it can be used, and some of its meaning is lost:

*   n-ary relationships are decomposed or turned into join tables,
    
*   roles survive only as column or edge names,
    
*   generalizations are flattened into nullable columns or extra tables,
    
*   participation and cardinality constraints end up in application code, triggers, or nowhere.
    

TypeDB’s schema language, TypeQL, has entity, relation and attribute types as first-class constructs, with n-ary relations, named roles, generalization, and cardinality, key and value constraints. The conceptual schema you write is the database schema, and the database enforces its constraints. A few constructs need workarounds, which [Chapter Nine](09-limits-and-patterns/index.md) covers.

⭐ TypeDB in one paragraph

TypeDB is a database whose schema is a conceptual model. Entity, relation and attribute types are declared directly, relations keep their roles and can be n-ary, and types are organized into generalization hierarchies. Every query is type-checked against the model before it runs, so a query whose types can’t fit the schema is an error, not an empty result. Every write is checked against the model’s constraints by the time a transaction commits.

## [](#_what_you_will_build)What you will build

You will model a real dataset: palm oil trade flows from East Kalimantan, Indonesia, to the European Union in 2022, taken from Trase’s open supply-chain data. Each flow links a district of production, a mill, sometimes a refinery, an exporter, an importer, a destination country and a commodity, and carries a volume, a value and a deforestation exposure.

You will:

1.  Map the constructs of the ER family onto TypeQL, and see where the mapping is exact, approximate, or missing.
    
2.  Read elementary facts off the raw data, and build the model a few columns at a time.
    
3.  Make and justify modeling decisions: entity or attribute, subtype or role, one relation or several.
    
4.  Implement a seven-role relation with an optional role and attributes of its own.
    
5.  Populate the model, and watch the database reject data and queries that contradict it.
    
6.  Query at the conceptual level: by type, by role, polymorphically, and with derivation rules.
    
7.  Query the model itself, and attach definitions to it.
    
8.  Work around what TypeDB cannot express, with reusable patterns.
    

## [](#_assumptions)Assumptions

Three TypeDB properties to understand before we start:

*   **Closed world.** The database contains the facts it has been told. A query for something that was not inserted returns no answers; nothing is inferred to exist.
    
*   **Schema first.** Every instance belongs to a type declared in the schema, and every attribute, role and relation it participates in must be allowed by that schema.
    
*   **One most-specific type per instance.** Each instance is created as one type and stays that type. It is also an instance of all that type’s supertypes, but it cannot belong to two unrelated types or change type later. [Chapter Nine](09-limits-and-patterns/index.md) covers the consequences for multiple and dynamic classification.
    

## [](#_how_to_use_this_course)How to use this course

How the chapters work

Each modeling chapter follows the same loop: a requirement read off the data, the constraints stated in plain sentences, an ER diagram in Chen notation, and the TypeQL that implements it. Try writing the TypeQL yourself before reading it. Run each code block in TypeDB Studio in the order shown, unless it says otherwise. If you skip ahead, each chapter starts by saying what to run first.

The course takes about an hour. It is a companion to [TypeDB Academy](../../academy/index.md), which teaches TypeQL more systematically, and to the [schema modeling guide](../../guides/schema-modeling/index.md).

## [](#_chapters)Chapters

[Chapter Zero: Setup](00-setup/index.md)

Run TypeDB and connect TypeDB Studio.

[Chapter One: From ER to TypeQL](01-from-er-to-typeql/index.md)

The mapping from ER, ORM, UML and UFO constructs to TypeQL.

[Chapter Two: About the dataset](02-about-the-dataset/index.md)

The dataset, and the elementary facts in one row.

[Chapter Three: Entity types and generalization](03-entity-types-and-generalization/index.md)

Places: identification, abstract supertypes, and a first relation.

[Chapter Four: Modeling decisions](04-modeling-decisions/index.md)

Companies, facilities and commodities: choosing between alternatives.

[Chapter Five: The n-ary relation](05-n-ary-relations/index.md)

The trade flow: one relation, seven roles.

[Chapter Six: Population and conformance](06-population-and-conformance/index.md)

Load the data, and break the constraints on purpose.

[Chapter Seven: Querying at the conceptual level](07-querying/index.md)

Queries by type and role, aggregates, and derivation rules.

[Chapter Eight: The model as data](08-the-model-as-data/index.md)

Query the schema, document it, and evolve it.

[Chapter Nine: Limits and patterns](09-limits-and-patterns/index.md)

What TypeDB cannot express, and how to model around it.

[Epilogue](10-epilogue/index.md)

Where to go next, and references.

[Epilogue: You Are the Architect](../rbac-in-business/10-epilogue/index.md) [Chapter Zero: Setup](00-setup/index.md)

[Edit on GitHub](https://github.com/typedb/typedb-docs/edit/3.x-development/learn-typedb/modules/ROOT/pages/conceptual-modeling/index.adoc) Edit this page on GitHub.