This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
- Install dependencies:
uv sync - Run the application:
uv run python main.py(from root) oruv run python -m bird_travel_recommender - Run individual modules:
uv run python -m <module_name> - Add new dependencies:
uv add <package_name> - Activate environment:
source .venv/bin/activate(or useuv runprefix) - Run tests:
uv run pytest(tests intests/directory)
- Lint code:
uv run ruff check src/ - Format code:
uv run ruff format src/ - Fix lint issues:
uv run ruff check src/ --fix
- Verify API keys:
uv run python scripts/check_api_keys.py - Deploy MCP server:
uv run python scripts/deploy_mcp.py development
- Run MCP server:
uv run python src/bird_travel_recommender/mcp/server.py - Test MCP integration: Check scripts for test_*.py files for specific testing scenarios
The project follows modern Python packaging standards with a clean src/ layout:
Bird-Travel-Recommender/
├── src/bird_travel_recommender/ # Main package
│ ├── main.py # Application entry point
│ ├── flow.py # PocketFlow workflow definition (unified + legacy)
│ ├── nodes.py # Node imports (modularized)
│ ├── nodes/ # Legacy node implementations
│ │ ├── validation/ # Species validation nodes
│ │ ├── fetching/ # Data fetching nodes
│ │ ├── processing/ # Data processing nodes
│ │ └── ... # Other node categories
│ ├── core/ # 🆕 UNIFIED ARCHITECTURE
│ │ ├── config/ # Centralized settings with Pydantic
│ │ ├── ebird/ # Unified eBird API client
│ │ ├── exceptions/ # Professional exception hierarchy
│ │ ├── mcp/ # Unified MCP tool registry
│ │ └── nodes/ # Unified node implementations
│ │ ├── base.py # Abstract base classes
│ │ ├── factory.py # Node factory with dependency injection
│ │ ├── mixins.py # Reusable behavior mixins
│ │ └── implementations/ # Concrete unified nodes
│ ├── utils/ # Utility modules (legacy + unified)
│ │ ├── call_llm.py # OpenAI API integration
│ │ ├── ebird_api.py # eBird API client (legacy)
│ │ └── ... # Other utilities
│ └── mcp/ # MCP server integration
│ ├── server.py # MCP server implementation
│ └── config/ # MCP configuration files
├── tests/ # Test suite
│ ├── unit/ # Unit tests
│ ├── integration/ # Integration tests
│ ├── migration/ # Migration compatibility tests
│ └── fixtures/ # Test fixtures
├── scripts/ # Utility scripts
├── config/ # Configuration files
├── docs/ # Documentation
│ └── REFACTORING_PLAN.md # 🆕 Complete refactoring documentation
└── main.py # Development convenience entry point
This is a sophisticated PocketFlow-based Bird Travel Recommender system that leverages eBird API integration and expert birding knowledge. The architecture has undergone comprehensive refactoring to eliminate code duplication and achieve professional standards.
The codebase has undergone a comprehensive 4-phase refactoring plan that has achieved:
- ~1,700 lines of duplicate code eliminated (sync vs async implementations)
- Professional standards achieved with unified architecture patterns
- Zero breaking changes - full backward compatibility maintained
- Enhanced error handling with structured logging and metrics
- Type safety with Pydantic models throughout
✅ Phase 1: Foundation Layer - Unified eBird API client (core/ebird/client.py)
✅ Phase 2: MCP Tool Registry - Decorator-based tool system (core/mcp/registry.py)
✅ Phase 3: Node Factory Pattern - Unified node implementations (core/nodes/)
✅ Phase 4: All Nodes Migrated - Complete architecture transformation
# NEW: Unified architecture (recommended)
from .flow import create_unified_birding_flow, ExecutionMode
flow = create_unified_birding_flow(ExecutionMode.ASYNC)
# LEGACY: Original flows (deprecated but working)
from .flow import create_birding_flow, create_async_birding_flow
flow = create_async_birding_flow() # Still works with deprecation warning- Unified architecture: ✅ ACTIVE BY DEFAULT - Main flow now uses unified system
- Legacy flows: ✅ Available with deprecation warnings for gradual migration
- Tests: ✅ 139/144 passing (15 new unified architecture tests + existing coverage)
- Performance: ✅ ~0.1s flow creation, both sync/async modes operational
- Backward compatibility: ✅ 100% maintained - zero breaking changes
- ✅ PocketFlow Compatibility: RESOLVED - Created adapter system enabling unified nodes with
>>operator support - ✅ Architecture Validation: ALL TESTS PASSING - 15/15 unified architecture tests successful
- ✅ Performance Verified: Unified flows create in ~0.1s with both sync/async modes working perfectly
- ✅ Zero Breaking Changes: Complete backward compatibility maintained throughout
🚀 The unified architecture is now fully operational and activated by default!
The system features both legacy and unified architectures:
- FetchSightingsNode - Retrieves recent bird sightings data (nodes/fetching/)
- ClusterHotspotsNode - Identifies optimal birding locations (nodes/processing/)
- ValidateSpeciesNode - Validates bird species with taxonomic lookup (nodes/validation/)
- FilterConstraintsNode - Filters data based on user constraints (nodes/processing/)
- ScoreLocationsNode - Scores birding locations (nodes/processing/)
- OptimizeRouteNode - Optimizes travel routes (nodes/processing/)
- GenerateItineraryNode - Creates detailed itineraries (nodes/processing/)
- DecideBirdingToolNode - Enhanced with expert birding knowledge for species-specific advice, habitat assessment, and optimal observation timing
- Location Scoring - Evaluates birding potential of destinations
- Itinerary Generation - Creates detailed birding trip plans
- Species Validation - Prioritizes direct taxonomy lookup over external dependencies
- Enrichment-in-Place Strategy - Embeds validation flags within original data structures
- Dual Discovery Methods - Smart endpoint selection for optimal API performance
- Bootstrap Statistical Models - Negative binomial models for handling data overdispersion
- Comprehensive Schema Validation - JSON schemas ensure data integrity
The architecture leverages proven patterns from the moonbirdai/ebird-mcp-server JavaScript implementation, providing production-level reliability and scalability.
- Copy
.env.exampleto.env:cp .env.example .env - Fill in your actual API keys in the
.envfile:- OPENAI_API_KEY: Get from https://platform.openai.com/api-keys
- EBIRD_API_KEY: Get from https://ebird.org/api/keygen
- Uses GPT-4o model by default (configurable in
src/bird_travel_recommender/utils/call_llm.py) - Environment variables loaded automatically via python-dotenv
- Default settings can be configured in
.envfile - MCP configurations available in
src/bird_travel_recommender/mcp/config/
This project follows agentic coding principles from PocketFlow documentation:
- Human-AI Collaboration: Humans design at high level, AI implements details
- Start Simple: Begin with small, simple solutions before adding complexity
- Design First: Reference
docs/design.mdbefore major implementation changes - Frequent Feedback: Ask humans for feedback and clarification during development
- Flow-Based Architecture: Use PocketFlow's Node->Flow pattern for all workflows
- Follow PocketFlow's utility function separation (external APIs in
utils/) - Use structured error handling and logging
- Maintain type safety with Pydantic models
- Implement graceful fallbacks for LLM calls
- Keep nodes simple and focused on single responsibilities
- When asked where we left off, check changelog, memory, and git commit
- Always check changelog when asked "where did we leave off"