Skip to content
31 changes: 31 additions & 0 deletions .agents/skills/api-design/SKILL.md
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you run Claude to review this PR, asking something like "Confirm that this PR follows best practices for creating CLAUDE.md files. Evaluate it personally, confirming that various items are generally necessary. Also evaluate it based on official and authoritative sources (official Claude documentation, online posts that are corroborated AND experimentally verified, and posts from recognized experts; but not: blog posts, social media speculations, and other uncorroborated sources. Is anything unnecessary, and easily discoverable? Is anything crucial missing?"

Independently, have it doublecheck correctness until it stops finding issues.

Please also include info about how these files were generated, and AI-reviewed, including results of the above. (This is just the typical AI usage, effectiveness comment in the description).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: api-design
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran only this skill through Claude, and I got this:

What's already known to models:
  - The design principles section is essentially a summary of Ousterhout's A
  Philosophy of Software Design. Any capable model already knows these
  concepts and would apply them naturally. This section adds little value.
  - "Search before implementing" is generic good practice, not
  project-specific guidance.

  What's genuinely useful (project-specific):
  - The stability annotations (@Alpha, @Beta, @Evolving, @Sealed) — these are
   driver-specific and not inferable without reading the source.
  - The com.mongodb.internal.* / org.bson.internal.* rule.
  - The concrete pattern examples (Filters.eq(),
  MongoClientSettings.builder()).
  - The package-info.java requirement.

  What's missing that would actually help:
  - How to choose which annotation for new API — when should something be
  @Alpha vs @Beta vs @Evolving? What's the promotion path?
  - Sync/async API mirroring — does every sync method need an async
  counterpart? How are they kept in sync?
  - Nullability conventions — does the driver use @Nullable/@NonNull? What's
  the stance on null parameters?
  - The module structure — what goes in driver-core vs driver-sync vs
  driver-reactive-streams? Where should new API land?
  - Default methods on interfaces — the strategy for evolving @Evolving
  interfaces without breaking implementors.
  - Concrete examples of "wrong" API decisions — models learn more from
  "don't do X because Y happened" than from abstract principles.

  Bottom line: The skill is ~30% useful as-is. The design principles section
  could be dropped entirely without loss. The project-specific rules are
  valuable but thin. The biggest improvement would be replacing the generic
  principles with concrete, driver-specific guidance on the missing items
  above — things a model can't infer from first principles.

I am uncertain that what is marked "useful" above will be in practice (see other comments).

description: API stability annotations, design principles, and patterns for the MongoDB Java Driver. Use when adding or modifying public API surface — new classes, methods, interfaces, or changing method signatures.
---
# API Design

## API Stability Annotations

- `@Alpha` — Early development, may be removed.
Not recommended for production use.
- `@Beta` — Subject to change or removal.
It's not recommended for Libraries to depend on these APIs.
- `@Evolving` — May add abstract methods in future releases.
Safe to use, but implementing/extending bears upgrade risk.
- `@Sealed` — Must not be extended or implemented by consumers.
Safe to use, but not to subclass.
- `@Deprecated` — Supported until next major release but should be migrated away from.
Comment on lines +7 to +17
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think a model should ever be applying some of these. I also don't know what "Libraries should not depend on these" means? Our users can depend on Beta, but we can change it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can ask the model to apply / create / update methods to add / remove these etc.. these. This is just a skill regarding their usage.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I slightly modified the text for clarity.


## Design Principles

- **Deep modules:** Prefer simple interfaces with powerful implementations over shallow wrappers.
- **Information hiding:** Bury complexity behind simple interfaces.
- **Pull complexity downward:** Make the implementer work harder so callers work less.
- **General-purpose over special-case:** Fewer flexible methods over many specialized ones.
- **Define errors out of existence:** Design APIs so errors cannot happen rather than detecting and handling them.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how to interpret this or check if a model has actually applied these principles. For example, the first one, "deep modules", seems to be a matter of intuition. In practice, I'm not sure how we would choose one approach vs another, or what would make a given approach have a "powerful implementation".


## Key Patterns

