rdev/ai-lookup/patterns/hexagonal.md
jordan 39df51defd feat: Add multi-provider code agent interface with Claude Code and OpenCode adapters
Implements weeks 1-4 of the multi-provider architecture:

Week 1 - Foundation:
- Add domain models (AgentProvider, AgentRequest, AgentEvent, AgentResult)
- Define CodeAgent port interface with Execute, Cancel, Capabilities
- Create thread-safe provider registry with first-registered default

Week 2 - Claude Code Adapter:
- Extract kubectl exec logic into CodeAgent implementation
- Parse stream-json output format (init, message, tool_use, result)
- Support session continuation via --resume flag

Week 3 - OpenCode Adapter:
- HTTP/SSE client for opencode serve API
- Session management (create, send message, abort)
- Event streaming with documented buffer rationale

Week 4 - Quality & Polish:
- Fix race condition in OpenCode Cancel method
- Add AgentRequest.Validate() with ErrPromptRequired, ErrInvalidTimeout
- Document DefaultAvailabilityTimeout constants
- Add HTTP error context for debugging

Also includes:
- Work queue system with PostgreSQL adapter
- Credential store for infrastructure secrets
- Project templates with Woodpecker CI integration
- Comprehensive test coverage

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 09:25:51 -07:00

45 lines
1.4 KiB
Markdown

# Hexagonal Architecture
**Last Updated:** 2025-01
**Confidence:** High
## Summary
rdev uses hexagonal architecture (ports and adapters) to separate business logic from infrastructure. Domain models have zero external dependencies, services use port interfaces, and adapters implement those interfaces.
**Key Facts:**
- Domain models in `internal/domain/` have NO imports from other packages
- Port interfaces defined in `internal/port/`
- Adapters in `internal/adapter/{name}/` implement port interfaces
- Services in `internal/service/` orchestrate business logic
**File Pointers:**
- Port definitions: `internal/port/project.go`, `internal/port/webhook.go`
- Domain models: `internal/domain/project.go`, `internal/domain/command.go`
- Service layer: `internal/service/project.go`
## Layer Responsibilities
| Layer | Location | Purpose |
|-------|----------|---------|
| Handlers | `internal/handlers/` | HTTP request/response |
| Services | `internal/service/` | Business logic |
| Ports | `internal/port/` | Interface contracts |
| Domain | `internal/domain/` | Pure business models |
| Adapters | `internal/adapter/` | Infrastructure implementation |
## Dependency Direction
```
Handlers → Services → Ports ← Adapters
Domain
```
Dependencies point inward toward domain.
## Related Topics
- [Project Service](../services/project-service.md)
- [Command Execution](../features/command-execution.md)