Skip to content

Commit 9625c95

Browse files
committed
docs: expand CLAUDE.md with test infrastructure, startup behavior, and architecture context
Add missing context that improves AI-assisted development: custom test annotations table, test configuration classes, auto-configuration chain, startup ordering (RolePrivilegeSetupService), design decisions to preserve (serializable isolation, event-driven architecture, compileOnly starters), expanded configuration property groups, and references to related docs.
1 parent 8bfd7ab commit 9625c95

1 file changed

Lines changed: 70 additions & 8 deletions

File tree

CLAUDE.md

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
66

77
Spring User Framework is a reusable Spring Boot library (not an application) that provides user authentication and management features built on Spring Security. It supports Spring Boot 4.0 (Java 21+) and Spring Boot 3.5 (Java 17+).
88

9+
**This is a library, not an app.** All Spring Boot starters are `compileOnly` dependencies. Consuming applications provide their own database, mail server, and security configuration. Never add Spring starters as `implementation` dependencies.
10+
911
## Commands
1012

1113
```bash
@@ -59,7 +61,7 @@ com.digitalsanctuary.spring.user
5961
### Key Components
6062

6163
**Entry Points:**
62-
- `UserConfiguration` - Main auto-configuration class, enables async/scheduling/method security
64+
- `UserConfiguration` - Main auto-configuration class, enables async/retry/scheduling/method security
6365
- `WebSecurityConfig` - Spring Security filter chain configuration
6466
- `UserAPI` - REST endpoints at `/user/*` (registration, password reset, profile update)
6567

@@ -81,14 +83,36 @@ com.digitalsanctuary.spring.user
8183
- `BaseSessionProfile<T>` - Session-scoped profile access
8284
- `UserPreDeleteEvent` - Listen for user deletion to clean up related data
8385

86+
### Auto-Configuration
87+
88+
- Entry point: `META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports``UserConfiguration`
89+
- `UserAutoConfigurationRegistrar` dynamically registers the library package for entity/repository scanning
90+
- No conditional annotations — all features load, controlled by `user.*` properties
91+
92+
### Startup Behavior
93+
94+
- `RolePrivilegeSetupService` listens for `ContextRefreshedEvent` and creates/updates Role and Privilege entities from `user.roles-and-privileges` config. Must complete before any auth requests.
95+
- `PasswordHashTimeTester` runs async on `ApplicationStartedEvent` to benchmark bcrypt performance (controlled by `user.security.testHashTime`).
96+
97+
### Design Decisions to Preserve
98+
99+
- `UserService.createUser()` uses `@Transactional(isolation = Isolation.SERIALIZABLE)` to prevent race conditions during concurrent registration
100+
- Event-driven architecture: `AuthenticationEventListener`, `RegistrationListener`, `AuditEventListener`, `BaseAuthenticationListener` — don't bypass events
101+
- All Spring starters are `compileOnly` — this is intentional for library consumers
102+
84103
### Configuration
85104

86-
All configuration uses `user.*` prefix in application.yml. Key properties:
87-
- `user.security.*` - URIs, default action (allow/deny), bcrypt strength, lockout
88-
- `user.registration.*` - Email verification toggle
89-
- `user.mail.*` - Email sender settings
90-
- `user.audit.*` - Audit logging configuration
91-
- `user.roles.*` - Role/privilege definitions and hierarchy
105+
All configuration uses `user.*` prefix in application.yml. Key property groups:
106+
- `user.security.*` - URIs, default action (allow/deny), bcrypt strength, lockout settings, testHashTime
107+
- `user.registration.*` - Email verification toggle, OAuth provider toggles
108+
- `user.mail.*` - Email sender settings (fromAddress)
109+
- `user.audit.*` - Audit logging (logFilePath, flushOnWrite, logEvents, maxQueryResults)
110+
- `user.roles-and-privileges` - Role-to-privilege mapping (applied on startup)
111+
- `user.role-hierarchy` - Role inheritance (e.g., ROLE_ADMIN > ROLE_MANAGER)
112+
- `user.gdpr.*` - GDPR features (enabled, exportBeforeDeletion, consentTracking)
113+
- `user.purgetokens.cron.*` - Token cleanup schedule
114+
- `user.session.invalidation.warn-threshold` - Performance warning threshold
115+
- `user.actuallyDeleteAccount` - Hard delete vs disable
92116

93117
## Code Style
94118

@@ -97,7 +121,45 @@ All configuration uses `user.*` prefix in application.yml. Key properties:
97121
- **Logging**: SLF4J via Lombok `@Slf4j`
98122
- **DI**: `@RequiredArgsConstructor` with `final` fields
99123
- **Documentation**: JavaDoc on public classes/methods
124+
- **Assertions**: AssertJ fluent style (not JUnit assertEquals)
125+
- **Test naming**: `should[ExpectedBehavior]When[Condition]` pattern
100126

101127
## Testing
102128

103-
Tests use H2 in-memory database. The framework uses JUnit 5 with parallel execution enabled. Key test dependencies: Testcontainers, WireMock, GreenMail (email), AssertJ, REST Assured.
129+
Tests use H2 in-memory database with JUnit 5 parallel execution. Key dependencies: Testcontainers, WireMock, GreenMail, AssertJ, REST Assured.
130+
131+
### Custom Test Annotations (use these instead of raw Spring annotations)
132+
133+
| Annotation | Use When | Spring Context | Key Imports |
134+
|---|---|---|---|
135+
| `@ServiceTest` | Unit testing services with mocks | None (Mockito only) | `BaseTestConfiguration` |
136+
| `@DatabaseTest` | Testing JPA repositories | `@DataJpaTest` slice | `DatabaseTestConfiguration` |
137+
| `@IntegrationTest` | Full workflow testing | Full context | All 5 test configs |
138+
| `@SecurityTest` | Testing auth/authorization | Full context + security | `SecurityTestConfiguration` |
139+
| `@OAuth2Test` | Testing OAuth2/OIDC flows | Full context + OAuth2 | `OAuth2TestConfiguration` |
140+
141+
All annotations are in `com.digitalsanctuary.spring.user.test.annotations`.
142+
143+
### Test Configuration Classes (`test.config` package)
144+
145+
- `BaseTestConfiguration` - BCrypt strength 4 (fast), fixed Clock (2024-01-15 10:00 UTC), mock EventPublisher, SessionRegistry
146+
- `SecurityTestConfiguration` - Pre-built test users: `user@test.com`, `admin@test.com`, `moderator@test.com` (password: "password"). `TestSecurityContextFactory` for custom contexts.
147+
- `OAuth2TestConfiguration` - Mock OAuth2/OIDC providers (Google, GitHub, OIDC), test token factory
148+
- `MockMailConfiguration` - Captures sent emails via `TestMailCapture` instead of sending
149+
- `DatabaseTestConfiguration` - Database-specific test setup
150+
151+
### Test Application
152+
153+
Integration tests use `TestApplication` (in `test.app` package) as their Spring Boot context class.
154+
155+
## Related Documentation
156+
157+
- `TESTING.md` - Comprehensive testing guide with patterns and troubleshooting
158+
- `PROFILE.md` - User profile extension framework
159+
- `CONFIG.md` - Configuration reference
160+
- `MIGRATION.md` - Version migration guide
161+
- `CONTRIBUTING.md` - Contributor guidelines (fork/branch/PR workflow)
162+
163+
## Release Process
164+
165+
Version is in `gradle.properties`. Do not manually update version numbers. The release process (`./gradlew release`) handles versioning, changelog generation, tagging, and Maven Central publishing automatically.

0 commit comments

Comments
 (0)