Summary
The Crusades codebase requires a comprehensive refactor to improve maintainability, type safety, and architectural clarity. This issue tracks structural improvements following Python best practices and SOLID principles.
Scope
1. Type Safety
- Add comprehensive type hints to all public functions and classes
- Replace
Any and bare dict/list with concrete generics (dict[str, Any], list[int])
- Add
py.typed marker for PEP 561 compliance
- Integrate
mypy --strict into CI pipeline
2. Python Idioms
- Replace manual loop index tracking with
enumerate() where appropriate
- Use context managers (
with statements) for resource cleanup
- Adopt pathlib over os.path for path operations
- Use dataclasses for simple data containers
- Replace manual
__init__ assignments with @dataclass or attrs
3. SOLID Principles
Single Responsibility
- Split
validator.py into coherent modules: blockchain interface, evaluation orchestrator, scoring logic, weight setting
- Separate Docker/Basilica execution strategies into distinct executor classes
- Extract security scanning into dedicated scanner module
Open/Closed
- Define abstract base classes for evaluation backends (
AbstractExecutor)
- Use strategy pattern for MFU calculation methods
- Plugin architecture for verification checks
Liskov Substitution
- Ensure all executor implementations (Docker, Basilica, Local) are interchangeable
- Standardize result dataclasses across execution modes
Interface Segregation
- Split monolithic config objects into role-specific interfaces
- Separate miner-facing vs validator-facing APIs
Dependency Inversion
- Inject dependencies (database, blockchain client) rather than instantiating internally
- Use factories for creating execution contexts
4. DRY (Don't Repeat Yourself)
- Extract common validation logic between
env.py and simulate_validator.py
- Centralize security policy definitions (single source of truth already started in
security_defs.py)
- Unify MFU calculation formulas across validator and miner tooling
- Share constants between production and test environments
5. Separation of Concerns
- Domain layer: MFU calculation, scoring algorithms, verification logic
- Infrastructure layer: Docker API, Basilica client, database access, blockchain interface
- Application layer: Orchestration, commit processing, leaderboard management
- Presentation layer: TUI dashboard, logging formats
Specific Targets
Immediate
Structural
Out of Scope
- Unit testing infrastructure (tracked in separate issue)
- Feature additions or algorithm changes
- Security policy modifications
Acceptance Criteria
Notes
This refactor should not change behavior—only structure. All existing tests (once added separately) must continue to pass.
Summary
The Crusades codebase requires a comprehensive refactor to improve maintainability, type safety, and architectural clarity. This issue tracks structural improvements following Python best practices and SOLID principles.
Scope
1. Type Safety
Anyand baredict/listwith concrete generics (dict[str, Any],list[int])py.typedmarker for PEP 561 compliancemypy --strictinto CI pipeline2. Python Idioms
enumerate()where appropriatewithstatements) for resource cleanup__init__assignments with@dataclassorattrs3. SOLID Principles
Single Responsibility
validator.pyinto coherent modules: blockchain interface, evaluation orchestrator, scoring logic, weight settingOpen/Closed
AbstractExecutor)Liskov Substitution
Interface Segregation
Dependency Inversion
4. DRY (Don't Repeat Yourself)
env.pyandsimulate_validator.pysecurity_defs.py)5. Separation of Concerns
Specific Targets
Immediate
neurons/validator.py(currently too large)executors/modulemodels/directory for dataclasses (Submission, Evaluation, Score)Structural
Out of Scope
Acceptance Criteria
mypy --strictpasses with zero errorsNotes
This refactor should not change behavior—only structure. All existing tests (once added separately) must continue to pass.