skills/se-architecture/arch-clean/SKILL.md
Clean/hexagonal architecture: ports/adapters, dependency inversion, use cases, entities, testability
npx skillsauth add alphaonedev/openclaw-graph arch-cleanInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill implements Clean Architecture principles in codebases, focusing on hexagonal patterns with ports/adapters, dependency inversion, use cases, entities, and testability. It refactors or generates code to enforce separation of concerns, making systems modular and easier to test.
Use this skill when refactoring monolithic apps to improve maintainability, starting new projects requiring high testability, or integrating external dependencies without tight coupling. Apply it in scenarios with complex business logic, such as e-commerce backends, or when adapting legacy code to modern architectures like microservices.
interface UserPort { fetchUser(id: string): User; }).Invoke this skill via OpenClaw's CLI for quick refactoring or through API for automated pipelines. Start by analyzing the codebase with a scan command, then apply transformations. For scripts, pipe outputs to build tools like Make or Gradle. Always specify the target directory and language (e.g., TypeScript or Java) to avoid defaults. Use in CI/CD for pre-commit hooks to enforce architecture.
Use the OpenClaw CLI with subcommands prefixed by arch-clean. Authentication requires setting $OPENCLAW_API_KEY as an environment variable.
Generate a port interface:
openclaw arch-clean generate-port --name UserPort --methods "fetchUser(id: string)" --lang ts
This creates a file like UserPort.ts with the interface.
Invert dependencies in a module:
openclaw arch-clean invert-dep --path src/services --adapter DatabaseAdapter
Scans the specified path and wraps dependencies, e.g., replacing direct imports with adapter calls.
Create a use case:
openclaw arch-clean create-usecase --name FetchUser --ports UserPort --entities User
Generates a class like FetchUserUseCase.ts with injected ports.
API endpoints for programmatic use:
$OPENCLAW_API_KEY in headers.Config formats: Use JSON files for custom rules, e.g., .openclaw-arch.json with { "layers": { "domain": ["entities", "usecases"], "adapters": ["http", "db"] } }.
Integrate by adding OpenClaw as a dependency in your project (e.g., npm install openclaw or via Docker image). Set $OPENCLAW_API_KEY for authenticated requests. For IDE plugins, configure via settings like { "arch-clean": { "defaultLang": "ts", "excludePaths": ["tests/**"] } }. Combine with linters like ESLint by piping output, e.g., openclaw arch-clean scan | eslint --fix. Ensure your codebase uses a supported structure, such as folders for "domain", "application", and "infrastructure", to match hexagonal patterns.
Check command outputs for errors; CLI returns non-zero exit codes with JSON error messages, e.g., { "error": "Dependency not inverted: invalid path" }. For API, expect HTTP 4xx/5xx responses with bodies like { "code": 400, "message": "Missing required field: methods" }. Handle by wrapping calls in try-catch blocks, e.g.:
try {
const response = await fetch('/api/arch-clean/generate', { headers: { 'X-API-Key': process.env.OPENCLAW_API_KEY } });
if (!response.ok) throw new Error(response.statusText);
} catch (error) {
console.error('Arch error:', error.message);
}
Retry transient errors (e.g., network issues) up to 3 times with exponential backoff.
Refactor a simple service to use ports: For a Node.js app, run openclaw arch-clean invert-dep --path src/userService.js --adapter HttpAdapter. This transforms a direct HTTP call into a port, e.g., changing axios.get('/user') to this.userPort.fetchUser(id), improving testability by allowing mocks.
Generate a use case for business logic: In a Java project, execute openclaw arch-clean create-usecase --name OrderProcessor --ports PaymentPort --entities Order. This produces OrderProcessor.java with a method like public void process(Order order) { this.paymentPort.charge(order); }, enabling dependency injection for better architecture.
tools
Root web development: project structure, tooling selection, deployment decisions
development
WebAssembly: Rust/Go/C to WASM, wasm-bindgen, Emscripten, WASM Component Model
development
Vue 3: Composition API script setup, Pinia, Vue Router 4, SFCs, Vite, Nuxt 3
tools
Tailwind CSS 4: utility classes, config, JIT, arbitrary values, darkMode, plugins, shadcn/ui