Skip to main content
rule CX Codex

0-hexagonal — Claude Code rule: what it does, how to install

The 0-hexagonal rule splits each context into four layers and keeps dependencies pointed inward. Use it when reviewing TypeScript architecture.

MIT ★ 571 updated 2026-10-29

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/rules/0-hexagonal.md
Open on GitHub

What 0-hexagonal does

The rule targets src/contexts/**/*.ts and src/runtime/**/*.ts. It separates context code into domain/, application/, and infrastructure/: the domain contains entities, value objects, pure transformations, and capabilities; the application layer coordinates use cases; infrastructure handles port implementations and I/O.

Interfaces live in domain/ports/ or kernel/ports/, while adapters belong in infrastructure/ and receive a port through the constructor. import-rules-bite.arch.test.ts and ports-are-called.arch.test.ts check architectural boundaries, with import and global restrictions defined in biome.json. Since process is rejected in domain/ and application/, those layers must access it through a port.

What it helps with

  • split a context into four layers
  • keep dependencies pointed toward the domain
  • move I/O behind adapters
  • check import boundaries
  • match each adapter to one port

Example prompts for the agent

  • Review src/contexts/orders/**/*.ts against 0-hexagonal and list layer violations.
  • Run an architecture review on src/runtime/**/*.ts; find direct process access and port violations.
  • Check that every adapter in infrastructure/ implements one port and receives it through its constructor.

How to install 0-hexagonal

Manually: put the files in place

.claude/rules/0-hexagonal.md

The paths frontmatter field limits the files

Step by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use

Questions about 0-hexagonal

How do I install 0-hexagonal in Claude Code?

Save the rule as .claude/rules/0-hexagonal.md.

What does 0-hexagonal do?

It defines four layers inside a context, keeps dependencies directed inward, and separates ports from their adapters. It also sets architectural checks for imports and port usage.

Why is process blocked in domain/ and application/?

The restriction is configured in biome.json. Code in those layers must use a port instead of accessing the environment directly, while I/O stays in infrastructure.

Source text

0-hexagonal.md · MIT
---
description: Apply inside a context; four layers, dependencies pointing inward, one adapter per port.
paths:
  - "src/contexts/**/*.ts"
  - "src/runtime/**/*.ts"
---

# Layers Inside a Context

Which context owns a concept is `0-contexts.md`.

## Layers

- `domain/`: entities, value objects, pure transforms, capabilities. No I/O.
- Validate an invariant at construction.
- `domain/ports/`: interfaces only.
- `application/`: one class per use case, orchestration only.
- Never branch on the targeted tool; read its capability class.
- `infrastructure/`: port implementations and every piece of I/O.
- Dependencies point inward; `biome.json` holds one `noRestrictedImports` override per layer.
- `biome.json`'s `noRestrictedGlobals` refuses `process` in `domain/` and `application/`; take a port.
- `import-rules-bite.arch.test.ts` fails a pattern naming a vanished directory.

## Ports and adapters

- One context: `domain/ports/`. Two: `kernel/ports/`.
- Name an adapter `*Adapter`, in `infrastructure/`; `runtime/` for a kernel port.
- An adapter does I/O and format translation only.
- Inject through the constructor, typed as the port.
- One adapter, one port; `FileAdapter` is recorded debt.
- A port declares no uncalled method (`ports-are-called.arch.test.ts`, empty baseline).
- `CLIOutput` implements the kernel `Logger` from `presentation/output.ts`.

© ai-driven-dev · MIT · ai-driven-dev/framework

Similar IDE rules

IDE rules catalog →
hexagonal-architecture affaan-m hexagonal-architecture guides you in structuring Ports and Adapters systems across TypeScript, Java, Kotlin, and Go. Helps isolate domain logic when code gets tangled with I/O. CX Codex +1 6,600installs hexagonal-architecture-layers-java diegnghrmr The hexagonal-architecture-layers-java skill structures Java services around Domain, Application, and Infrastructure layers. Use it for new services or Spring refactoring. CX Codex +1 250installs 707-technologies-hexagonal-architecture Juan Antonio Breña Moral 707-technologies-hexagonal-architecture is a Claude Code skill that reviews and improves Hexagonal architecture boundaries in Java projects without coupling to Spring Boot, Quarkus, or Micronaut. CX Codex +1 174installs nestjs-hexagonal Softtor nestjs-hexagonal — a plugin for designing NestJS applications with Hexagonal Architecture, DDD, and CQRS patterns. Provides layer-specific skills, Opus and Sonnet agents, code checking, and TDD workflow. ★ 5repo stars context-mode Mert Koseoğlu context-mode routes heavy tool outputs and web pages into an MCP sandbox so raw data does not clutter the agent context window. CX Codex +1 ★ 34,370repo stars context-mode Mert Koseoğlu This rule routes data work through context-mode MCP tools and keeps raw files out of the conversation. Use it for analysis, search, and transformations. CX Codex +1 ★ 34,370repo stars json-structured-prompting calesthio json-structured-prompting defines a JSON architecture for complex image prompts with multiple subjects, explicit positioning, and variable templates. CX Codex +1 ★ 78,316repo stars i2i-prompting calesthio i2i-prompting — a rule for writing image-to-image editing prompts with FLUX.2. Use it for targeted changes, style transfers, text edits, and staged transformations. CX Codex +1 ★ 78,316repo stars

From the same set80

The whole set →
0-contexts 0-contexts enforces one-way imports across bounded contexts and keeps business logic out of the shared kernel in TypeScript projects. CX Codex +1 ★ 571repo stars 1-conventions The 1-conventions rule sets conventions for TypeScript files under src/ and tests/, covering module structure, file names, and test tiers. Use it when adding code or tests to a project. CX Codex +1 ★ 571repo stars 05-rule-generate 05-rule-generate takes a coding rule from draft to the rule files of installed AI hosts: create, edit, publish, delete. CX Codex +1 ★ 571repo stars 07-command-generate 07-command-generate generates flat slash commands across the AI assistants enabled in your repository. Useful when you need to scaffold or edit single-step commands without manual path wiring. CX Codex +1 ★ 571repo stars 09-mermaid 09-mermaid turns a written description of an architecture or a flow into a Mermaid diagram, with a plan you approve before anything gets drawn. CX Codex +1 ★ 571repo stars 06-test 06-test finds untested behaviors, iterates tests until they pass, and validates user flows end to end in the browser. CX Codex +1 ★ 571repo stars 03-release-tag 03-release-tag is a Claude Code skill that prepares SemVer releases from recent commits, updates version files, and creates annotated tags after you review the release details. CX Codex +1 ★ 571repo stars 08-hook-generate 08-hook-generate builds one hook: a handler fired at a lifecycle event of the host tool, with a config entry per tool and the script behind it. CX Codex +1 ★ 571repo stars

Project sponsors

Companies that keep this analytics open