Files
back/AGENTS.md
2026-10-05 14:40:04 +03:00

37 lines
3.1 KiB
Markdown

# AGENTS.md
Backend service of the gorodar project (group `ru.gorodar`, version `0.0.1-SNAPSHOT`).
Implements the API described in `docs/system-analysis.md` (public catalog / user visits / admin, in Russian).
## Stack
- Java 25 (Gradle toolchain; auto-downloaded if not installed locally)
- Spring Boot 4.1.1, Gradle 9.6.0 wrapper
- Spring Web MVC, Data JPA, Liquibase, OAuth2 resource server security, Validation, Actuator
- PostgreSQL (runtime driver), AWS SDK v2 S3 (MinIO-compatible, via `gorodar.s3.*` config)
- springdoc-openapi (Swagger UI), Lombok
## Commands
```bash
./gradlew build # full build incl. tests
./gradlew test # tests only (JUnit 5 via useJUnitPlatform)
./gradlew bootRun # run the application
```
On Windows, `gradlew.bat` is equivalent (it is git-ignored but present locally).
## Conventions and gotchas
- **Spring Boot 4 starter names**: `spring-boot-starter-webmvc`, `spring-boot-starter-security-oauth2-resource-server`, and matching `*-test` starters. Do not "fix" them to Boot 3 names (`spring-boot-starter-web`, `spring-boot-starter-oauth2-resource-server`) — those do not exist in Boot 4. Auth is self-issued (email-code flow in `ru.gorodar.auth`, OIDC-shaped endpoints); the service validates its own JWTs (RS256, local JWKS) as a resource server; there is no Keycloak and no oauth2-client.
- **Lombok**: declared as `compileOnly` + `annotationProcessor` (plus test variants). Keep this pattern when adding modules; plain `implementation` breaks annotation processing.
- **MapStruct** (entity↔DTO mappers in `ru.gorodar.mapper`, `componentModel = "spring"`, `unmappedTargetPolicy = ERROR`): `mapstruct` is an `implementation` dep, `mapstruct-processor` and `lombok-mapstruct-binding` are `annotationProcessor` entries — keep all three together, order matters for Lombok interop.
- **Criteria queries use the generated JPA metamodel**: `hibernate-jpamodelgen` runs as an annotation processor and generates `X_` classes next to entities; Specifications (`ru.gorodar.dao.spec`) must reference attributes via `Entity_.field`, never string paths like `root.get("name")`.
- **Liquibase**: schema changes go through Liquibase changelogs under `src/main/resources` (default `db/changelog`), not ad-hoc DDL.
- **Timestamps are UTC everywhere**: DB columns are plain `timestamp` (no `timestamptz`), entities use `LocalDateTime`, the JVM default timezone is forced to UTC in `main()` — keep it that way when touching date/time code.
- **Query/multipart params are kebab-case** (`parent-id`, `area-id`, `sort-order`); JSON body fields stay camelCase.
- **Entities declare explicit column names**: every field carries `@Column(name = "…")` (or `@JoinColumn(name = "…")`) — no reliance on the implicit naming strategy.
- **No `settings.gradle`**: single-project build; the project name falls back to the directory name (`back`). Add one only if the build becomes multi-module.
- **Line endings** (`.gitattributes`): `gradlew` is forced to LF, `*.bat` to CRLF, `*.jar` is binary. Preserve this when adding scripts.
- `.idea/` and `gradlew.bat` are git-ignored; do not commit them.