Code Quality Guidelines
Overview
This document outlines code quality standards and best practices for the AI-Powered Photo Journaling Flutter app.Code Organization
Directory Structure
Feature Module Structure
Each feature follows clean architecture:Coding Standards
Dart Style Guide
Follow Effective Dart:-
Naming:
- Classes:
PascalCase - Functions/variables:
camelCase - Constants:
lowerCamelCase - Files:
snake_case.dart
- Classes:
-
Formatting:
- Use
dart format .before committing - Max line length: 80 characters
- Use trailing commas for better diffs
- Use
-
Imports:
- Organize imports: dart → flutter → packages → relative
- Use relative imports for project files
- Avoid unused imports
Widget Best Practices
- Use const constructors wherever possible:
- Split large widgets into smaller, focused widgets:
- Use keys for list items:
- Implement proper dispose:
State Management
-
BLoC Pattern:
- Use
flutter_blocfor complex state - Keep business logic in BLoC
- Use events for actions, states for UI updates
- Use
-
State Locality:
- Keep state as local as possible
- Avoid global state when not needed
- Use
StatefulWidgetfor local state
-
Immutability:
- Use immutable state classes
- Use
equatablefor value equality - Avoid mutable collections in state
Error Handling
- Use try-catch for async operations:
- Provide user-friendly messages:
- Log errors in debug mode:
Performance Optimization
Widget Performance
- Const constructors: Prevent unnecessary rebuilds
- RepaintBoundary: Isolate expensive widgets
- ListView.builder: For long lists
- Lazy loading: Load data on demand
- Image caching: Use
cached_network_image
Memory Management
- Dispose controllers: Always dispose in
dispose() - Cancel subscriptions: Cancel streams and listeners
- Weak references: Use when appropriate
- Image memory: Configure
maxCacheSizeandmaxCacheSizeBytes
Build Optimization
- Use profile mode for performance testing
- Enable obfuscation in release builds
- Tree-shake icons: Remove unused icons
- Split debug info: Reduce app size
Testing
Unit Tests
Test business logic and utilities:Widget Tests
Test widget behavior:Integration Tests
Test complete flows:Documentation
Code Comments
- Document public APIs:
- Explain complex logic:
- Use TODO for future work:
README Files
- Project root: Setup and overview
- Feature modules: Feature-specific docs
- Complex algorithms: Explanation and examples
Code Review Checklist
Before Submitting PR
- Code follows style guide
- All tests passing
- No linting warnings
- Proper error handling
- Performance considered
- Accessibility tested
- Documentation updated
- No debug code (print statements, etc.)
- No commented-out code
- Commit messages follow convention
Reviewing Code
Look for:- Code readability
- Proper abstractions
- Error handling
- Edge cases covered
- Performance implications
- Security considerations
- Test coverage
- Documentation quality
Common Anti-Patterns to Avoid
1. God Widgets
❌ Bad:2. setState in Parent
❌ Bad:3. Unnecessary Rebuilds
❌ Bad:4. Missing Dispose
❌ Bad:Tools
Static Analysis
Performance Profiling
Code Coverage
Resources
Last Updated: 2025-11-15 Maintained By: Frontend Developer