AGENTS.md
AGENTS.md
1# Backend — Spring Boot23Standards: [`docs/kotlin-style.md`](docs/kotlin-style.md) · [`docs/annotations.md`](docs/annotations.md) ·4[`docs/layered-architecture.md`](docs/layered-architecture.md) · [`docs/controllers.md`](docs/controllers.md) ·5[`docs/mappers.md`](docs/mappers.md) · [`docs/exceptions.md`](docs/exceptions.md) ·6[`docs/testing.md`](docs/testing.md) · [`docs/logging.md`](docs/logging.md)78## Stack910Kotlin (JVM 25) · Spring Boot 4.x · Gradle · Spring Data JPA · JUnit 5 + Mockito + AssertJ.1112## Feature package layout1314One package per feature, split into layer subpackages:1516```17at/fhtw/swen3/paperless/<feature>/18 controller/ <Feature>Controller @RestController @RequestMapping("/<feature>")19 service/ <Feature>Service interface — the feature's public surface20 <Feature>ServiceImpl @Service, class-level @Transactional — the one impl21 entity/ <Feature>Entity JPA annotations only, no business logic22 persistence/ <Feature>Persistence domain-facing interface23 Jpa<Feature>Persistence @Repository adapter — maps models ↔ entities24 repository/ <Feature>Repository plain Spring Data interface25 mapper/ <Feature>EntityMapper pure model ↔ entity mapping26 model/ <Feature>, enums domain models (data class), no jakarta.persistence imports27 dto/ Create/Update/Response records28 mapper/ <Feature>Mapper static — DTO ↔ model29```3031`model/`, `entity/`, `service/`, and `persistence/` are sibling folders within each32feature. Entities stay separate from the persistence adapters and repositories.3334Not every feature needs every file — a read-only feature has no `Create<Feature>DTO`. Add a35layer only when it actually carries weight.3637## Gotchas3839- The service is an interface `<Feature>Service` plus one `@Service` implementation40 `<Feature>ServiceImpl` (both in `service/`). Inject and mock the interface; `@InjectMocks`41 in the service's own unit test targets `<Feature>ServiceImpl` — Mockito can't instantiate42 an interface.43- Services must never inject or call another service. Use domain-facing persistence44 interfaces for cross-feature data access and keep validation and authorization in the calling service.45- JPA repositories remain plain Spring Data interfaces inside `persistence/repository/`.46 Services inject `<Feature>Persistence` domain interfaces; adapters handle JPA and mapping.47 "Find or 404" remains a service concern:48 `repository.findById(id).orElseThrow(() -> new AppException(AppErrorMessage.<X>_NOT_FOUND))`.49- `model/` holds Kotlin domain models / data classes (no JPA imports); `entity/` holds `@Entity` classes only, no logic.50- Primary constructor injection is used in services (`class <Feature>ServiceImpl(private val persistence: <Feature>Persistence) : <Feature>Service`);51 Lombok is not used.52- Prefer `val` for immutability; use `var` only when mutable state is strictly necessary (see [`docs/kotlin-style.md`](docs/kotlin-style.md)).53- No existence checks or business logic in controllers — that belongs in the service, which54 should throw when something isn't there.55- `@Transactional` at class level, service classes only (`readOnly = true` for read paths).5657- Controllers, services, and domain models must not import JPA, persistence entities, Spring Data58 repositories, or entity mappers. Only persistence adapters may access these implementation details.59