# Project working rules ## Start with the relevant code - This is a Kotlin/JVM messenger: Ktor, Koin/KSP, Exposed JDBC, PostgreSQL, Redis and S3. - Before implementing, read the nearest interface, a good analogous implementation and its caller/test. Expand the search only as needed. - Use `ExposedUserRepository`, `ExposedChatRepository` and `DefaultChatService` as established style anchors; proximity alone does not make new code an example to copy. - For Kotlin persistence, transaction boundaries, DI or library DSL changes, use [messenger-kotlin-exposed](.agents/skills/messenger-kotlin-exposed/SKILL.md). ## Match the project - Keep the existing controller → service → repository separation and reuse local helpers before adding abstractions. - Follow the anchors' multiline declarations, named arguments, vertically chained calls and spacing between logical steps. Do not compress them into dense one-liners. - Prefer the library DSLs and project wrappers actually available in the pinned dependencies. Do not invent a DSL or replace a library just to avoid a builder. - Exposed is **1.0.0** with `org.jetbrains.exposed.v1.*` imports; `gradle/libs.versions.toml` is the source of truth. - Express ordinary database operations with Exposed DSL. Before introducing raw SQL, check the pinned API and existing extensions, and identify the concrete operation they cannot express. Keep a necessary fallback small and parameterized; SQL migration files remain appropriate. - Repositories use the caller's current transaction. Preserve the existing controller/service ownership of `suspendedTransaction`; do not open a separate transaction for each repository operation. - Reuse Koin `@Single`, constructor injection and existing component-scanned modules; follow the affected feature's registration pattern. - Apply a user's correction to other relevant code in the current change, not only to the reported line. Preserve the scope of the requested task. - Preserve unrelated API contracts and test expectations. Update them when the requested behavior requires it, rather than to hide an implementation failure. ## Verify the actual change - Use the Gradle wrapper and JVM 21. Inspect `build.gradle.kts` when build behavior matters. - Compile application changes with `./gradlew compileKotlin`; include `compileTestKotlin` when test sources change. - Run the relevant tests, for example `./gradlew test --tests '*ExposedChatRepositoryTest'`; database/API tests use Testcontainers and need Docker. - Use `./gradlew test` when the change warrants the broader Kotlin suite. - `make check` validates contract/repository structure offline; `make test` runs smoke checks against a running API. They serve different purposes. - Documentation/instruction-only edits need link/content checks, not an application build or full test suite. - Review the complete diff for behavior, consistency with the selected analogues, accidental SQL/builders, formatting and unrelated edits before finishing. - Report what changed and which checks actually ran, including any check blocked by the local environment.