# Design Rust Port and Adapter Boundaries

External services can leak infrastructure concerns into domain code. This skill helps design Rust traits and adapters that keep dependencies isolated and testable.

## Install

```bash
npx skillstore add emillindfors/port-adapter-designer
```

## Metadata

- Status: approved
- Slug: emillindfors-port-adapter-designer
- Version: 1.0.0
- Author version: 1.0.0
- Skillstore revision: r1
- Version status: valid
- Tree hash: 2fe0c375499ac567e35abf7f8078e89892928cffb7d9e9c932def19c7e38afff
- Author: EmilLindfors
- GitHub username: EmilLindfors
- License: MIT
- Repository: https://github.com/EmilLindfors/claude-marketplace/tree/main/plugins/rust-hexagonal/skills/port-adapter-designer
- Ref: a06681402992ceae98ba04d54cfd4ab004862696
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: external\_commands, network, env\_access
- Quality score: 80
- Quality tier: silver
- Public page: https://skillstore.pages.dev/skills/emillindfors-port-adapter-designer
- Manifest: https://skillstore.pages.dev/api/skills/emillindfors-port-adapter-designer/manifest

## Capabilities

- Designs Rust trait ports for repositories, payment gateways, and notification services.
- Shows adapter patterns for PostgreSQL, HTTP clients, and in-memory tests.
- Uses async\_trait, Send, and Sync patterns for async Rust services.
- Maps infrastructure errors into domain-specific error types.
- Suggests boundaries for databases, APIs, file systems, and other external systems.
- Describes testing strategies with in-memory or mock adapters.

## Use Cases

- Decouple Persistence: Move direct SQLx usage behind repository traits and keep domain logic independent from the database.
- Plan Hexagonal Architecture: Define ports and adapters before adding external APIs, queues, file stores, or payment services.
- Improve Testability: Create in-memory adapters or mocks so application services can be tested without production infrastructure.

## Prompt Templates

### Identify a Port

```
Find the external dependency in this Rust module and suggest the smallest useful port trait for it.
```

### Design an Adapter

```
Design a Rust adapter for this port. Include construction, error mapping, async behavior, and ownership choices.
```

### Add Test Doubles

```
Suggest in-memory or mock adapters for these ports and explain which behaviors each test should cover.
```

### Refactor a Boundary

```
Review this Rust service and propose a step-by-step refactor to ports and adapters without changing behavior.
```

## Limitations

- Provides patterns and examples, not a complete framework or generated project.
- Example types such as UserId, Money, and RepositoryError must be defined by the user.
- Repository-specific advice requires the assistant to read the relevant project files.
- Does not validate runtime credentials, network behavior, or database schemas.

## Best Practices

- Keep port traits focused on domain actions, not vendor APIs.
- Use domain types and domain errors at every boundary.
- Add test adapters before wiring production infrastructure.

## Anti Patterns

- Expose database rows or HTTP response types through domain traits.
- Create large gateway traits that combine unrelated external systems.
- Let adapters return raw infrastructure errors to application services.

## Security Audit

- Audited at: 2026-07-06T15:16:14.881\+00:00
- Summary: All static findings were adjudicated as false positives tied to Markdown Rust examples or normal adapter design text. No evidence found of executable commands, live network behavior by the skill, credential exfiltration, obfuscation, or prompt injection. The skill declares only Read and Grep tools.

## Stats

- Views: 138
- Downloads: 11
- Favorites: 0
- Popularity score: 0
