Skip to main content

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:
  1. Naming:
    • Classes: PascalCase
    • Functions/variables: camelCase
    • Constants: lowerCamelCase
    • Files: snake_case.dart
  2. Formatting:
    • Use dart format . before committing
    • Max line length: 80 characters
    • Use trailing commas for better diffs
  3. Imports:
    • Organize imports: dart → flutter → packages → relative
    • Use relative imports for project files
    • Avoid unused imports

Widget Best Practices

  1. Use const constructors wherever possible:
  1. Split large widgets into smaller, focused widgets:
  1. Use keys for list items:
  1. Implement proper dispose:

State Management

  1. BLoC Pattern:
    • Use flutter_bloc for complex state
    • Keep business logic in BLoC
    • Use events for actions, states for UI updates
  2. State Locality:
    • Keep state as local as possible
    • Avoid global state when not needed
    • Use StatefulWidget for local state
  3. Immutability:
    • Use immutable state classes
    • Use equatable for value equality
    • Avoid mutable collections in state

Error Handling

  1. Use try-catch for async operations:
  1. Provide user-friendly messages:
  1. Log errors in debug mode:

Performance Optimization

Widget Performance

  1. Const constructors: Prevent unnecessary rebuilds
  2. RepaintBoundary: Isolate expensive widgets
  3. ListView.builder: For long lists
  4. Lazy loading: Load data on demand
  5. Image caching: Use cached_network_image

Memory Management

  1. Dispose controllers: Always dispose in dispose()
  2. Cancel subscriptions: Cancel streams and listeners
  3. Weak references: Use when appropriate
  4. Image memory: Configure maxCacheSize and maxCacheSizeBytes

Build Optimization

  1. Use profile mode for performance testing
  2. Enable obfuscation in release builds
  3. Tree-shake icons: Remove unused icons
  4. 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

  1. Document public APIs:
  1. Explain complex logic:
  1. 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:
Good:

2. setState in Parent

Bad:
Good:

3. Unnecessary Rebuilds

Bad:
Good:

4. Missing Dispose

Bad:
Good:

Tools

Static Analysis

Performance Profiling

Code Coverage

Resources


Last Updated: 2025-11-15 Maintained By: Frontend Developer