1 of 21

Visualising

complex content models

contentful-graph

2 of 21

About me

Hi, my name is Yaraslau Kurmyza (or simply Yarik)

Now: Head of Web @ croove (https://letscroove.com/)

Before: Lead developer @ crosslend (https://uk.crosslend.com/)

From time to time: Loliful App, Mutiful (Android), Uelco

Twitter: lotask | Github: lotas | Linkedin: yaraslaukurmyza

3 of 21

Contentful

  • DX: Complexity shifting

4 of 21

Contentful

  • DX: Complexity shifting�
  • Application architecture
    • Pages
    • Containers
    • Components / Blocks
    • Blog / Articles..

5 of 21

Component 1:1 matching

Author

Category

Image

Photo Gallery

6 of 21

Component 1:1 matching

Author

Category

Image

Photo Gallery

7 of 21

Component 1:1 matching

Author

Category

Image

Photo Gallery

const PhotoGallery = ({ children }) => <div>{children}</div>

const Image = ({ src, author, category }) => <div>

<img src={src} />

<Category name={category} />

<Author name={author} />

</div>

const Category = ({ name }) => <h3>{name}</h3>

const Author = ({ name }) => <a href={`/users/${name}`}>{name}</a>

8 of 21

Component 1:1 matching - more components

Author

Parnter

Car

BlogAuthor

JobPosition

FAQAnswer

BlogPostList

PressCarousel

PressContaine

BlogPostList

Insurance

PressArticle

Feature

TwoColumnList

Feedback

CalculateEarnings

CarCarousel

FAQContainer

BrandedHero

FeaturesList

UserJourney

9 of 21

What to do?

  • Try to understand the model
    • Click around files in project
    • Open all model definitions in contentful
    • Do some hand-drawings on the nearby walls�
  • Make it easy to understand
    • Visualise
    • Automate

10 of 21

Use Contentful API

API:

    • Content Delivery (CDA) (read content, media, type definitions)
    • Content Management (CMA) (manage content, content types)

Content type definitions:

  • Fetch all
  • Build dependency graph
  • Visualise it

11 of 21

Understanding model relations

Mode field definitions:

  • linkType: ‘Asset’
  • type: ‘Link’
    • linkContentType[]: ‘linkedModel’

"PressCarousel": {

"fields": [{

"id": "children",

"name": "Children",

"type": "Array",

"validations": [],

"items": {

"type": "Link",

"validations": [{

"linkContentType": [

"press"

]

}

],

"linkType": "Entry|Asset"

}

12 of 21

Understanding model relations

Mode field definitions:

  • linkType: ‘Asset’
  • type: ‘Link’
    • linkContentType[]: ‘linkedModel’

Type of relationship:

  • 1:1 field.validations[] (CMA)
  • 1:many field.items[]

"PressCarousel": {

"fields": [{

"id": "children",

"name": "Children",

"type": "Array",

"validations": [{

"linkMimetypeGroup": [

"image"

]

}

],

"items": {

"type": "Link",

"validations": [{

"linkContentType": [

"press"

]

13 of 21

Understanding model relations

Mode field definitions:

  • linkType: ‘Asset’
  • type: ‘Link’
    • linkContentType[]: ‘linkedModel’

Type of relationship:

  • 1:1 field.validations[]
  • 1:many field.items[]

"PressCarousel": {

"fields": [{

"id": "children",

"name": "Children",

"type": "Array",

"validations": [],

"items": {

"type": "Link",

"validations": [{

"linkContentType": [

"press"

]

}

],

"linkType": "Entry|Asset"

}

14 of 21

Visualising connections

$ npx contentful-graph

digraph obj {� node[shape=record];�� Category ;� Author ;� Post ;

Author -> Post;� Post -> Author;� Post -> Category;�}

models.dot

15 of 21

Visualising connections

digraph obj {� node[shape=record];�� Category ;� Author ;� Post ;

Author -> Post;� Post -> Author;� Post -> Category;�}

models.dot

Graphviz

dot -Tpng > model.png

16 of 21

Visualising connections

digraph obj {� node[shape=record];�� Category ;� Author ;� Post ;

Author -> Post;� Post -> Author;� Post -> Category;�}

models.dot

17 of 21

Visualising connections - real world models

18 of 21

Visualising connections

19 of 21

But wait..

There’s more

20 of 21

contentful-graph-web

21 of 21

Thank you.