51 lines
6.0 KiB
Markdown
51 lines
6.0 KiB
Markdown
# 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](../../../../gradle/libs.versions.toml): Kotlin **2.3.20**, Exposed **1.0.0** (`core`, `jdbc`, `kotlin-datetime`, migration modules). Preserve `org.jetbrains.exposed.v1.*` imports and follow the affected model's types.
|
|
- [Settings](../../../../settings.gradle.kts): 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](../../../../build.gradle.kts): 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](../../../../src/main/kotlin/com/mtusi/messenger/main/infrastructure/repositories/user/ExposedUserRepository.kt): multiline function parameters, `insertIgnore`, `selectAll().where(...)` split into vertical chains, nullable results and `ResultRow` mapping.
|
|
- [ExposedSessionRepository](../../../../src/main/kotlin/com/mtusi/messenger/main/infrastructure/repositories/authentication/session/ExposedSessionRepository.kt): `insert`, `deleteWhere`, typed time predicates and result mapping.
|
|
- [ExposedChatRepository](../../../../src/main/kotlin/com/mtusi/messenger/main/infrastructure/repositories/chat/ExposedChatRepository.kt): related writes via `insert`/`batchInsert`, joins, keyset pagination and grouped member loading. Keep result ordering and transaction atomicity intact.
|
|
- [ExposedMessageIdempotencyRepository](../../../../src/main/kotlin/com/mtusi/messenger/main/infrastructure/repositories/message/idempotency/ExposedMessageIdempotencyRepository.kt): conflict handling, `update`, `deleteWhere` and reusable typed conditions.
|
|
- [RowGreater](../../../../src/main/kotlin/com/mtusi/messenger/main/utils/exposed/operations/RowGreater.kt) and [InstantPlusSeconds](../../../../src/main/kotlin/com/mtusi/messenger/main/utils/exposed/operations/InstantPlusSeconds.kt): existing typed expression extensions. Inspect the relevant operation before implementing another SQL escape hatch.
|
|
- [ChatModel](../../../../src/main/kotlin/com/mtusi/messenger/main/infrastructure/models/chat/ChatModel.kt): 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](../../../../src/main/kotlin/com/mtusi/messenger/main/plugins/Database.kt) defines `suspendedTransaction` using `newSuspendedTransaction` on `Dispatchers.IO`. The database configuration sets `defaultMaxAttempts = 1`; do not silently introduce retries around side effects.
|
|
- [ChatController](../../../../src/main/kotlin/com/mtusi/messenger/main/infrastructure/controllers/chat/ChatController.kt) and [UserController](../../../../src/main/kotlin/com/mtusi/messenger/main/infrastructure/controllers/user/UserController.kt) open transactions around their service calls. [DefaultChatService](../../../../src/main/kotlin/com/mtusi/messenger/main/infrastructure/services/chat/DefaultChatService.kt) 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](../../../../src/test/kotlin/com/mtusi/messenger/main/infrastructure/repositories/chat/ExposedChatRepositoryTest.kt) demonstrates caller-owned transactions and rollback when a related write fails.
|
|
- Flyway migrations live in `src/main/resources/migrations`. Database.kt's `generateMigration` connects 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](../../../../src/main/kotlin/com/mtusi/messenger/main/infrastructure/repositories/RepositoriesModule.kt) and [ServicesModule](../../../../src/main/kotlin/com/mtusi/messenger/main/infrastructure/services/ServicesModule.kt) use `@Module`/`@ComponentScan`.
|
|
- [Koin.kt](../../../../src/main/kotlin/com/mtusi/messenger/main/plugins/Koin.kt) installs the generated modules; concrete implementations use `@Single` and 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:
|
|
|
|
```sh
|
|
./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](../../../../src/test/kotlin/com/mtusi/messenger/main/support/TestApp.kt) and [TestDatabase](../../../../src/test/kotlin/com/mtusi/messenger/main/support/TestDatabase.kt) show that API/database tests use Testcontainers and require Docker; those API helpers also start Redis and S3 test dependencies.
|
|
|
|
[Makefile](../../../../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.
|