# adapter:outbound:persistence-mongo — module rules ## Registered identity - Module ID: `adapter-outbound-persistence-mongo` - Gradle path: `:adapter:outbound:persistence-mongo` - Focused test (derived from Gradle path): `./gradlew :adapter:outbound:persistence-mongo:test --console=plain` - Runtime baseline: Java 21; repository framework baseline: Spring Boot 4.0.0. - Registry SSOT: `src/config/architecture/modules.json`. Package root: `dev.caskeleton.adapter.outbound.mongo`. Driven (outbound) adapter — opt-in Spring Data MongoDB infrastructure. Design rationale lives in [README.md](README.md). ## Responsibility - Provide opt-in Mongo client and template infrastructure without shipping a fake business domain. - Real forks add their own document, repository, mapper, and application/domain port implementation. - It does **not** reimplement idempotency / outbox / lock on Mongo (those stay JPA-only). - Opt-in: `MongoPersistenceConfig` re-imports the Mongo auto-configuration (`@ImportAutoConfiguration`) only when `ca-skeleton.persistence-mongo.enabled=true` (default off). The connection URI and database come from Spring's standard `spring.data.mongodb.*` settings. - `MongoOptInAutoConfigurationImportFilter`, registered through `META-INF/spring.factories`, blocks Boot 4's classpath-driven sync/reactive/data/repository/health/metrics Mongo auto-configuration when the module enable flag is absent or false. ## Allowed - No project dependency is required by the generic infrastructure. The allowed-edge SSOT remains the `adapter-outbound-persistence-mongo` entry in `src/config/architecture/modules.json`. - External: `org.springframework.boot:spring-boot-starter-data-mongodb` (version via the shared Spring Boot BOM), `spring-boot-configuration-processor` (annotation processor). ## Forbidden - Inbound adapters, sibling outbound adapters, `app-bootstrap`, `sample-portfolio` (ArchUnit `OUTBOUND_ADAPTERS_*` family rules). - Shipping placeholder `Example*` document, repository, record, or adapter types in production. - Adding idempotency/outbox/lock on Mongo without a separately approved contract. - Fully-qualified inline type references; more than one public top-level type per file. ## Tests `MongoPersistenceConfigTest` proves default/false behavior through an actual `@EnableAutoConfiguration` context, typed enablement binding, and enabled infrastructure with a mock `MongoClient` plus a real `MongoTemplate` without a network connection. ```bash cd src ./gradlew :adapter:outbound:persistence-mongo:check ```