- Enhanced infrastructure.md with identifier convention table, format requirements, migration notes - Updated docs/README.md with series identifier convention section - Updated docs/api_reference.md with key-based API examples and notes - Added deprecation warnings to SerieList.get_by_folder() - Added deprecation warnings to anime.py folder fallback lookup - Added deprecation warnings to validate_series_key_or_folder() - All warnings include v3.0.0 removal timeline - All 1006 tests pass
14 KiB
Aniworld Web Application Development Instructions
This document provides detailed tasks for AI agents to implement a modern web application for the Aniworld anime download manager. All tasks should follow the coding guidelines specified in the project's copilot instructions.
Project Overview
The goal is to create a FastAPI-based web application that provides a modern interface for the existing Aniworld anime download functionality. The core anime logic should remain in SeriesApp.py while the web layer provides REST API endpoints and a responsive UI.
Architecture Principles
- Single Responsibility: Each file/class has one clear purpose
- Dependency Injection: Use FastAPI's dependency system
- Clean Separation: Web layer calls core logic, never the reverse
- File Size Limit: Maximum 500 lines per file
- Type Hints: Use comprehensive type annotations
- Error Handling: Proper exception handling and logging
Additional Implementation Guidelines
Code Style and Standards
- Type Hints: Use comprehensive type annotations throughout all modules
- Docstrings: Follow PEP 257 for function and class documentation
- Error Handling: Implement custom exception classes with meaningful messages
- Logging: Use structured logging with appropriate log levels
- Security: Validate all inputs and sanitize outputs
- Performance: Use async/await patterns for I/O operations
📞 Escalation
If you encounter:
- Architecture issues requiring design decisions
- Tests that conflict with documented requirements
- Breaking changes needed
- Unclear requirements or expectations
Document the issue and escalate rather than guessing.
📚 Helpful Commands
# Run all tests
conda run -n AniWorld python -m pytest tests/ -v --tb=short
# Run specific test file
conda run -n AniWorld python -m pytest tests/unit/test_websocket_service.py -v
# Run specific test class
conda run -n AniWorld python -m pytest tests/unit/test_websocket_service.py::TestWebSocketService -v
# Run specific test
conda run -n AniWorld python -m pytest tests/unit/test_websocket_service.py::TestWebSocketService::test_broadcast_download_progress -v
# Run with extra verbosity
conda run -n AniWorld python -m pytest tests/ -vv
# Run with full traceback
conda run -n AniWorld python -m pytest tests/ -v --tb=long
# Run and stop at first failure
conda run -n AniWorld python -m pytest tests/ -v -x
# Run tests matching pattern
conda run -n AniWorld python -m pytest tests/ -v -k "auth"
# Show all print statements
conda run -n AniWorld python -m pytest tests/ -v -s
#Run app
conda run -n AniWorld python -m uvicorn src.server.fastapi_app:app --host 127.0.0.1 --port 8000 --reload
Final Implementation Notes
- Incremental Development: Implement features incrementally, testing each component thoroughly before moving to the next
- Code Review: Review all generated code for adherence to project standards
- Documentation: Document all public APIs and complex logic
- Testing: Maintain test coverage above 80% for all new code
- Performance: Profile and optimize critical paths, especially download and streaming operations
- Security: Regular security audits and dependency updates
- Monitoring: Implement comprehensive monitoring and alerting
- Maintenance: Plan for regular maintenance and updates
Task Completion Checklist
For each task completed:
- Implementation follows coding standards
- Unit tests written and passing
- Integration tests passing
- Documentation updated
- Error handling implemented
- Logging added
- Security considerations addressed
- Performance validated
- Code reviewed
- Task marked as complete in instructions.md
- Infrastructure.md updated
- Changes committed to git; keep your messages in git short and clear
- Take the next task
Prerequisites
- Server is running:
conda run -n AniWorld python -m uvicorn src.server.fastapi_app:app --host 127.0.0.1 --port 8000 --reload - Password:
Hallo123! - Login via browser at
http://127.0.0.1:8000/login
Notes
- This is a simplification that removes complexity while maintaining core functionality
- Improves user experience with explicit manual control
- Easier to understand, test, and maintain
- Good foundation for future enhancements if needed
🎯 CRITICAL: Series Identifier Standardization
Overview
Problem: The codebase currently uses multiple identifiers inconsistently:
key(provider identifier, e.g., "attack-on-titan")folder(filesystem folder name, e.g., "Attack on Titan (2013)")serie_id(sometimes key, sometimes folder)serie_folder(filesystem path used as identifier)
Solution: Standardize on key as the single source of truth for all series identification.
Benefits:
- Single, consistent identifier throughout the codebase
keyis unique, provider-assigned, URL-safefolderbecomes metadata only (not used for lookups)- Clearer separation of concerns
- Easier to maintain and debug
Scope: This affects core logic, services, API endpoints, frontend, WebSocket events, and tests.
Task Series: Identifier Standardization
Phase 4: API Layer ✅ (Completed November 28, 2025)
All API layer tasks completed.
Phase 5: Frontend ✅ (Completed November 28, 2025)
Phase 6: Database Layer ✅ (Completed November 28, 2025)
All database layer tasks completed:
- Task 6.1: Verified
AnimeSeries.keyis unique and indexed,folderis metadata only, updated docstrings - Task 6.2: Verified all service methods use
keyfor lookups, no folder-based identification
Phase 7: Testing and Validation ✅ Completed November 28, 2025
Task 7.1: Update All Test Fixtures to Use Key ✅
Files: All test files in tests/
Objective: Ensure all test fixtures and mocks use key consistently.
Steps:
- Search for all test files using
folderas identifier - Update
FakeSerieclass intests/api/test_anime_endpoints.py:- Ensure
keyis the primary identifier
- Ensure
- Update all test fixtures to use
key - Update mock data to use realistic
keyvalues - Ensure tests verify both
keyandfolderare present but onlykeyis used for operations
Success Criteria:
- All test fixtures use
keyas identifier - Tests verify
keyis used for operations - Tests verify
folderis present as metadata - All tests pass (1006 tests passing)
Test Command:
conda run -n AniWorld python -m pytest tests/ -v
Completion Notes:
- Updated
FakeSerieandFakeSeriesAppintest_anime_endpoints.pywith realistic keys - Updated fixtures in
test_websocket_integration.py(6+ fixtures) - Updated fixtures in
test_download_progress_integration.py(5 fixtures) - Updated fixtures in
test_download_progress_websocket.py(9 fixtures) - Updated fixtures in
test_download_models.py(10+ fixtures) - All fixtures now use URL-safe, lowercase, hyphenated key format
Task 7.2: Add Integration Tests for Identifier Consistency ✅
File: Created tests/integration/test_identifier_consistency.py
Objective: Create integration tests to verify key is used consistently across all layers.
Steps:
- Create
tests/integration/test_identifier_consistency.py - Write test to verify:
- API endpoint returns
keyas identifier - Download service uses
key - Database lookups use
key - WebSocket events include
key
- API endpoint returns
- Write test to verify
folderis never used for lookups - Write test for end-to-end flow using
key
Success Criteria:
- Integration test file created
- Tests verify
keyusage across all layers - Tests verify
foldernot used for identification - All integration tests pass (10 tests)
Completion Notes:
- Created comprehensive test file with 10 tests:
TestAPIIdentifierConsistency: 2 tests for API response validationTestServiceIdentifierConsistency: 2 tests for download service key usageTestWebSocketIdentifierConsistency: 2 tests for WebSocket eventsTestIdentifierValidation: 2 tests for model validationTestEndToEndIdentifierFlow: 2 tests for full flow verification
- Tests use UUID suffixes for isolation to prevent state leakage
Test Command:
conda run -n AniWorld python -m pytest tests/integration/test_identifier_consistency.py -v
Phase 8: Documentation and Cleanup ✅ Completed November 28, 2025
All tasks completed:
- Task 8.1: Updated
infrastructure.mdwith enhanced identifier convention section including table format, key format requirements, migration notes, and code examples - Task 8.2: Updated
docs/README.mdwith series identifier convention section, updateddocs/api_reference.mdwith key-based API examples - Task 8.3: Added deprecation warnings with Python's
warningsmodule to:SerieList.get_by_folder()insrc/core/entities/SerieList.py- Folder fallback lookup in
src/server/api/anime.py validate_series_key_or_folder()insrc/server/utils/validators.py
All deprecation warnings include removal timeline (v3.0.0) and guidance to use key instead.
Phase 9: Final Validation
Task 9.1: Run Full Test Suite
Objective: Verify all changes work together correctly.
Steps:
- Run complete test suite:
conda run -n AniWorld python -m pytest tests/ -v --tb=short - Fix any failing tests
- Verify test coverage is maintained
- Run integration tests
- Run manual UI tests
Success Criteria:
- All unit tests pass
- All integration tests pass
- All API tests pass
- Test coverage >= 80%
- Manual UI testing successful
Task 9.2: Manual End-to-End Testing
Objective: Manually verify all features work with the new identifier system.
Steps:
- Start server:
conda run -n AniWorld python -m uvicorn src.server.fastapi_app:app --host 127.0.0.1 --port 8000 --reload - Login to web interface
- Test search functionality (verify results show
key) - Test adding new series (verify uses
key) - Test downloading episodes (verify uses
key) - Test WebSocket events (verify events include
key) - Verify database contains correct
keyvalues - Test rescan functionality
Success Criteria:
- Search works correctly
- Adding series works
- Downloads work correctly
- WebSocket events work
- Database entries correct
- Rescan functionality works
Task 9.3: Performance and Load Testing
Objective: Ensure identifier changes don't impact performance.
Steps:
- Run performance tests on key operations:
- Series lookup by
key - Database queries using
key - API response times
- Series lookup by
- Compare with baseline if available
- Identify any performance regressions
- Optimize if needed
Success Criteria:
- No significant performance regression
- Lookup by
keyis fast - Database queries optimized
- API response times acceptable
Phase 10: Deployment
Task 10.1: Create Migration Script
Objective: Create script to migrate existing data if needed.
Steps:
- Create
scripts/migrate_identifiers.py - Script should:
- Check all series have valid
keyvalues - Update any references that incorrectly use
folder - Validate database integrity
- Create backup before migration
- Check all series have valid
- Add rollback capability
- Test migration on test data
Success Criteria:
- Migration script created
- Script validates data
- Backup functionality works
- Rollback capability tested
- Migration tested on test data
Task 10.2: Update Deployment Documentation
File: Update deployment section in instructions.md
Objective: Document deployment steps for identifier changes.
Steps:
- Add pre-deployment checklist
- Document migration steps
- Add rollback procedure
- Document verification steps
- Add troubleshooting guide
Success Criteria:
- Deployment steps documented
- Migration procedure clear
- Rollback procedure documented
- Verification steps listed
- Troubleshooting guide added
Task 10.3: Deploy to Production
Objective: Deploy changes to production environment.
Steps:
- Create deployment tag:
v2.0.0-identifier-standardization - Backup production database
- Run migration script
- Deploy new code
- Monitor logs for errors
- Verify production functionality
- Monitor for 24 hours
Success Criteria:
- Deployment tag created
- Database backed up
- Migration successful
- Code deployed
- No errors in logs
- All features working
- 24-hour monitoring completed
Task Tracking
Completion Status
- Phase 1: Core Models and Data Layer ✅
- Phase 2: Core Application Layer ✅
- Phase 3: Service Layer ✅
- Phase 4: API Layer ✅ Completed November 28, 2025
- Phase 5: Frontend ✅ Completed November 28, 2025
- Phase 6: Database Layer ✅ Completed November 28, 2025
- Phase 7: Testing and Validation ✅ Completed November 28, 2025
- Phase 8: Documentation and Cleanup ✅ Completed November 28, 2025
- Task 8.1: Update Infrastructure Documentation - Enhanced identifier convention section with table, format requirements, migration notes, and code examples
- Task 8.2: Update README and Developer Docs - Updated docs/README.md with identifier section, updated api_reference.md with key-based examples
- Task 8.3: Add Deprecation Warnings - Added warnings to SerieList.get_by_folder(), anime.py folder fallback, and validators.py
- Phase 9: Final Validation
- Phase 10: Deployment