Refactor: extract lib.rs into focused sub-modules, add --output-dir CLI option

- Split monolithic src/lib.rs (~640 lines) into 7 sub-modules:
  types.rs, context.rs, user_data.rs, translate.rs, http.rs,
  csv_util.rs, test_utils.rs
- Add configurable --output-dir CLI option for CSV output files
- Implement atomic file writes (write-to-temp + rename) for all CSVs
- Change compute_car_counts() to return CarCounts directly (not Result)
- Add test-utils feature gate for shared test helpers
- Add HTTP mock tests with mockito (6 tests)
- Add proptest tests for compute_car_counts (3 property tests)
- Update integration tests to use shared test utilities
- Update documentation (API.md, ARCHITECTURE.md, DATA_STRUCTURES.md)
This commit is contained in:
Jan-Peter von Hunnius 2026-05-08 20:21:46 +02:00
parent d2c1418e5e
commit 67a79f190a
27 changed files with 1648 additions and 789 deletions

View file

@ -8,7 +8,14 @@ This document provides comprehensive API documentation for the Top Drives Record
```
src/
├── lib.rs # Shared library: types, utilities, error handling
├── lib.rs # Thin re-export module: declares sub-modules, re-exports public types
├── types.rs # Core types: AppError, Car, BestCarRecord, TripletKey
├── context.rs # Analysis state: AnalysisContext, CarCounts, compute_car_counts
├── user_data.rs # User data: MyCarsData, load_my_cars_data
├── translate.rs # Translation: translate_track_name, translate_track_type
├── http.rs # HTTP: get_file (async download with retry)
├── csv_util.rs # CSV utilities: compare_cars, escape_csv_field
├── test_utils.rs # Test helpers: make_record, make_car
├── records.rs # Binary entry point: CLI definition and dispatch
├── commands/
│ ├── mod.rs # Command dispatch, run_analysis(), load_my_cars_or_warn()
@ -30,7 +37,7 @@ src/
## Shared Library (`src/lib.rs`)
Common types and utilities shared across the project.
Thin re-export module that declares 6 focused sub-modules and re-exports all public types for backward compatibility. External code can use `top_drives::Car` without knowing the internal module layout.
### Public Types
@ -176,7 +183,7 @@ pub enum AppError {
- Sorts by: RQ → Brand → Model name
#### `compute_car_counts(ctx: &AnalysisContext, car_list: Vec<Car>) -> Result<CarCounts, AppError>`
#### `compute_car_counts(ctx: &AnalysisContext, car_list: Vec<Car>) -> CarCounts`
**Aggregates per-car win counts from analysis context**
- Iterates all entries in the `DashMap`