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.
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.
Add a chart (the chart block) from the "/" menu and type the data into the block panel:
| Spaghetti | Hexagon | |
|---|---|---|
| 1. new provider | 8 SP | 3 SP |
| 2. backup provider | 13 SP | 2 SP |
| 3. new message format | 13 SP | 2 SP |
| 4. test fake | 21 SP | 1 SP |
Ports and adapters
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:
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
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);
}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.99interface 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); }
}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)
}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