|
1 | 1 | --- |
2 | 2 | applyTo: ** |
3 | | -description: This file describes the architecture and module structure of the support-query-builder project. |
| 3 | +description: Use when understanding support-query-builder architecture, module boundaries, consumer-facing APIs, annotation processing, Room integration, or shared Gradle/buildSrc behavior. |
4 | 4 | --- |
5 | 5 |
|
6 | | -# Support Query Builder Architecture |
| 6 | +# Support Query Builder Context |
7 | 7 |
|
8 | | -The support-query-builder project is a Kotlin library that provides a fluent SQL query builder with annotation processing capabilities for Android Room database integration. Its design goal is to generate type-safe SQL queries dynamically while maintaining compile-time verification through annotation processing. |
| 8 | +- `support-query-builder` is a reusable Kotlin library, not an app. Favor reusable abstractions, extension points, and stable consumer-facing APIs over app-specific behavior. |
| 9 | +- The library's primary purpose is to provide a fluent, type-safe SQL query builder that integrates with Android Room via generated schema objects and `SupportSQLiteQuery`. |
| 10 | +- Treat the published Dokka site as part of the product surface: `https://anitrend.github.io/support-query-builder/`. |
9 | 11 |
|
10 | | -## Module Structure |
| 12 | +## Module Groups |
11 | 13 |
|
12 | | -The project is organized into distinct Gradle modules, each with specific responsibilities: |
| 14 | +- Core JVM modules: `:annotations`, `:core`, `:processor` |
| 15 | +- Android integration module: `:core:ext` |
| 16 | +- Development-only module: `:sample` (excluded from CI via `settings.gradle.kts`) |
13 | 17 |
|
14 | | -### Core Modules |
15 | | -- **`:core`** - The main query builder library containing the core SQL query construction logic. This module provides the fluent builder API with support for complex queries including joins, unions, and chaining operations. It contains no Android-specific dependencies, making it a pure Kotlin library that can be used in any JVM environment. |
16 | | -- **`:core:ext`** - Extension functions for the core module, primarily providing integration with Android Room's `SupportSQLiteQuery`. The main function `asSupportSQLiteQuery()` converts query builder instances to Room-compatible query objects. |
| 18 | +## Dependency Direction |
17 | 19 |
|
18 | | -### Annotation Processing |
19 | | -- **`:annotations`** - Contains the annotation definitions used to mark Room entities for processing. This module is dependency-free and only defines the annotations that other modules consume. |
20 | | -- **`:processor`** - Kotlin annotation processor (KAPT) that inspects Room entity annotations (`@Entity`, `@ColumnInfo`, `@Embedded`) and generates corresponding schema object classes. These generated objects mirror the entity structure and provide type-safe column references for the query builder. |
| 20 | +- `:annotations` is a JVM-only API module with no project dependencies. It only defines the `@EntitySchema` annotation and is the lowest layer. |
| 21 | +- `:core` is a pure JVM Kotlin module with no project dependencies. It owns the entire query builder API surface: `QueryBuilder`, `AbstractQueryBuilder`, `IQueryBuilder`, `Criteria`, `From`, `Order`, `Projection`, and their DSL helpers. |
| 22 | +- `:core:ext` is an Android library that depends on `:core`. It bridges the query builder to Room's `SupportSQLiteQuery` via extension functions. |
| 23 | +- `:processor` is a JVM KAPT module that depends on `:annotations`. It reads Room entity annotations and generates schema object classes using KotlinPoet and `auto-service`. |
| 24 | +- `:sample` depends on everything and is an Android application used for local development only. |
| 25 | +- Avoid introducing new dependencies that cause lower modules to depend on higher-layer ones. |
21 | 26 |
|
22 | | -### Development and Testing |
23 | | -- **`:sample`** - Example application demonstrating library usage. This module is excluded from CI builds but serves as a practical reference for integration patterns and usage examples. |
| 27 | +## Package Expectations |
24 | 28 |
|
25 | | -## Architecture Principles |
| 29 | +- `:annotations` exposes `co.anitrend.support.query.builder.annotation` — the `@EntitySchema` annotation. |
| 30 | +- `:core` exposes `contract/`, `criteria/`, `from/`, `order/`, `projection/`, and the top-level `QueryBuilder` and `dsl/` entrypoints. |
| 31 | +- `:core:ext` exposes `co.anitrend.support.query.builder.core.ext` — the `asSupportSQLiteQuery()` extension and related Room helpers. |
| 32 | +- `:processor` exposes `extensions/`, `factory/`, `logger/`, and `model/` under `co.anitrend.support.query.builder.processor`. The `EntitySchemaProcessor` is the KAPT entry point. |
26 | 33 |
|
27 | | -### Type Safety |
28 | | -The library emphasizes compile-time type safety through: |
29 | | -- Generated schema objects that mirror Room entity definitions |
30 | | -- Fluent builder API that prevents malformed SQL construction |
31 | | -- Extension functions that seamlessly integrate with Room's type system |
| 34 | +## Build And Tooling Facts |
32 | 35 |
|
33 | | -### Room Integration |
34 | | -The library is designed specifically for Room database integration: |
35 | | -- Annotation processor reads Room entity annotations directly |
36 | | -- Generated queries are compatible with Room's `@RawQuery` annotation |
37 | | -- Support for Room's `SupportSQLiteQuery` interface through extension functions |
| 36 | +- All modules apply the shared `co.anitrend.support.query.builder.plugin` Gradle plugin from `buildSrc`. |
| 37 | +- Shared Android defaults live in `buildSrc/.../ProjectConfiguration.kt`: `compileSdk = 35`, `minSdk = 23`, `targetSdk = 35`, Java 21 source/target compatibility, and `JvmTarget.JVM_21` for Kotlin. |
| 38 | +- The repo Java pin is `.java-version = 21.0.8`. Systems are expected to have `jenv` installed; `.java-version` is picked up by `jenv local` to set the active JDK automatically. `buildSrc/.../ProjectConfiguration.kt` must stay aligned: `JavaVersion.VERSION_21` for Java source/target compatibility and `JvmTarget.JVM_21` for Kotlin must both match the `.java-version` major version (21). |
| 39 | +- Kotlin library group (JVM-only, no Android plugin): `:annotations`, `:core`, `:processor`. All other non-sample modules are Android libraries. |
| 40 | +- Dependency versions belong in `gradle/libs.versions.toml` before they are referenced from module build files. |
| 41 | +- Spotless and ktlint are enforced centrally via `buildSrc/.../ProjectSpotless.kt`, with the license header sourced from `spotless/copyright.kt`. |
| 42 | +- Publishing is configured centrally in `buildSrc/.../ProjectMaven.kt`; artifacts are distributed through JitPack under group `co.anitrend.query.builder`. |
38 | 43 |
|
39 | | -### Modularity |
40 | | -The multi-module approach ensures: |
41 | | -- Core logic is separate from Android-specific integrations |
42 | | -- Annotation processing is isolated for clean build dependencies |
43 | | -- Extensions can be optionally included based on project needs |
| 44 | +## Documentation Contract |
44 | 45 |
|
45 | | -## Build System |
| 46 | +- Dokka is configured centrally and the published site documents the public API surface. |
| 47 | +- When changing public behavior, update KDoc in the same change. |
| 48 | +- Document what the API does, when to use it, and what a consumer must provide or expect. |
46 | 49 |
|
47 | | -The project uses Gradle with Kotlin DSL and includes: |
48 | | -- Custom build plugins in `buildSrc` for consistent configuration |
49 | | -- Android library configuration for Room compatibility |
50 | | -- Annotation processor configuration for code generation |
51 | | -- JitPack integration for distribution |
| 50 | +## Working Heuristics |
52 | 51 |
|
53 | | -## Key Components |
54 | | - |
55 | | -### Query Builder Core |
56 | | -The core module provides a fluent API for constructing SQL SELECT queries with support for: |
57 | | -- Table selection and aliasing |
58 | | -- Column projection with type safety |
59 | | -- JOIN operations (INNER, LEFT, RIGHT, FULL) |
60 | | -- WHERE clause construction with parameter binding |
61 | | -- GROUP BY and HAVING clauses |
62 | | -- ORDER BY with multiple columns |
63 | | -- UNION and UNION ALL operations |
64 | | -- Subquery support |
65 | | - |
66 | | -### Schema Generation |
67 | | -The annotation processor generates Kotlin object classes that: |
68 | | -- Mirror Room entity class structure |
69 | | -- Provide compile-time column name verification |
70 | | -- Support nested objects for `@Embedded` annotations |
71 | | -- Generate table metadata for query construction |
72 | | - |
73 | | -### Room Extensions |
74 | | -Extension functions bridge the query builder with Room: |
75 | | -- Convert builder instances to `SupportSQLiteQuery` |
76 | | -- Handle parameter binding for dynamic queries |
77 | | -- Maintain compatibility with Room's query execution model |
78 | | - |
79 | | -## Documentation |
80 | | - |
81 | | -Full documentation is available at: https://anitrend.github.io/support-query-builder/ |
82 | | - |
83 | | -The documentation includes: |
84 | | -- API reference for all public classes and methods |
85 | | -- Integration guides for Room database usage |
86 | | -- Examples of complex query construction |
87 | | -- Best practices for annotation processor usage |
88 | | - |
89 | | -This modular architecture ensures the library remains focused on its core purpose while providing flexible integration options for different use cases and maintaining compatibility with the Android ecosystem. |
| 52 | +- Put new query builder logic in `:core` if it has no Android dependency; put Room-specific glue in `:core:ext`. |
| 53 | +- Annotation additions go in `:annotations` first; corresponding processor changes go in `:processor` in the same change. |
| 54 | +- Prefer shared build logic changes in `buildSrc` over copy-pasting Gradle configuration into individual modules. |
| 55 | +- When running Gradle locally, use the `jenv-gradle-low-ram` skill to align the JDK and manage memory pressure before invoking `./gradlew`. |
| 56 | +- When unsure where code belongs, consult the dependency direction above and confirm it before editing. |
0 commit comments