1- # CLAUDE .md - MongoDB Java Driver
1+ # AGENTS .md - MongoDB Java Driver
22
33Guidelines for AI agents working on the MongoDB Java Driver codebase.
44
55## Project Overview
66
77This is the official MongoDB JVM driver monorepo, providing Java, Kotlin, and Scala
88drivers for MongoDB. The driver implements the
9- [ MongoDB Driver Specifications] ( https://github.com/mongodb/specifications )
10- and follows semantic versioning.
9+ [ MongoDB Driver Specifications] ( https://github.com/mongodb/specifications ) and follows
10+ semantic versioning.
1111
1212### Module Structure
1313
14- | Module | Purpose |
15- | ---------------------------- | ----------------------------------------------------------- |
16- | ` bson ` | BSON library (core serialization) |
17- | ` bson-kotlin ` | Kotlin BSON extensions |
18- | ` bson-kotlinx ` | Kotlin serialization BSON codec |
19- | ` bson-record-codec ` | Java record codec support |
20- | ` bson-scala ` | Scala BSON extensions |
21- | ` driver-core ` | Core driver internals (connections, protocol, operations) |
22- | ` driver-sync ` | Synchronous Java driver |
23- | ` driver-legacy ` | Legacy MongoDB Java driver API |
24- | ` driver-reactive-streams ` | Reactive Streams driver |
25- | ` driver-kotlin-coroutine ` | Kotlin Coroutines driver |
26- | ` driver-kotlin-extensions ` | Kotlin driver extensions |
27- | ` driver-kotlin-sync ` | Kotlin synchronous driver |
28- | ` driver-scala ` | Scala driver |
29- | ` mongodb-crypt ` | Client-side field-level encryption |
30- | ` testing ` | Shared test resources and MongoDB specifications |
14+ | Module | Purpose |
15+ | --- | --- |
16+ | ` bson ` | BSON library (core serialization) |
17+ | ` bson-kotlin ` | Kotlin BSON extensions |
18+ | ` bson-kotlinx ` | Kotlin serialization BSON codec |
19+ | ` bson-record-codec ` | Java record codec support |
20+ | ` bson-scala ` | Scala BSON extensions |
21+ | ` driver-core ` | Core driver internals (connections, protocol, operations) |
22+ | ` driver-sync ` | Synchronous Java driver |
23+ | ` driver-legacy ` | Legacy MongoDB Java driver API |
24+ | ` driver-reactive-streams ` | Reactive Streams driver |
25+ | ` driver-kotlin-coroutine ` | Kotlin Coroutines driver |
26+ | ` driver-kotlin-extensions ` | Kotlin driver extensions |
27+ | ` driver-kotlin-sync ` | Kotlin synchronous driver |
28+ | ` driver-scala ` | Scala driver |
29+ | ` mongodb-crypt ` | Client-side field-level encryption |
30+ | ` testing ` | Shared test resources and MongoDB specifications |
3131
3232### Internal API Convention
3333
34- All code in ` com.mongodb.internal.* ` and ` org.bson.internal.* ` is private API.
35- It can change at any time without notice. Never expose internal types in
36- public APIs, and never advise users to depend on them.
34+ All code in ` com.mongodb.internal.* ` and ` org.bson.internal.* ` is private API. It can
35+ change at any time without notice.
36+ Never expose internal types in public APIs, and never advise users to depend on them.
3737
3838### API Stability Annotations
3939
40- - ` @Alpha ` - Early development, may be removed. Not for production use.
41- - ` @Beta ` - Subject to change or removal. Libraries should not depend on these.
42- - ` @Evolving ` - May add abstract methods in future releases. Safe to use, but implementing/extending bears upgrade risk.
43- - ` @Sealed ` - Must not be extended or implemented by consumers. Safe to use, but not to subclass.
40+ - ` @Alpha ` - Early development, may be removed.
41+ Not for production use.
42+ - ` @Beta ` - Subject to change or removal.
43+ Libraries should not depend on these.
44+ - ` @Evolving ` - May add abstract methods in future releases.
45+ Safe to use, but implementing/extending bears upgrade risk.
46+ - ` @Sealed ` - Must not be extended or implemented by consumers.
47+ Safe to use, but not to subclass.
4448- ` @Deprecated ` - Supported until next major release but should be migrated away from.
4549
4650## General
@@ -60,7 +64,7 @@ public APIs, and never advise users to depend on them.
6064### Essential Build Commands
6165
6266``` bash
63- # Full validation (static checks + unit tests + integration tests)
67+ # Full validation (spotlessApply + static checks + unit tests + integration tests)
6468./gradlew check
6569
6670# Integration tests (requires running MongoDB)
@@ -69,22 +73,16 @@ public APIs, and never advise users to depend on them.
6973# Single module tests
7074./gradlew :driver-core:test
7175
72- # Format check only
73- ./gradlew spotlessCheck
74-
75- # Auto-fix formatting
76- ./gradlew spotlessApply
77-
7876# Test with alternative JDK
7977./gradlew test -PjavaVersion=11
8078```
8179
8280## Code Style and Formatting
8381
8482Formatting is enforced automatically because the Gradle ` check ` task depends on
85- ` ./gradlew spotlessApply ` , which formats sources. To run a check without modifying
86- files, invoke ` ./gradlew spotlessCheck ` manually. Do not manually reformat files
87- outside the scope of your changes.
83+ ` ./gradlew spotlessApply ` , which formats sources.
84+ To run a check without modifying files, invoke ` ./gradlew spotlessCheck ` manually.
85+ Do not manually reformat files outside the scope of your changes.
8886
8987### Style Rules
9088
@@ -96,7 +94,8 @@ outside the scope of your changes.
9694- ** Final parameters:** Required (FinalParameters checkstyle rule)
9795- ** Braces:** Required for all control structures (NeedBraces)
9896- ** Else placement:** On its own line (not cuddled)
99- - ** Copyright header:** Every Java / Kotlin / Scala file must contain ` Copyright 2008-present MongoDB, Inc. `
97+ - ** Copyright header:** Every Java / Kotlin / Scala file must contain
98+ ` Copyright 2008-present MongoDB, Inc. `
10099
101100### Prohibited Patterns
102101
@@ -114,28 +113,35 @@ outside the scope of your changes.
114113
115114### Writing Tests
116115
117- - ** Every code change must include tests.** New code needs new tests; modified code needs updated tests. Do not reduce test coverage.
116+ - ** Every code change must include tests.** New code needs new tests; modified code
117+ needs updated tests. Do not reduce test coverage.
118118- Extend existing test patterns in the module you are modifying
119119- Unit tests should not require a running MongoDB instance
120- - Test methods should be descriptive:
121- prefer ` shouldReturnEmptyListWhenNoDocumentsMatch() ` over ` test1() ` ,
122- use ` @DisplayName ` for a human readable name
120+ - Test methods should be descriptive: prefer
121+ ` shouldReturnEmptyListWhenNoDocumentsMatch() ` over ` test1() ` , use ` @DisplayName ` for a
122+ human readable name
123123- Clean up test data in ` @AfterEach ` / ` cleanup() ` to prevent test pollution
124124
125125### MongoDB Specifications and Specification Tests
126126
127- The driver implements the [ MongoDB Specifications] ( https://github.com/mongodb/specifications ) . Specification test data files live in
128- ` testing/resources/specifications/ ` — a git submodule for test resources. When modifying driver specification-related behavior: do
129- not modify existing specification tests unless they test incorrect behavior. Create new tests instead.
127+ The driver implements the
128+ [ MongoDB Specifications] ( https://github.com/mongodb/specifications ) .
129+ Specification test data files live in ` testing/resources/specifications/ ` — a git
130+ submodule for test resources.
131+ When modifying driver specification-related behavior: do not modify existing
132+ specification tests unless they test incorrect behavior.
133+ Create new tests instead.
130134
131135## Core Development Principles
132136
133137### Essential Rules
134138
135- - ** Read before modifying.** Understand existing code and patterns before making changes.
139+ - ** Read before modifying.** Understand existing code and patterns before making
140+ changes.
136141- ** Minimal changes only.** No drive-by refactoring.
137142- ** Preserve existing comments.** Only remove comments that are provably incorrect.
138- - ** No unrelated changes.** Do not fix formatting or refactor code outside the scope of the task.
143+ - ** No unrelated changes.** Do not fix formatting or refactor code outside the scope of
144+ the task.
139145- ** No rewrites** without explicit permission.
140146
141147### Search Before Implementing
@@ -148,20 +154,19 @@ Before writing new code, search the codebase for existing implementations:
148154
149155### API Design
150156
151- - ** Deep modules:** Prefer simple interfaces with powerful implementations over shallow wrappers.
157+ - ** Deep modules:** Prefer simple interfaces with powerful implementations over shallow
158+ wrappers.
152159- ** Information hiding:** Bury complexity behind simple interfaces.
153160- ** Pull complexity downward:** Make the implementer work harder so callers work less.
154- - ** General-purpose over special-case:** Fewer flexible methods over many specialized ones.
155- - ** Define errors out of existence:** Design APIs so errors cannot happen rather than detecting and handling them.
161+ - ** General-purpose over special-case:** Fewer flexible methods over many specialized
162+ ones.
163+ - ** Define errors out of existence:** Design APIs so errors cannot happen rather than
164+ detecting and handling them.
156165
157166## Dependency Management
158167
159168Dependencies are managed centrally via ` gradle/libs.versions.toml ` .
160-
161- - ** Never add dependencies without justification.** Dependencies are liabilities.
162- - ** Use dependencies for:** Security/crypto, complex protocols, battle-tested algorithms.
163- - ** Write it yourself for:** fewer than 100 LOC of straightforward code, project-specific logic, performance-critical paths.
164- - Optional dependencies (Netty, Snappy, Zstd, AWS SDK, SLF4J) use ` optionalImplementation ` and must not be required at runtime.
169+ Optional dependencies (Netty, Snappy, Zstd, AWS SDK, SLF4J) use ` optionalImplementation ` and must not be required at runtime.
165170
166171## Safety Rules - Do Not Modify Without Review
167172
@@ -177,7 +182,8 @@ Dependencies are managed centrally via `gradle/libs.versions.toml`.
177182
178183### Evergreen (MongoDB Internal CI)
179184
180- Primary CI runs on MongoDB's Evergreen system. Configuration is in ` .evergreen/ ` .
185+ Primary CI runs on MongoDB’s Evergreen system.
186+ Configuration is in ` .evergreen/ ` .
181187
182188### Before Submitting
183189
0 commit comments