# Refactoring Summary

## Changes Made

### 1. Created src/error.rs
Moved from lib.rs:
- `AppError` struct and all impl blocks
- `ApiErrorDetails` is already in types.rs
- `LocalizedErrorMessages` is already in types.rs  
- `db_error_status()` function
- `db_error_response()` function
- `error_response()` function
- All From impls for AppError (no longer needed - the types are already in types.rs)
- `fallback_for_status()` and `log()` methods

All types `pub(crate)`, functions `pub(crate)`.

### 2. Created src/config.rs
Moved from lib.rs:
- `Config` struct and its impl
- `load_config()` function
- `dirs_config_path()` helper
- `dirs_home()` helper

`Config` is `pub`, functions are `pub(crate)`.

### 3. Created src/resolve.rs
Moved from lib.rs:
- `resolve_project_id()` async function
- `resolve_edge_id()` function
- `resolve_node_id()` function
- `parse_uuid()` helper

All functions take `&Database` as parameter. All `pub(crate)`.

### 4. Updated src/types.rs
Added analysis types from db.rs (lines 744-822):
- `AttackPath`
- `PathNode`
- `TaggedNode`
- `NextStep`
- `CrossConnection`
- `HealthIssue`
- `CheckIssue`
- `CheckResult`
- `AttackAnalysis`

### 5. Updated src/db.rs
- Removed analysis types (moved to types.rs)
- Kept existing imports from `crate::types::*`

### 6. Updated src/lib.rs
- Added module declarations: `mod error; mod config; mod resolve;`
- Re-exported: `AppError`, `Config`, `load_config`
- Internal re-exports for routes: `db_error_status`, `db_error_response`, `error_response`
- Internal re-exports: `parse_uuid`, `resolve_project_id`, `resolve_edge_id`, `resolve_node_id`
- Kept `AppState`, `serve()`, `deepseek_chat()`, middleware, and router setup

### 7. Updated route files
- src/routes/analysis.rs: Updated imports from `crate::db::*` to `crate::types::*`
- src/routes/check.rs: Updated imports
- src/routes/report.rs: Updated imports

## Verification
✅ `cargo check` passes with only warnings

## Public API Preserved
The following remain accessible from `crate::*`:
- `AppError`
- `Config`
- `types::*` (all existing types)

The following are accessible from `crate::*` internally:
- `db_error_status`
- `db_error_response`
- `error_response`
- `load_config`
- `parse_uuid`
- `resolve_project_id`
- `resolve_edge_id`
- `resolve_node_id`
