2.1 KiB
2.1 KiB
Design Spec: Clean-Modular Architecture Refactor
Date: 2026-05-08
Topic: Refactor apps/rust from Hybrid to Clean-Modular Architecture.
1. Purpose
Standardize codebase structure for rigidity, maintainability, and clear separation of concerns (SOC) without violating the Zero-Bloat Policy.
2. Target Architecture
Moving from current structure to a three-tier modular design:
A. Presentation Layer (src/presentation/)
- API Handlers: Pure Axum handlers.
- DTOs: Request/Response models for external communication.
- Middleware: Cross-cutting concerns (CORS, Metrics, Logging).
B. Core Layer (src/core/) - The Domain
- Models: Pure data structures (Plain Rust Objects).
- Repository Traits: Abstract interfaces for data persistence.
- Use Cases: Orchestration of business logic (e.g.,
ScrapeAnime,ProcessImage). - Dependencies: None (or minimal shared utils).
C. Infrastructure Layer (src/infra/) - The Adapters
- Repositories: SeaORM & Redis implementations of Core traits.
- Scrapers: Site-specific parsing logic implementing Core scraping traits.
- External Clients: HTTP Client (reqwest), Browser Pool.
D. Shared Layer (src/shared/)
- Utils: Low-level helpers (Date, JSON, String).
- Config: Application configuration.
- Errors: Centralized error handling.
3. Implementation Strategy
- Phase 1: Scaffold new directory structure.
- Phase 2: Migrate
modelsandentitiestocore/modelsandinfra/repositories. - Phase 3: Refactor
scrapinglogic intoinfra/scrapersand define traits incore. - Phase 4: Move Axum handlers to
presentation/apiand update routing. - Phase 5: Cleanup
helpersintoshared/utils.
4. Constraints
- Zero-Bloat: No new heavy dependencies for the sake of abstraction.
- Performance: Maintain latency metrics as defined in
docs/development.md. - SeaORM: Entities stay in
infra/to keepcore/pure.
5. Success Criteria
- All tests pass.
/metricsshow no latency regression.- Circular dependencies are eliminated.
- Folder structure matches this spec.