mirror of
https://github.com/bitwarden/android.git
synced 2026-04-30 04:49:36 -05:00
3.7 KiB
3.7 KiB
Claude Guidelines
Core directives for maintaining code quality and consistency in the Bitwarden Android project.
Core Directives
You MUST follow these directives at all times.
- Adhere to Architecture: All code modifications MUST follow patterns in
docs/ARCHITECTURE.md - Follow Code Style: ALWAYS follow
docs/STYLE_AND_BEST_PRACTICES.md - Error Handling: Use Result types and sealed classes per architecture guidelines
- Best Practices: Follow Kotlin idioms (immutability, appropriate data structures, coroutines)
- Document Everything: All public APIs require KDoc documentation
- Dependency Management: Use Hilt DI patterns as established in the project
- Use Established Patterns: Leverage existing components before creating new ones
- File References: Use file:line_number format when referencing code
Code Quality Standards
Module Organization
Core Library Modules:
:core- Common utilities and managers shared across multiple modules:data- Data sources, database, data repositories:network- Networking interfaces, API clients, network utilities:ui- Reusable Bitwarden Composables, theming, UI utilities
Application Modules:
:app- Password Manager application, feature screens, ViewModels, DI setup:authenticator- Authenticator application for 2FA/TOTP code generation
Specialized Library Modules:
:authenticatorbridge- Communication bridge between :authenticator and :app:annotation- Custom annotations for code generation (Hilt, Room, etc.):cxf- Android Credential Exchange (CXF/CXP) integration layer
Patterns Enforcement
- MVVM + UDF: ViewModels with StateFlow, Compose UI
- Hilt DI: Interface injection, @HiltViewModel, @Inject constructor
- Testing: JUnit 5, MockK, Turbine for Flow testing
- Error Handling: Sealed Result types, no throws in business logic
Security Requirements
Every change must consider:
- Zero-knowledge architecture preservation
- Proper encryption key handling (Android Keystore)
- Input validation and sanitization
- Secure data storage patterns
- Threat model implications
Workflow Practices
Before Implementation
- Read relevant architecture documentation
- Search for existing patterns to follow
- Identify affected modules and dependencies
- Consider security implications
During Implementation
- Follow existing code style in surrounding files
- Write tests alongside implementation
- Add KDoc to all public APIs
- Validate against architecture guidelines
After Implementation
- Ensure all tests pass
- Verify compilation succeeds
- Review security considerations
- Update relevant documentation
Anti-Patterns
Avoid these:
- Creating new patterns when established ones exist
- Exception-based error handling in business logic
- Direct dependency access (use DI)
- Mutable state in ViewModels (use StateFlow)
- Missing null safety handling
- Undocumented public APIs
- Tight coupling between modules
Communication & Decision-Making
Always clarify ambiguous requirements before implementing. Use specific questions:
- "Should this use [Approach A] or [Approach B]?"
- "This affects [X]. Proceed or review first?"
- "Expected behavior for [specific requirement]?"
Defer high-impact decisions to the user:
- Architecture/module changes, public API modifications
- Security mechanisms, database migrations
- Third-party library additions
Reference Documentation
Critical resources:
docs/ARCHITECTURE.md- Architecture patterns and principlesdocs/STYLE_AND_BEST_PRACTICES.md- Code style guidelines
Do not duplicate information from these files - reference them instead.