- Static factory methods: `Filters.eq()`, `Updates.set()`, `Aggregates.match()`
- Fluent builders: `MongoClientSettings.builder()` is the primary entry point
- Abstract core with pluggable transports
36 changes: 36 additions & 0 deletions .agents/skills/evergreen/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: evergreen
description: Evergreen CI infrastructure, configuration validation. Use when modifying .evergreen/ config, preparing to submit changes or understanding the Evergreen test matrix.
disable-model-invocation: true
allowed-tools: Bash(evergreen *)
---
# Evergreen

## Evergreen (MongoDB Internal CI)

Primary CI runs on MongoDB’s Evergreen system.
Configuration lives in `.evergreen/`.

- Do not modify `.evergreen/` configuration without review
- Evergreen runs the full test matrix across MongoDB versions, OS platforms, and JDK versions

## Validating Evergreen Configuration

After modifying `.evergreen/` files, validate the config locally:

```bash
evergreen validate .evergreen/.evg.yml
```

Always run this before submitting changes to `.evergreen/` to catch syntax errors and invalid task definitions.

## Testing with a Patch Build

To test your changes on Evergreen before merging, create a patch build:

```bash
evergreen patch -u
```

This uploads your uncommitted and committed local changes as a patch build on Evergreen, allowing you to run the full CI
test matrix against your branch.
63 changes: 63 additions & 0 deletions .agents/skills/project-guide/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
name: project-guide
description: Project structure, dependency graph, and guide for finding the right project to work in. Use when starting a task and unsure which project owns the relevant code, or when you need to understand cross-project dependencies.
---
# Project Guide

## Project Structure

| Project | Purpose |
| --- | --- |
| `bson` | BSON library (core serialization) |
| `bson-kotlin` | Kotlin BSON extensions |
| `bson-kotlinx` | Kotlin serialization BSON codec |
| `bson-record-codec` | Java record codec support |
| `bson-scala` | Scala BSON extensions |
| `driver-core` | Core driver internals (connections, protocol, operations) |
| `driver-sync` | Synchronous Java driver |
| `driver-legacy` | Legacy MongoDB Java driver API |
| `driver-reactive-streams` | Reactive Streams driver |
| `driver-kotlin-coroutine` | Kotlin Coroutines driver |
| `driver-kotlin-extensions` | Kotlin driver extensions |
| `driver-kotlin-sync` | Kotlin synchronous driver |
| `driver-scala` | Scala driver |
| `mongodb-crypt` | Client-side field-level encryption |
| `bom` | Bill of Materials for dependency management |
| `testing` | Shared test resources and MongoDB specifications |
| `buildSrc` | Gradle convention plugins and build infrastructure |
| `driver-benchmarks` | JMH and custom performance benchmarks (not published) |
| `driver-lambda` | AWS Lambda test application (not published) |
| `graalvm-native-image-app` | GraalVM Native Image compatibility testing (not published) |

## Dependency Graph (simplified)

```
bson
├── bson-kotlin
├── bson-kotlinx
├── bson-record-codec
├── bson-scala
└── driver-core
├── driver-sync
│ ├── driver-legacy
│ ├── driver-kotlin-sync
│ └── driver-lambda
├── driver-reactive-streams
│ ├── driver-kotlin-coroutine
│ └── driver-scala
└── driver-kotlin-extensions
```

## Finding the Right Module

- **BSON serialization/codecs:** `bson` (or `bson-kotlin`/`bson-kotlinx`/`bson-scala` for language-specific)
- **Query builders, filters, aggregates:** `driver-core` (`com.mongodb.client.model`)
- **Sync Java API:** `driver-sync`
- **Reactive API:** `driver-reactive-streams`
- **Kotlin coroutines:** `driver-kotlin-coroutine`
- **Kotlin DSL builders:** `driver-kotlin-extensions`
- **Scala driver:** `driver-scala`
- **Connection, protocol, auth internals:** `driver-core` (`com.mongodb.internal.*`)
- **Build plugins, formatting, test infra:** `buildSrc`

