refactor_to_hexagonal

refactor_to_hexagonal is a skill for Claude Code, Codex from EmilLindfors/a2a-rs. It costs 67 tokens per session (1,507 once invoked), scanned A, original, MIT.

A step-by-step guide for gradually reorganizing a Rust codebase into ports-and-adapters architecture. This design separates core business rules from outside systems such as databases, web servers, or HTTP clients.

In plain words
What is it for?
Use it when moving a Rust service toward separate domain, port, and adapter layers, especially when tests require external services or infrastructure is hard to replace.
Why use it?
It helps untangle business logic from infrastructure and makes the core easier to test or connect to different outside systems. The migration is split into small, reviewable changes.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: installed under .agents/ (shared by several agents).

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/emillindfors/a2a-rs/refactor_to_hexagonal
Any agent
npx skills add EmilLindfors/a2a-rs --skill refactor_to_hexagonal
Clone the repo
git clone --depth 1 https://github.com/EmilLindfors/a2a-rs

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for refactor_to_hexagonal

README.md
[![agentmods](https://agentmods.dev/badge/skills/emillindfors/a2a-rs/refactor_to_hexagonal.svg)](https://agentmods.dev/skills/emillindfors/a2a-rs/refactor_to_hexagonal)
Your own site
<a href="https://agentmods.dev/skills/emillindfors/a2a-rs/refactor_to_hexagonal"><img src="https://agentmods.dev/badge/skills/emillindfors/a2a-rs/refactor_to_hexagonal.svg" alt="Measured on agentmods" height="20"></a>
Per session 67 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,507 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00067 $0.01507
Opus 5 $0.00034 $0.00754
Sonnet 5 $0.00013 $0.00301
Haiku 4.5 $0.00007 $0.00151

Measured 6d ago against content hash 4730556c6f68, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

refactor_to_hexagonal scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.agents/plugins/rust-patterns/skills/refactor_to_hexagonal/SKILL.md · 102 lines

How it starts

The opening of the file, as written. The whole thing — 102 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Refactor to Hexagonal (Rust)

Drive an incremental migration from a flat or layered-by-framework Rust codebase to one organized by ports and adapters. The goal is small, reviewable PRs — never a big-bang rewrite.

Read rules/hexagonal_architecture.md first; this skill operationalizes those rules into a migration sequence.

When to recommend this refactor

Recommend hex when you see at least two of:

  • Business logic interleaved with HTTP handlers or DB queries.
  • A test suite that needs a running database or HTTP mock to exercise core logic.
  • Difficulty swapping infrastructure (e.g. "we want to try Postgres alongside SQLite" or "we want a CLI version of this service").
  • Errors from sqlx, reqwest, axum, etc. propagating up through what should be business code.

Do not recommend it for:

  • Small CLIs or scripts where there is no real "domain."
  • Pure libraries that already have no I/O.
  • Codebases where the dominant problem is something else (perf, concurrency, type safety) — fix that first.

Migration sequence

Drive the refactor in this order. Each step should be a separate, mergeable change.

Step 1 — Carve out a domain/ module

  • Find the data types the business cares about (entities, value objects, status enums) and move them into domain/.
  • Strip framework attributes from these types (#[derive(sqlx::FromRow)], #[serde(rename_all)] for HTTP, axum extractors). If serialization is needed in every adapter, keep serde derives; if it's only the HTTP adapter, define a DTO there and map.
  • Introduce newtypes for primitive-typed identifiers and bounded values (struct TaskId(String), struct Port(u16)). Parse at construction.
  • Define a single DomainError enum with thiserror. Initially it can have a catch-all variant; tighten over time.

Done when: cargo check -p <crate> --no-default-features compiles the domain module in isolation, with no third-party I/O crates pulled in.

Step 2 — Extract one port

Pick the smallest, highest-pain capability first. Storage is usually a good first target.

Read the full file on GitHub · 102 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 102 lines · 67 tokens per session scan A 4730556c6f68

Subscribe to this mod's changes

refactor_to_hexagonal is a skill published in the GitHub repository EmilLindfors/a2a-rs (87 stars, last pushed yesterday), licensed MIT. It adds 67 tokens to every session and 1,507 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

azure-eventhub-rust

Azure Event Hubs library for Rust. Send and receive events for streaming data ingestion and batch processing. Triggers: "event hubs rust", "ProducerClient rust", "ConsumerClient rust", "send event rust", "streaming rust", "eventhub rust".

microsoft/skills · 58 tokens

rust-engineer

Writes, reviews, and debugs idiomatic Rust code with memory safety and zero-cost abstractions. Implements ownership patterns, manages lifetimes, designs trait hierarchies, builds async applications with tokio, and structures error handling with Result/Option. Use when building Rust applications, solving ownership or…

Jeffallan/claude-skills · 120 tokens

azure-eventhub-rust

Client library for Azure Event Hubs — big data streaming platform and event ingestion service.

benjaminasterA/antigravity-awesome-skills · 0 tokens

cloudflare-workers-multi-lang

Multi-language Workers development with Rust, Python, and WebAssembly. Use when building Workers in languages other than JavaScript/TypeScript, or when integrating WASM modules for performance-critical code.

secondsky/claude-skills · 45 tokens

actix-web

Actix Web is a powerful, high-performance web framework for Rust. It provides async handlers, type-safe extractors, middleware, and integrates with the Rust ecosystem for building fast, reliable, and memory-safe web services.

TerminalSkills/skills · 51 tokens

axum

You are an expert in Axum, the web framework built on top of Tokio and Tower by the Tokio team. You help developers build high-performance, type-safe APIs and web services using Axum's extractor-based handler system, middleware via Tower layers, WebSocket support, and compile-time route validation — achieving C-level…

TerminalSkills/skills · 74 tokens