# PeerSpeak Codebase Layout and Architecture Rules When working in the PeerSpeak repository, adhere to the following architectural boundaries and layout: ## Code Layout - `src/main.rs`: The application entry point (initializes Tokio and the Iced GUI). - `src/app/`: The UI layer (Iced). Handles themes, views (Home, Room, Settings), and visual state. Must communicate with the core via message passing (`UiEvent`/`CoreCommand`), not direct function calls. - `src/core/`: The central orchestrator. - `mod.rs`: Manages the session lifecycle, ties together network and UI, and manages the async mixer tasks. - `jitter.rs`: Houses the adaptive playout delay JitterBuffer and Packet Loss Concealment (PLC) logic. - `src/network/`: The "Dual-Plane" transport layer. - `gossip.rs` (Control Plane): Built on `iroh-gossip`. Manages room rosters, verified membership, presence, and chat via cryptographically signed envelopes. - `iroh_impl.rs` (Data Plane): Manages raw QUIC endpoints and peer connections. Forwards UDP voice datagrams directly to peers for minimum latency. - `src/audio/`: Hardware audio backends. - Interfaces heavily with `cpal_impl.rs` (Windows/WASAPI) and `pipewire_impl.rs` (Linux). - **CRITICAL RULE**: The RT audio callbacks are strictly lock-free. They communicate with the async core exclusively via Single-Producer Single-Consumer (SPSC) ring buffers (`HeapRb`). Never allocate memory, log to stdout, or lock Mutexes on the RT threads. - `src/codec/`: Audio compression abstractions, standardizing on Opus at 48kHz mono (`opus_impl.rs`). ## General Directives - **Security**: Audio admission is strictly derived from the verified gossip roster (S8). Never trust raw UDP sender IDs without validating against gossip. - **Latency**: Preserve the deterministic dialer vs acceptor logic in the QUIC layer to prevent connection loops.