- Updated DownloadRequest and DownloadItem models with comprehensive docstrings explaining serie_id (key as primary identifier) vs serie_folder (filesystem metadata) - Updated add_to_queue() endpoint docstring to document request parameters - Updated all test files to include required serie_folder field: - tests/api/test_download_endpoints.py - tests/api/test_queue_features.py - tests/frontend/test_existing_ui_integration.py - tests/integration/test_download_flow.py - Updated infrastructure.md with Download Queue request/response models - All 869 tests pass This is part of the Series Identifier Standardization effort (Phase 4.2) to ensure key is used as the primary identifier throughout the codebase.
27 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
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
Deployment Steps:
- Commit all changes to git repository
- Create deployment tag (e.g.,
v1.0.0-queue-simplified) - Deploy to production environment
- Monitor logs for any unexpected behavior
- Verify production queue functionality
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
- No database schema changes required
- WebSocket infrastructure remains unchanged
🎯 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 1: Core Models and Data Layer
✅ All Phase 1 tasks completed and committed to git
Phase 2: Core Application Layer
✅ Task 2.1 completed and committed to git
Phase 3: Service Layer
✅ All Phase 3 tasks completed and committed to git (November 2025)
- Task 3.1: Update DownloadService ✅
- Task 3.2: Update AnimeService ✅
- Task 3.3: Update ProgressService ✅
- Task 3.4: Update ScanService ✅ (November 27, 2025)
Phase 4: API Layer
Task 4.1: Update Anime API Endpoints to Use Key ✅
Completed: November 27, 2025
Updated src/server/api/anime.py to standardize all endpoints to use key as the primary series identifier:
- Updated
AnimeSummarymodel with proper documentation (key as primary identifier) - Updated
AnimeDetailmodel withkeyfield (replacedidfield) - Updated
get_anime()endpoint with key-first lookup and folder fallback - Updated
add_series()endpoint to extract key from link URL - Updated
_perform_search()to use key as identifier - All docstrings updated to clarify identifier usage
- All anime API tests pass (11/11)
Task 4.2: Update Download API Endpoints to Use Key ✅
Completed: November 27, 2025
Updated src/server/api/download.py and src/server/models/download.py to standardize identifier documentation:
- Updated
DownloadRequestmodel with comprehensive docstrings explainingserie_id(key as primary identifier) vsserie_folder(filesystem metadata) - Updated
DownloadItemmodel with same clarification - Updated
add_to_queue()endpoint docstring to document request parameters - Updated all test files to include required
serie_folderfield - All download API tests pass (23/23)
- All integration tests pass (869/869)
Task 4.3: Update Queue API Endpoints to Use Key
File: src/server/api/queue.py
Objective: Ensure queue API endpoints use key for series identification.
Steps:
- Open
src/server/api/queue.py - Review all queue-related endpoints
- Update request/response models to use
keyas identifier - Ensure queue status includes
keyin item data - Update queue manipulation endpoints to accept
key - Update docstrings and OpenAPI documentation
Success Criteria:
- All queue endpoints use
key - Queue status responses include
key - Request models use
keyfor identification - All queue API tests pass
Test Command:
conda run -n AniWorld python -m pytest tests/api/ -k "queue" -v
Task 4.4: Update WebSocket API Endpoints to Use Key
File: src/server/api/websocket.py
Objective: Ensure WebSocket API endpoint handlers use key for series identification.
Steps:
- Open
src/server/api/websocket.py - Review all WebSocket message handlers
- Ensure messages use
keyfor series identification - Update message schemas to include
keyfield - Keep
folderfor display purposes - Update docstrings
Success Criteria:
- All WebSocket handlers use
key - Message schemas include
key - All WebSocket API tests pass
Test Command:
conda run -n AniWorld python -m pytest tests/api/ -k "websocket" -v
Task 4.5: Update Pydantic Models to Use Key
Files:
src/server/models/anime.pysrc/server/models/download.py
Objective: Ensure all Pydantic models use key as the series identifier.
Steps:
- Open
src/server/models/anime.py - Review all models (e.g.,
AnimeDetail,AnimeSummary,SearchResult) - Ensure
keyis the primary identifier field - Add
folderas optional metadata field - Update field validators to validate
keyformat - Repeat for
src/server/models/download.py - Update
DownloadRequestand related models - Update all docstrings and field descriptions
Success Criteria:
- All anime models use
keyas identifier - All download models use
keyas identifier - Field validators ensure
keyformat is correct folderis optional metadata- All model tests pass
Test Command:
conda run -n AniWorld python -m pytest tests/unit/ -k "models" -v
Task 4.6: Update Validators to Use Key
File: src/server/utils/validators.py
Objective: Ensure validation functions validate key instead of folder.
Steps:
- Open
src/server/utils/validators.py - Review all validation functions
- Add
validate_series_key()function if not exists - Update any validators that check series identifiers
- Ensure validators accept
keyformat (URL-safe, lowercase with hyphens) - Add tests for key validation
Success Criteria:
- Validators validate
keyformat - No validators use
folderfor identification - Validation functions well-documented
- All validator tests pass
Test Command:
conda run -n AniWorld python -m pytest tests/unit/ -k "validator" -v
Task 4.7: Update Template Helpers to Use Key
File: src/server/utils/template_helpers.py
Objective: Ensure template helpers pass key to templates for series identification.
Steps:
- Open
src/server/utils/template_helpers.py - Review all helper functions
- Ensure functions that handle series data use
key - Update any filtering or sorting to use
key - Ensure
folderis available for display purposes - Update docstrings
Success Criteria:
- All helpers use
keyfor identification folderavailable for display- No breaking changes to template interface
- All template helper tests pass
Test Command:
conda run -n AniWorld python -m pytest tests/unit/ -k "template" -v
Phase 5: Frontend
Task 5.1: Update Frontend JavaScript to Use Key
File: src/server/web/static/js/app.js
Objective: Update frontend to use key as the primary series identifier instead of folder.
Steps:
- Open
src/server/web/static/js/app.js - Update
seriesDatastorage to index bykey - Update
selectedSeriesSet to usekeyinstead offolder - Update
createSerieCard():- Use
data-keyattribute instead ofdata-folder - Display
folderas metadata only
- Use
- Update
toggleSerieSelection()to usekey - Update
downloadSelected():- Send
keyasserie_id - Include
folderfor filesystem operations
- Send
- Update all event handlers and lookups to use
key - Keep
foldervisible in UI for user reference
Success Criteria:
- Frontend uses
keyfor all series operations folderdisplayed in UI but not used for identification- Selection tracking uses
key - All frontend interactions work correctly
Manual Test:
- Start server
- Login to web interface
- Verify series list displays correctly
- Test selecting series (should use key internally)
- Test downloading episodes
- Verify search functionality
Task 5.2: Update WebSocket Events to Use Key
File: src/server/services/websocket_service.py
Objective: Ensure WebSocket events use key for series identification.
Steps:
- Open
src/server/services/websocket_service.py - Update
broadcast_download_progress():- Include
keyin event data - Keep
folderfor display purposes
- Include
- Update
broadcast_scan_progress()similarly - Update all event broadcasts to include
key - Update event handler subscriptions to use
key
Success Criteria:
- All WebSocket events include
key - Events also include
folderfor display - All WebSocket tests pass
Test Command:
conda run -n AniWorld python -m pytest tests/unit/test_websocket_service.py -v
Task 5.3: Update Additional Frontend JavaScript Files
Files:
src/server/web/static/js/websocket.jssrc/server/web/static/js/queue.jssrc/server/web/static/js/download.jssrc/server/web/static/js/utils.js
Objective: Ensure all frontend JavaScript modules use key for series identification.
Steps:
-
Update
websocket.js:- Open
src/server/web/static/js/websocket.js - Review all message handlers
- Ensure event payloads use
keyfor identification - Update event listeners to use
key - Keep
folderfor display
- Open
-
Update
queue.js:- Open
src/server/web/static/js/queue.js - Update queue item identification to use
key - Update queue manipulation functions
- Ensure queue display shows both
keyandfolder
- Open
-
Update
download.js:- Open
src/server/web/static/js/download.js - Update download request building to use
key - Update progress tracking to use
key - Keep
folderfor file path operations
- Open
-
Update
utils.js:- Open
src/server/web/static/js/utils.js - Review utility functions that handle series data
- Ensure utilities use
keyfor identification - Update any series-related helper functions
- Open
Success Criteria:
- All JavaScript modules use
keyfor identification - WebSocket handlers use
key - Queue operations use
key - Download operations use
key - Utilities handle
keycorrectly folderdisplayed in UI where appropriate- All frontend functionality works correctly
Manual Test:
- Test WebSocket connectivity and events
- Test queue management
- Test download functionality
- Verify all series operations use
key
Task 5.4: Update HTML Templates to Use Key
Files: All templates in src/server/web/templates/
Objective: Ensure all HTML templates use key for series identification in data attributes and forms.
Steps:
-
Review all template files:
index.htmlanime_detail.htmlsearch.html- Any other templates using series data
-
For each template:
- Update data attributes to use
data-keyinstead ofdata-folder - Keep
data-folderfor display purposes if needed - Update form inputs to submit
keyas identifier - Update JavaScript references to use
key - Display
folderfor user-friendly names
- Update data attributes to use
-
Update template variables:
- Ensure templates receive
keyfrom backend - Verify
folderis available for display - Update any template logic that filters/sorts by series
- Ensure templates receive
Success Criteria:
- All templates use
data-keyfor identification - Forms submit
keyas identifier folderdisplayed for user reference- No templates use
folderfor identification - All template rendering works correctly
Manual Test:
- Verify all pages render correctly
- Test form submissions
- Verify JavaScript interactions
- Check data attributes in browser dev tools
Phase 6: Database Layer
Task 6.1: Verify Database Models Use Key Correctly
File: src/server/database/models.py
Objective: Verify and document that database models correctly use key as unique identifier.
Steps:
- Open
src/server/database/models.py - Verify
AnimeSeries.keyis unique and indexed - Verify
AnimeSeries.folderis not used for lookups - Update docstrings to clarify identifier usage
- Ensure all relationships use
id(primary key) notkeyorfolder
Success Criteria:
keyis unique and indexedfolderis metadata only- Docstrings are clear
- All database model tests pass
Test Command:
conda run -n AniWorld python -m pytest tests/unit/test_database_models.py -v
Task 6.2: Update Database Services to Use Key
File: src/server/database/service.py
Objective: Ensure all database service methods use key for series lookup.
Steps:
- Open
src/server/database/service.py - Verify
AnimeSeriesService.get_by_key()is used for lookups - Verify no methods use
folderfor identification - Update any methods that incorrectly use
folderfor lookups - Add migration helper if needed to update existing data
Success Criteria:
- All service methods use
keyfor lookups foldernever used as identifier- All database service tests pass
Test Command:
conda run -n AniWorld python -m pytest tests/unit/test_database_service.py -v
Phase 7: Testing and Validation
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
Test Command:
conda run -n AniWorld python -m pytest tests/ -v
Task 7.2: Add Integration Tests for Identifier Consistency
File: Create new file 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
Test Command:
conda run -n AniWorld python -m pytest tests/integration/test_identifier_consistency.py -v
Phase 8: Documentation and Cleanup
Task 8.1: Update Infrastructure Documentation
File: infrastructure.md
Objective: Document the identifier standardization in infrastructure documentation.
Steps:
- Open
infrastructure.md - Add section explaining identifier usage:
key: Unique series identifier (provider-assigned)folder: Filesystem folder name (metadata only)id: Database primary key (internal use)
- Update all API documentation to show
keyas identifier - Update data model documentation
- Add migration notes if needed
Success Criteria:
- Documentation clearly explains identifier usage
- All API examples use
key - Data model section updated
- Migration notes added if applicable
Task 8.2: Update README and Developer Documentation
Objective: Update all developer-facing documentation.
Steps:
- Update main README to explain identifier usage
- Update any developer guides to use
key - Add note about backward compatibility with
folder - Update code examples to use
key
Success Criteria:
- README updated
- Developer guides updated
- Code examples use
key - Backward compatibility documented
Task 8.3: Add Deprecation Warnings for Folder-Based Lookups
Files: Various service and API files
Objective: Add deprecation warnings where folder is still accepted for backward compatibility.
Steps:
- Identify all methods that accept
folderfor lookups - Add deprecation warnings using Python's
warningsmodule - Update docstrings to indicate deprecation
- Plan removal timeline (e.g., next major version)
Success Criteria:
- Deprecation warnings added
- Docstrings indicate deprecation
- Removal timeline documented
- Tests updated to suppress warnings
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
- Task 4.1: Update Anime API Endpoints ✅ Completed November 27, 2025
- Task 4.2: Update Download API Endpoints ✅ Completed November 27, 2025
- Task 4.3: Update Queue API Endpoints
- Task 4.4: Update WebSocket API Endpoints
- Task 4.5: Update Pydantic Models
- Task 4.6: Update Validators
- Task 4.7: Update Template Helpers
- Phase 5: Frontend
- Task 5.1: Update Frontend JavaScript
- Task 5.2: Update WebSocket Events
- Task 5.3: Update Additional Frontend JavaScript Files
- Task 5.4: Update HTML Templates
- Phase 6: Database Layer
- Task 6.1: Verify Database Models
- Task 6.2: Update Database Services
- Phase 7: Testing and Validation
- Task 7.1: Update Test Fixtures
- Task 7.2: Add Integration Tests
- Phase 8: Documentation and Cleanup
- Task 8.1: Update Infrastructure Documentation
- Task 8.2: Update README
- Task 8.3: Add Deprecation Warnings
- Phase 9: Final Validation