|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Repository Overview |
| 6 | + |
| 7 | +This is the Komapper Examples repository demonstrating various ways to use Komapper, a Kotlin SQL Mapper library. The repository contains 10 example projects showcasing different frameworks and database access patterns. |
| 8 | + |
| 9 | +- **Komapper Version**: 5.3.0 |
| 10 | +- **Kotlin Version**: 2.1.21 |
| 11 | +- **Java Target**: 17 |
| 12 | +- **Build Tool**: Gradle 8.14.2 with Kotlin DSL |
| 13 | + |
| 14 | +## Common Development Commands |
| 15 | + |
| 16 | +### Building and Testing |
| 17 | +```bash |
| 18 | +# Build all projects |
| 19 | +./gradlew build |
| 20 | + |
| 21 | +# Build specific project |
| 22 | +./gradlew :<project-name>:build |
| 23 | + |
| 24 | +# Run all tests |
| 25 | +./gradlew test |
| 26 | + |
| 27 | +# Run tests for specific project |
| 28 | +./gradlew :<project-name>:test |
| 29 | + |
| 30 | +# Run a single test class |
| 31 | +./gradlew :<project-name>:test --tests "org.komapper.example.ApplicationTest" |
| 32 | +``` |
| 33 | + |
| 34 | +### Running Applications |
| 35 | + |
| 36 | +**Spring Boot Applications:** |
| 37 | +```bash |
| 38 | +./gradlew :spring-boot-jdbc:bootRun |
| 39 | +./gradlew :spring-boot-r2dbc:bootRun |
| 40 | +./gradlew :jpetstore:bootRun # Access at http://localhost:8080/ (user: jpetstore/jpetstore) |
| 41 | +``` |
| 42 | + |
| 43 | +**Console Applications:** |
| 44 | +```bash |
| 45 | +./gradlew :console-jdbc:run |
| 46 | +./gradlew :console-r2dbc:run |
| 47 | +``` |
| 48 | + |
| 49 | +**Ktor Application:** |
| 50 | +```bash |
| 51 | +./gradlew :kweet:run # Access at http://localhost:8080/ |
| 52 | +``` |
| 53 | + |
| 54 | +**Quarkus Application:** |
| 55 | +```bash |
| 56 | +./gradlew :quarkus-jdbc:quarkusDev # Development mode with hot reload |
| 57 | +``` |
| 58 | + |
| 59 | +### Code Formatting |
| 60 | +```bash |
| 61 | +# Check formatting |
| 62 | +./gradlew spotlessCheck |
| 63 | + |
| 64 | +# Auto-format code (automatically runs before build) |
| 65 | +./gradlew spotlessApply |
| 66 | +``` |
| 67 | + |
| 68 | +## Project Structure and Architecture |
| 69 | + |
| 70 | +### Multi-Module Structure |
| 71 | +Each example is a separate Gradle subproject demonstrating specific Komapper features: |
| 72 | + |
| 73 | +- **codegen**: KSP code generation examples |
| 74 | +- **comparison-with-exposed**: Comparison with Exposed ORM |
| 75 | +- **console-jdbc/r2dbc**: Simple console applications |
| 76 | +- **spring-boot-jdbc/r2dbc**: Spring Boot integrations |
| 77 | +- **jpetstore**: Full e-commerce application (Spring Boot) |
| 78 | +- **kweet**: Twitter-like messaging app (Ktor) |
| 79 | +- **quarkus-jdbc**: Quarkus framework integration |
| 80 | +- **repository-pattern-jdbc**: Repository pattern implementation |
| 81 | + |
| 82 | +### Key Architectural Patterns |
| 83 | + |
| 84 | +1. **Entity Mapping**: All projects use Komapper's annotation-based entity mapping |
| 85 | + - Entities are in `entity` packages |
| 86 | + - Use `@KomapperEntity` annotation |
| 87 | + - Primary keys use `@KomapperId` |
| 88 | + |
| 89 | +2. **Database Configuration**: |
| 90 | + - JDBC projects use `JdbcDatabase` |
| 91 | + - R2DBC projects use `R2dbcDatabase` |
| 92 | + - Most examples use H2 in-memory database |
| 93 | + - Configuration typically in `application.yml` or `application.properties` |
| 94 | + |
| 95 | +3. **Transaction Management**: |
| 96 | + - Spring Boot: Declarative with `@Transactional` or programmatic with `TransactionOperator` |
| 97 | + - Console/Ktor: Manual transaction management with `db.withTransaction` |
| 98 | + |
| 99 | +4. **Code Generation**: Uses KSP (Kotlin Symbol Processing) to generate metamodel classes for type-safe queries |
| 100 | + |
| 101 | +### Dependencies and Versions |
| 102 | +All dependency versions are centralized in `gradle/libs.versions.toml`. Key frameworks: |
| 103 | +- Spring Boot: 3.5.3 |
| 104 | +- Quarkus: 3.24.0 |
| 105 | +- Ktor: 3.2.0 |
| 106 | +- Testing: JUnit 5, Testcontainers |
| 107 | + |
| 108 | +### Important Files |
| 109 | +- **Root build configuration**: `build.gradle.kts` |
| 110 | +- **Dependency versions**: `gradle/libs.versions.toml` |
| 111 | +- **CI/CD workflow**: `.github/workflows/build.yml` |
| 112 | +- **Auto-update config**: `renovate.json` |
0 commit comments