Skip to content

Rename refactor#1

Merged
dasevilla merged 18 commits intomainfrom
rename-refactor
Sep 11, 2025
Merged

Rename refactor#1
dasevilla merged 18 commits intomainfrom
rename-refactor

Conversation

@dasevilla
Copy link
Owner

Refactors the project to support building Anki decks for both Scouting America merit badges and Cub Scout Adventures, renaming the repository and codebase from scout-merit-badges-anki to scout-anki. It introduces a more flexible CLI, updates documentation and configuration, and adds a new processor for Cub Scout adventures. The changes streamline deck building, clarify usage, and enable the generation of multiple deck types.

- Rename package: scout_merit_badges_anki → scout_anki
- Update CLI command: scout-merit-badges-anki → scout-anki
- Update project metadata and documentation
- Update all import statements and test paths
- Verify functionality with successful deck creation

Prepares for Phase 2: Generic deck type support
- Update CLI signature: scout-anki build DECK_TYPE DIRECTORY
- Add deck type validation: merit-badges, cub-adventures
- Implement routing dispatcher with auto-generated defaults
- Preserve all merit badge functionality
- Add cub-adventures placeholder for Phase 3
- Update tests, Makefile, and documentation

Clean, extensible interface ready for Phase 3 implementation
- Add adventure.py module with Adventure schema and processing
- Implement adventure JSON discovery across rank directories
- Add adventure image mapping with 97.6% success rate (122/125)
- Extend deck.py with adventure card template and creation
- Replace CLI placeholder with full adventure functionality
- Add adventure-specific summary reporting
- Support 125 adventures across 6 rank levels
- Create 3.9MB adventure deck with professional card layout

Complete implementation: scout-anki now supports both merit badges and Cub Scout adventures
- Extract shared logic into DeckProcessor base class
- Create MeritBadgeProcessor and AdventureProcessor implementations
- Simplify CLI from 250+ lines to 60 lines (76% reduction)
- Eliminate ~150 lines of duplicate code
- Implement clean processor pattern for extensibility
- Preserve all functionality with no regressions

Benefits:
- DRY principle: shared workflow logic
- Single responsibility: one processor per deck type
- Easy extensibility: add new deck types with minimal changes
- Improved maintainability: centralized shared logic
- Add config.py with JSON-based configuration management
- Support hierarchical config loading: current dir → home → ~/.config/
- Integrate configuration into DeckProcessor base class
- Add 'scout-anki config' command with --show and --save options
- Implement priority system: CLI options > config > built-in defaults
- Per-deck-type configuration support
- Graceful fallbacks when no config file exists

Features:
- Persistent user preferences in scout-anki.json
- Per-project configuration support
- No breaking changes to existing workflows
- Easy extensibility for future config options
- Remove complex configuration system (config.py, scout-anki config command)
- Update defaults to be cleaner and more useful:
  - merit_badges.apkg (was merit_badges_image_trainer.apkg)
  - cub_adventures.apkg (was cub_adventures_image_trainer.apkg)
  - 'Merit Badges' deck name (was 'Merit Badges Visual Trainer')
  - 'Cub Adventures' deck name (was 'Cub Scout Adventures')
  - 'Merit Badge Quiz' model (was 'Merit Badge Image → Text')
  - 'Adventure Quiz' model (was 'Cub Scout Adventure Image → Text')

Benefits:
- Simpler, cleaner filenames and names
- No configuration complexity
- CLI options still work for customization
- Easier to understand and use
- Move merit badge files to merit_badges/ subdirectory:
  - merit_badge.py → merit_badges/processor.py
  - directory.py → merit_badges/directory.py
  - mapping.py → merit_badges/mapping.py

- Move cub adventure files to cub_adventures/ subdirectory:
  - adventure_processor.py → cub_adventures/processor.py
  - adventure.py → cub_adventures/adventure.py

- Update all imports throughout codebase
- Fix test imports for new structure
- Add __init__.py files for proper Python packages

Benefits:
- Better organization and separation of concerns
- Cleaner project structure
- Easier to find deck-specific code
- Scalable for future deck types
- Extract mapping logic from adventure.py to separate mapping.py
- Rename directory.py to data.py for merit badges (matches adventure.py pattern)
- Both subdirectories now have consistent structure:
  - processor.py (main processor logic)
  - mapping.py (image mapping logic)
  - data.py/adventure.py (data structures and loading)

Benefits:
- Consistent naming and organization
- Clear separation of concerns
- Easier to understand and maintain
- Scalable pattern for future deck types
- Move directory processing logic directly into MeritBadgeProcessor
- Remove data.py file (was just one function)
- Update tests to use processor directly instead of separate module
- Fix line length issues in tests

Benefits:
- Simpler structure - no unnecessary intermediate files
- More consistent with adventure processor pattern
- Fewer imports and dependencies
- Cleaner organization

Final structure:
merit_badges/
├── processor.py (includes directory processing)
├── mapping.py (image mapping logic)
└── __init__.py

cub_adventures/
├── processor.py (main logic)
├── adventure.py (data structures + directory processing)
├── mapping.py (image mapping logic)
└── __init__.py
- Add image_filename field to Badge and Adventure classes
- Replace complex pattern matching with direct field lookup
- Achieve 100% mapping success for both merit badges and adventures
- Remove ~100 lines of complex mapping logic
- Simplify and improve reliability of image mapping
- Rename build-deck to build-merit-badges for consistency
- Add build-cub-adventures command
- Add build-all command to build both deck types
- Update fetch-and-build commands with consistent naming
- Improve help text with clear command descriptions
- Remove separate mapping.py files for both deck types
- Move simple mapping logic directly into processor classes
- Rename adventure.py to schema.py for consistency
- Update imports and fix test mocking
- Simplify architecture by removing ~80 lines of code
- Update class name from Badge to MeritBadge in merit badges schema
- Update all type annotations and imports in deck.py
- Fix line length formatting for linting compliance
- Improve code clarity with more specific class naming
- Add cub adventures support to README.md usage examples
- Update Makefile commands with new naming conventions
- Reflect simplified image mapping using direct field lookup
- Update copilot instructions with current architecture
- Document both merit-badges and cub-adventures deck types
- Split tests into separate files for merit badges, cub adventures, and CLI
- Fix test issues with correct class names and directory structures
- Increase coverage from 51% to 68%
- All 15 tests now pass with focused, maintainable approach
- Create scout_anki/image_utils.py with shared image processing functions
- Replace duplicate image discovery logic in both processors
- Replace duplicate content-to-image mapping logic
- Maintain identical functionality while improving maintainability
- All tests pass, linting clean
- Add NoImagesFoundError exception to errors.py
- Replace ValueError with NoImagesFoundError in processor.py
- Remove string matching in CLI error handling
- Maintain same exit codes for backward compatibility
- Improve type safety and maintainability
- Add ContentItem protocol for type-safe content interface
- Replace Any with specific types: MeritBadge, Adventure, Path, genanki.Deck
- Update all processor method signatures with proper types
- Improve return types for mapping summaries and deck creation
- Enhance type safety while maintaining flexibility through protocols
- Better IDE support and compile-time error detection
@dasevilla dasevilla merged commit 84e02f6 into main Sep 11, 2025
4 checks passed
@dasevilla dasevilla deleted the rename-refactor branch September 11, 2025 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant