Polski

Tutorial

Author guide: writing in Art of Devs

A showcase article: every editor block – gallery, chart, diagram, timeline, quiz, tabbed code and embeds – told through a pierogi place in a hexagon.

By · · 8 min read

Author guide: writing in Art of Devs

Art of Devs should show architecture, not just talk about it. This guide doubles as a showcase article: using Halina's pierogi place and hexagonal architecture it walks through every editor block – from galleries and charts to a quiz.

8
accent colours – set the theme in the Studio "Appearance" tab
5
languages in one code group – C#, TypeScript, Java, Go, Python
30%
of the text is visible to guests – the rest after signing in

The problem: spaghetti code

An orders controller that writes to the database, sends text messages and calculates discounts works fine – until the first change. Every new integration means digging through business logic.

  • logic welded to the database and the SMS gateway,
  • tests need real infrastructure,
  • one change means risk in several places at once.
Spaghetti code: OrdersController welded with noodles to SQL Server, an SMS gateway, a webhook and a business rule
Spaghetti code: everything connected to everything

Add a chart (the chart block) from the "/" menu and type the data into the block panel:

Cost of changing the SMS provider: spaghetti vs hexagon – Illustrative example – made-up story point values, not a measurement from a real project.
SpaghettiHexagon
1. new provider8 SP3 SP
2. backup provider13 SP2 SP
3. new message format13 SP2 SP
4. test fake21 SP1 SP

Ports and adapters

A laptop with a USB-C socket as the ICustomerNotifier port and three plugs as adapters: SMS, console and a test fake
A port is the socket, an adapter is the plug

The core of the application – the "kitchen" – defines ports: interfaces that describe what it needs, such as IOrderBook or ICustomerNotifier. The outside world connects through adapters: an HTTP controller, an EF Core repository, a Kafka producer or a fake in a test.

Dependencies always point inward. A right-aligned image lets the text flow around it and stacks above the paragraph on phones. Diagrams (the diagram block) are written in drawings Mermaid syntax:

Diagram: The path of a request through the hexagon

Code in five languages

Insert the same example in several languages as a tabbed group. The reader picks a language once and the choice applies to every group on the page. File names end up in the "Download code" ZIP.

Strategy – shipping cost

Shipping.cs
public interface IShippingStrategy
{
    decimal Cost(decimal weightKg);
}

public sealed class Courier : IShippingStrategy
{
    public decimal Cost(decimal weightKg) => 15m + 2m * weightKg;
}

public sealed class Parcel : IShippingStrategy
{
    public decimal Cost(decimal weightKg) => 9.99m;
}

public sealed class Checkout(IShippingStrategy shipping)
{
    public decimal Total(decimal items, decimal kg) => items + shipping.Cost(kg);
}
shipping.ts
interface ShippingStrategy {
  cost(weightKg: number): number;
}

const courier: ShippingStrategy = { cost: (kg) => 15 + 2 * kg };
const parcel: ShippingStrategy = { cost: () => 9.99 };

class Checkout {
  constructor(private readonly shipping: ShippingStrategy) {}

  total(items: number, kg: number): number {
    return items + this.shipping.cost(kg);
  }
}

console.log(new Checkout(courier).total(120, 3)); // 141
console.log(new Checkout(parcel).total(120, 3)); // 129.99
Checkout.java
interface ShippingStrategy {
    double cost(double weightKg);
}

record Courier() implements ShippingStrategy {
    public double cost(double kg) { return 15 + 2 * kg; }
}

record Parcel() implements ShippingStrategy {
    public double cost(double kg) { return 9.99; }
}

public class Checkout {
    private final ShippingStrategy shipping;
    public Checkout(ShippingStrategy shipping) { this.shipping = shipping; }
    public double total(double items, double kg) { return items + shipping.cost(kg); }
}
shipping.go
package checkout

type ShippingStrategy interface {
	Cost(weightKg float64) float64
}

type Courier struct{}

func (Courier) Cost(kg float64) float64 { return 15 + 2*kg }

type Parcel struct{}

func (Parcel) Cost(float64) float64 { return 9.99 }

type Checkout struct{ Shipping ShippingStrategy }

func (c Checkout) Total(items, kg float64) float64 {
	return items + c.Shipping.Cost(kg)
}
shipping.py
from typing import Protocol


class ShippingStrategy(Protocol):
    def cost(self, weight_kg: float) -> float: ...


class Courier:
    def cost(self, weight_kg: float) -> float:
        return 15 + 2 * weight_kg


class Parcel:
    def cost(self, weight_kg: float) -> float:
        return 9.99


def total(items: float, kg: float, shipping: ShippingStrategy) -> float:
    return items + shipping.cost(kg)

The rest of this article is for members

Create a free account or sign in to read it all. Still ahead:

  • Gallery: Halina's pierogi place
  • Where it came from
  • See it in motion
  • When it pays off and when it does not
  • Check yourself
  • Block cheat sheet
  • Around the topic
  • What next

Create a free account · Sign in

Tags: author-guide, editor, tiptap