# Phase 5 Architectural Audit: Intensive Pipeline Mapping

This document provides a tool-assisted, intensive technical trace of the major processing routes within Manual Slop. It identifies exact function call chains, data transformations, and subsystem boundaries.

---

## 1. AI Interaction Pipeline
**Primary Route:** Traces the flow from a user send request to final execution.

### Call Graph (Depth 3)
```text
-> ai_client.send (src\ai_client.py)
  -> _append_comms (src\ai_client.py)
  -> _get_combined_system_prompt (src\ai_client.py)
    -> generate_tooling_strategy (src\tool_bias.py)
  -> _send_anthropic (src\ai_client.py)
    -> _build_chunked_context_blocks (src\ai_client.py)
    -> _execute_tool_calls_concurrently (src\ai_client.py)
    -> run (src\aggregate.py)
  -> _send_gemini (src\ai_client.py)
    -> _gemini_tool_declaration (src\ai_client.py)
      -> get_tool_schemas (src\mcp_client.py)
```

---

## 2. Context Aggregation Pipeline
**Primary Route:** Traces the transformation of project files into AI-ready context.

### Call Graph (Depth 3)
```text
-> aggregate.run (src\aggregate.py)
  -> build_file_items (src\aggregate.py)
    -> get_monitor (src\performance_monitor.py)
    -> resolve_paths (src\aggregate.py)
  -> build_markdown_from_items (src\aggregate.py)
    -> _build_files_section_from_items (src\aggregate.py)
    -> build_beads_section (src\aggregate.py)
    -> build_discussion_section (src\aggregate.py)
    -> build_summary_markdown (src\summarize.py)
  -> find_next_increment (src\aggregate.py)
```

---

## 3. GUI Event & State Synchronization
**Primary Route:** Traces the background event loop and state management.

### Call Graph (Depth 3)
```text
-> app_controller._process_event_queue (src\app_controller.py)
  -> refresh_external_mcps (src\app_controller.py)
    -> add_server (src\mcp_client.py)
    -> stop_all (src\mcp_client.py)
  -> run (src\aggregate.py)
    -> build_file_items (src\aggregate.py)
    -> build_markdown_from_items (src\aggregate.py)
```

---

## 4. Simulation Lifecycle Pipeline
**Primary Route:** Traces the automated verification and scaffolding flow.

### Call Graph (Depth 3)
```text
-> simulation.sim_base.run_sim (simulation\sim_base.py)
  -> run (src\aggregate.py)
    -> build_file_items (src\aggregate.py)
    -> build_markdown_from_items (src\aggregate.py)
  -> teardown (simulation\sim_base.py)
```

---

## 5. Performance & Curation Insights

### 5.1 Redundancy Hotspots
- **Aggregation Boilerplate:** Both `AppController` and `run_sim` call `aggregate.run` directly, but `ai_client` also triggers it during context refreshes. This indicates a potential for a shared, reactive context manager.
- **Provider Divergence:** The call graph for `_send_anthropic` is significantly more complex than `_send_gemini`, suggesting inconsistent abstraction for context chunking and history management.

### 5.2 Threading Boundaries
- **Context Switches:** The audit confirms that `_process_event_queue` acts as the primary synchronization gate, transitioning foreground UI requests into background worker tasks.
- **Lock Contention:** Heavy reliance on `threading.Lock` within `mcp_client` (implied by `configure` calls) and `app_controller` suggests areas where lock-free data structures could improve frame latency.

### 5.3 Automated Tooling Success
- The `derive_code_path` tool successfully navigated cross-subsystem boundaries (e.g., from `simulation` back into `src.aggregate`).
- Future curation should prioritize tools over manual reviews to maintain the Acton/Muratori standards of technical discipline.