Each module has its own `AGENTS.md` with module-specific packages, patterns, and notes.
40 changes: 40 additions & 0 deletions .agents/skills/spec-tests/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
name: spec-tests
description: How to work with MongoDB specification tests — structure, rules, and adding new spec test support. Use when implementing or modifying behavior defined by the MongoDB Driver Specifications.
---
# MongoDB Specification Tests

## Overview

The driver implements the [MongoDB Driver Specifications](https://github.com/mongodb/specifications).
Specification test data files live in `testing/resources/specifications/` — a git submodule.

## Rules

- **Do not modify spec test data files** (JSON/YAML in `testing/resources/specifications/`) — managed upstream
- Test runners (Java code) may be modified to fix bugs or add support for new spec tests
- Update the submodule via `git submodule update`

## Structure

Spec test data is organized by specification area:

- CRUD, SDAM, auth, CSFLE, retryable operations, and more
- Each spec area has JSON/YAML test data files defining inputs and expected outputs
- Driver test runners parse these files and execute against the driver

## Test Data Location

```
testing/
resources/
specifications/ # Git submodule — do not edit directly
logback-test.xml # Shared logback configuration for tests
```

## Adding Spec Test Support

1. Check `testing/resources/specifications/` for the relevant spec test data
2. Find existing test runners in the module (look for `*SpecificationTest*` or similar)
3. Extend existing patterns — each module handles spec tests slightly differently
4. Ensure tests run with `./gradlew check` or the module’s test task
55 changes: 55 additions & 0 deletions .agents/skills/style-reference/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
name: style-reference
description: Detailed code style rules for Java, Kotlin, Scala, and Groovy in the MongoDB Java Driver. Use when you need specific formatting rules beyond the basics in root AGENTS.md — e.g., line length, import ordering, brace style.
---
# Style Reference

## Java Style Rules

- **Max line length:** 140 characters
- **Indentation:** 4 spaces (no tabs)
- **Line endings:** LF (Unix)
- **Charset:** UTF-8
- **Star imports:** Prohibited (AvoidStarImport)
- **Final parameters:** Required (FinalParameters checkstyle rule)
- **Braces:** Required for all control structures (NeedBraces)
- **Else placement:** `} else {` on the same line (Palantir Java Format default)
- **Copyright header:** Every Java / Kotlin / Scala file must contain `Copyright 2008-present MongoDB, Inc.`
- **Formatter:** Palantir Java Format

## Kotlin Style Rules

- **Formatter:** ktfmt dropbox style, max width 120
- **Static analysis:** detekt

## Scala Style Rules

- **Formatter:** scalafmt
- **Supported versions:** 2.11, 2.12, 2.13, 3 (default: 2.13)

## Groovy Style Rules

- **Static analysis:** CodeNarc

## Javadoc / KDoc / Scaladoc
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude identified these as missing


- All public classes and interfaces **must** have class-level Javadoc (enforced by checkstyle)
- Public methods should have Javadoc with `@param`, `@return`, and `@since` tags
- Use `@since X.Y` to indicate the version when the API was introduced
- Use `@mongodb.driver.manual <path> <label>` for MongoDB manual links
- Use `@mongodb.server.release <version>` to indicate the minimum server version required
- Scala modules use Scaladoc — follow Scaladoc conventions (`@param`, `@return`, `@since`, `@see`)
- Internal packages (`com.mongodb.internal.*`, `org.bson.internal.*`) are excluded from doc generation
- Run `./gradlew doc` to validate Javadoc/KDoc/Scaladoc builds cleanly

## Prohibited Patterns

- `System.out.println` / `System.err.println` — Use SLF4J logging
- `e.printStackTrace()` — Use proper logging/error handling

## Formatting Commands

```bash
./gradlew spotlessApply # Auto-fix all formatting
./gradlew spotlessCheck # Check without modifying
```
27 changes: 27 additions & 0 deletions .agents/skills/sync-agents-docs/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: sync-agents-docs
description: Sync AGENTS.md files and skills after buildSrc or convention changes. Use after modifying build plugins, formatting rules, testing conventions, or task names to keep documentation consistent.
disable-model-invocation: true
---
# Sync Documentation After Build Changes
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude identified the buildSrc/AGENTS.md was not the correct place for this as it changes code. It also recommended this not be automatically run by claude.


After modifying `buildSrc` or build conventions, check whether AGENTS.md files and skills need updating.
Review your changes against the checklist below and update only the affected files.

## Checklist

| What changed | What to update |
| --- | --- |
| Formatting conventions (`spotless.gradle.kts`) | Root `AGENTS.md` Style section, `style-reference` skill, affected module AGENTS.md files |
| Convention plugins added or removed | `buildSrc/AGENTS.md` plugin table, root `AGENTS.md` if build commands or workflow changed |
| Testing conventions (`testing-*.gradle.kts`) | Root `AGENTS.md` Testing section, `testing-guide` skill, affected module AGENTS.md files |
| Project plugins added or removed | `buildSrc/AGENTS.md` project plugin table |
| Build commands or task names changed | Root `AGENTS.md` Build and Before Submitting sections, `evergreen` skill, module AGENTS.md files |
| CI/CD or publishing changes | `evergreen` skill |

## How to use

1. Review the diff of your buildSrc changes
2. Walk through the checklist above — only rows matching your changes need action
3. Update the affected files, keeping changes minimal and accurate
4. Verify no stale references remain (e.g., renamed tasks, removed plugins)
69 changes: 69 additions & 0 deletions .agents/skills/testing-guide/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
name: testing-guide
description: Testing frameworks, conventions, and commands for the MongoDB Java Driver. Use when writing or running tests — covers framework selection per module, test naming conventions, integration test setup, and how to run specific test subsets.
---
# Testing Guide

## Frameworks

| Framework | Usage | Notes |
| --- | --- | --- |
| JUnit 5 (Jupiter) | Primary unit test framework | All new tests |
| Spock (Groovy) | Legacy tests | Do not add new Spock tests |
| Mockito | Mocking | Use `mockito-junit-jupiter` integration |
| ScalaTest | Scala module testing | FlatSpec + ShouldMatchers |
| Project Reactor | Reactive test utilities | `driver-reactive-streams` tests |

## Assertions

- **JUnit Jupiter Assertions** (`org.junit.jupiter.api.Assertions`) is the standard for all new tests
- Hamcrest matchers appear in older tests but should not be used in new code
- AssertJ is in the dependency catalog but is not used — do not introduce it
- Spock tests use Spock's built-in `expect:`/`then:` assertions (no external assertion library)

## Writing Tests

- Every code change must include tests
- Extend existing test patterns in the module you are modifying
- Unit tests must not require a running MongoDB instance
- Descriptive method names: `shouldReturnEmptyListWhenNoDocumentsMatch()` not `test1()`
- Use `@DisplayName` for human-readable names
- Clean up test data in `@AfterEach` / `cleanup()` to prevent pollution

## Running Tests

```bash
# All tests (unit + integration)
./gradlew check

# Single module
./gradlew :driver-core:test

# Integration tests (requires MongoDB)
./gradlew integrationTest -Dorg.mongodb.test.uri="mongodb://localhost:27017"

# Specific test class
./gradlew :driver-core:test --tests "com.mongodb.internal.operation.FindOperationTest"

# Alternative JDK
./gradlew test -PjavaVersion=11

# Scala tests (all versions)
./gradlew scalaCheck
```

## Module-Specific Notes

- **driver-core:** Largest test suite — JUnit 5 + Spock + Mockito
- **driver-sync:** JUnit 5 + Spock (heavy Spock usage, but don’t add new)
- **driver-reactive-streams:** JUnit 5 + Spock + Project Reactor
- **bson-scala / driver-scala:** ScalaTest, test per Scala version
- **Kotlin modules:** JUnit 5 + mockito-kotlin

## Integration Tests

- Require a running MongoDB instance
- Set connection URI: `-Dorg.mongodb.test.uri="mongodb://localhost:27017"`
- Integration test source set configured via `conventions/testing-integration.gradle.kts`

See [examples.md](examples.md) for Java, Scala, and Kotlin test skeletons.
Loading