# 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)
