6.0 KiB
Project patterns
Read the section relevant to the change. Source links point to the repository's current files, not frozen examples.
Dependencies and build
- Version catalog: Kotlin 2.3.20, Exposed 1.0.0 (
core,jdbc,kotlin-datetime, migration modules). Preserveorg.jetbrains.exposed.v1.*imports and follow the affected model's types. - Settings: Ktor catalog 3.3.0, AWS SDK for Kotlin catalog 1.6.41. Do not substitute MinIO Java builders for the installed Kotlin SDK.
- Build: JVM 21, Koin annotations/KSP with configuration checking, JUnit Platform. There is no configured ktlint/detekt task to assume or claim ran.
The catalogs/build files remain the source of truth if versions or plugins change. Check API details against those versions when the local examples do not establish an operation.
CRUD, layout and query expressions
- ExposedUserRepository: multiline function parameters,
insertIgnore,selectAll().where(...)split into vertical chains, nullable results andResultRowmapping. - ExposedSessionRepository:
insert,deleteWhere, typed time predicates and result mapping. - ExposedChatRepository: related writes via
insert/batchInsert, joins, keyset pagination and grouped member loading. Keep result ordering and transaction atomicity intact. - ExposedMessageIdempotencyRepository: conflict handling,
update,deleteWhereand reusable typed conditions. - RowGreater and InstantPlusSeconds: existing typed expression extensions. Inspect the relevant operation before implementing another SQL escape hatch.
- ChatModel: the model/table namespace used by queries. Read the affected feature's own model before changing its columns or mapping.
These are focused references, not a requirement to open every listed file on every task. Prefer User/Chat for established layout; newer attachment/storage code is not automatically the style authority.
Transaction ownership
- Database.kt defines
suspendedTransactionusingnewSuspendedTransactiononDispatchers.IO. The database configuration setsdefaultMaxAttempts = 1; do not silently introduce retries around side effects. - ChatController and UserController open transactions around their service calls. DefaultChatService and ordinary Exposed repositories assume that active transaction.
- Authentication and attachment orchestration also own transactions in services. Inspect the actual caller of the method you change; do not impose a controller-only rule or create nested/per-operation boundaries.
- ExposedChatRepositoryTest demonstrates caller-owned transactions and rollback when a related write fails.
- Flyway migrations live in
src/main/resources/migrations. Database.kt'sgenerateMigrationconnects to the development database and applies existing migrations before generating SQL; it is not a harmless formatting/check command.
DI and library API choice
- RepositoriesModule and ServicesModule use
@Module/@ComponentScan. - Koin.kt installs the generated modules; concrete implementations use
@Singleand constructor dependencies. Reuse this flow instead of adding a parallel registry. - Ktor routing, Koin modules, Exposed queries and the installed AWS Kotlin SDK expose Kotlin DSLs. Check the affected dependency's real API: Java integrations such as Hikari/Lettuce already use builders/configuration objects, so a blanket builder ban would conflict with the project.
Focused verification
From the repository root, choose the checks that exercise the change:
./gradlew compileKotlin
./gradlew compileTestKotlin
./gradlew test --tests '*ExposedChatRepositoryTest'
Replace the test selector with the affected class; use ./gradlew test when broader coverage is warranted. TestApp and TestDatabase show that API/database tests use Testcontainers and require Docker; those API helpers also start Redis and S3 test dependencies.
Makefile provides make check for offline structure/contract checks and make test for smoke checks against a running API (BASE_URL defaults to http://localhost:8080). Use the existing Gradle wrapper; do not invent lint tasks or count an unavailable/skipped check as passing. Instruction-only changes do not need an application build or test suite.