About This Project

A full Gang of Four catalog for Go, focused on idiomatic implementations instead of framework-specific class hierarchies.

Idiomatic Go

Patterns are adapted to Go using plain constructors, small interfaces, and explicit package boundaries.

Real Source

All examples are backed by real Go files imported at build time, not pseudo-code.

Interactive Walkthroughs

All 22 patterns include an animated diagram powered by Mermaid.js, with a narrator panel that explains each component's role step by step.

Local-First Progress

Reading progress is persisted locally in IndexedDB via Dexie.js. Your data stays on your device — no account, no server sync, no tracking.

Two Locales

The content is available in English and Khmer while preserving the same information architecture.

What is this?

This site applies classic Gang of Four (GoF) design patterns to Go in a way that fits the language. Go still benefits from creational, structural, and behavioral patterns, but the shape of those patterns changes when you favor composition, interfaces, plain constructors, explicit errors, and package-level boundaries over inheritance-heavy object models.

The examples use practical commerce and platform scenarios so the patterns stay concrete. Each published article is backed by actual Go source files, and the write-up calls out the Go-specific tradeoffs that matter in real codebases.

How the patterns are organized

The patterns are still organized into the classic three categories:

  • Creational — Construction-focused patterns such as Singleton and Factory Method, adapted to Go with constructor functions, interfaces, and functional options.
  • Structural — Composition-focused patterns such as Adapter, Facade, Decorator, and Proxy, usually expressed through small interfaces and package boundaries.
  • Behavioral — Workflow and collaboration patterns such as Chain of Responsibility, Command, Strategy, and State, typically implemented with interfaces and explicit control flow.

What each pattern page includes

  • The Problem — A concrete scenario where the pattern is needed.
  • The Solution — How the pattern translates into Go.
  • Interactive Architecture — A step-by-step Mermaid.js diagram that highlights active nodes while the narrator panel explains each component's role. Includes source view, copy, and fullscreen mode.
  • Structure — The moving parts and how they collaborate.
  • Implementation — Full Go source code with syntax highlighting.
  • Real World Analogy — A simple real-life comparison to make each pattern easier to understand.
  • Pros and Cons — Explains the advantages, disadvantages, and tradeoffs of each pattern.
  • Best Practices — Guidance on Go idioms, tradeoffs, and testability.
  • When to Use / When NOT to Use — Practical guidance on applicability.
  • Related Patterns — Cross-references to complementary or alternative patterns.

Technology

This site is built with a small, focused stack that stays fast and keeps all user data off the server.

  • Astro — Static site generator that renders HTML at build time. JavaScript is only shipped when a component needs interactivity. MDX allows real Go source files to be imported directly into content pages.
  • Tailwind CSS v4 — Utility-first CSS using CSS custom properties to drive a consistent dark/light theme across every component.
  • Mermaid.js v11 — Renders flowchart diagrams client-side as SVG. Every pattern page includes a step-by-step diagram where nodes highlight and a narrator panel explains each component's role. Diagrams automatically re-render on dark/light mode toggle to pick up fresh CSS variable values. Each diagram also supports a source view to inspect the raw Mermaid syntax, a copy button, and fullscreen mode.
  • Dexie.js v4 — A clean IndexedDB wrapper used instead of localStorage to track reading progress per pattern. Stored data includes the slug, first-read timestamp, last-visited timestamp, and visit count — all kept on your browser only, with no server involved. An automatic migration step upgrades any existing localStorage data so returning users keep their progress.