Skip to main content

Quickly visualize your Ent schemas with entviz

· 3 min read

TL;DR​

To get a public link to a visualization of your Ent schema, run:

go run -mod=mod ariga.io/entviz ./path/to/ent/schema 

Visualizing Ent schemas​

Ent enables developers to build complex application data models using graph semantics: instead of defining tables, columns, association tables and foreign keys, Ent models are simply defined in terms of Nodes and Edges:

package schema

import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
)

// User schema.
type User struct {
ent.Schema
}

// Fields of the user.
func (User) Fields() []ent.Field {
return []ent.Field{
// ...
}
}

// Edges of the user.
func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("pets", Pet.Type),
}
}

Modeling data this way has many benefits such as being able to easily traverse an application's data graph in an intuitive API, automatically generating GraphQL servers and more.

While Ent can use a Graph database as its storage layer, most Ent users use common relational databases such as MySQL, PostgreSQL or MariaDB for their applications. In these use-cases, developers often ponder, what actual database schema will Ent create from my application's schema?

Whether you're a new Ent user learning the basics of creating Ent schemas or an expert dealing with optimizing the resulting database schema for performance reasons, being able to easily visualize your Ent schema's backing database schema can be very useful.

Introducing the new entviz​

A year and a half ago we shared an Ent extension named entviz, that extension enabled users to generate simple, local HTML documents containing entity-relationship diagrams describing an application's Ent schema.

Today, we're happy to share a super cool tool by the same name created by Pedro Henrique (crossworth) which is a completely fresh take on the same problem. With (the new) entviz you run a simple Go command:

go run -mod=mod ariga.io/entviz ./path/to/ent/schema 

The tool will analyze your Ent schema and create a visualization on the Atlas Playground and create a shareable, public link for you:

Here is a public link to your schema visualization:
https://gh.atlasgo.cloud/explore/saved/60129542154

In this link you will be able to see your schema visually as an ERD or textually as either a SQL or Atlas HCL document.

Wrapping up​

In this blog post we discussed some scenarios where you might find it useful to quickly get a visualization of your Ent application's schema, we then showed how creating such visualizations can be achieved using entviz. If you like the idea, we'd be super happy if you tried it today and gave us feedback!

For more Ent news and updates: