---
description: EEIK Architecture Rules — hexagonal architecture and DDD
globs: ["**/*.java", "**/*.ts"]
alwaysApply: true
---
<!-- Generated by EEIK generate_adapters.py on 2026-08-10 — do not edit by hand -->

## Hexagonal Architecture

Package structure (Java):
```
domain/         — Entities, value objects, domain events, ports (interfaces)
application/    — Use cases, command/query handlers
infrastructure/ — JPA repos, messaging, external clients
web/            — REST controllers, DTOs
```

Dependencies flow INWARD only:
- infrastructure → application → domain
- web → application
- domain has ZERO dependencies on other layers

## DDD Rules

- Aggregates enforce invariants — no direct field access from outside
- Domain events for cross-context communication — never direct DB joins across contexts
- Value objects are immutable
- Repositories return domain objects, not JPA entities

## Knowledge Base

- Patterns: `knowledge/patterns/`
- Anti-patterns: `knowledge/anti-patterns/`
- Reference architectures: `knowledge/reference-architectures/`
