# hkim807/p4p architecture

> Architecture diagram of the GitHub repository hkim807/p4p, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hkim807/p4p
- Repository: https://github.com/hkim807/p4p

## Overview

Navel collects robot perception and locomotion into raw observation frames, sends them to a receiver, and can derive tracked people, temporal social cues, policy proposals, target locks, and correlated commands. Offline replay supports inspecting recordings and derived state; optional model inference and physical actions extend the flow but are not required by the default collector. The README documents the principal stages; some implementation links below rely on its statements and the SOURCE INDEX rather than complete excerpts.

Main entry points: [`app/social_pipeline.py`](https://github.com/hkim807/p4p/blob/main/app/social_pipeline.py) (Social pipeline), [`robot/navel_client/main.py`](https://github.com/hkim807/p4p/blob/main/robot/navel_client/main.py) (Sensor collector), [`app/server.py`](https://github.com/hkim807/p4p/blob/main/app/server.py) (HTTP receiver), [`app/pipeline.py`](https://github.com/hkim807/p4p/blob/main/app/pipeline.py) (Tracking pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_collection["Robot collection"]
  node_collector["Sensor collector<br/>[main.py]"]
  node_adapter["SDK adapter<br/>[adapter.py]"]
  node_transport["HTTP transport<br/>[transport.py]"]
end

subgraph group_receiver["Receiver and records"]
  node_server["HTTP receiver<br/>[server.py]"]
  node_frame["Raw frame contract<br/>[models.py]"]
  node_recording[("JSONL recording<br/>[recording.py]")]
end

subgraph group_social["Social processing"]
  node_pipeline["Tracking pipeline<br/>[pipeline.py]"]
  node_tracks["UID track histories<br/>[tracks.py]"]
  node_estimator["Social estimator<br/>[estimator.py]"]
  node_features["Temporal features<br/>[features.py]"]
  node_socialstate["Social state<br/>[social_models.py]"]
  node_socialpipeline["Social pipeline<br/>[social_pipeline.py]"]
end

subgraph group_decisions["Policy and actions"]
  node_rules["Rule policy<br/>[rules.py]"]
  node_targetlock["Target lock<br/>[target_lock.py]"]
  node_commands["Command planner<br/>[commands.py]"]
  node_dispatch["Robot decision dispatch"]
end

subgraph group_extensions["Replay and models"]
  node_replay["Recording replay<br/>[__init__.py]"]
  node_llmpolicy["LLM policy<br/>[llm.py]"]
  node_ollama["Ollama client<br/>[ollama.py]"]
  node_decisioncontract["Decision contract<br/>[model_decision.py]"]
end

node_robot(("Navel robot"))

node_robot -->|"supplies packets"| node_collector
node_collector -->|"reads SDK"| node_adapter
node_collector -->|"sends frames"| node_transport
node_transport -->|"POSTs observations"| node_server
node_server -->|"validates"| node_frame
node_server -->|"records frames"| node_recording
node_server -->|"processes frames"| node_pipeline
node_pipeline -->|"writes raw frames"| node_recording
node_pipeline -->|"updates histories"| node_tracks
node_socialpipeline -->|"gets snapshots"| node_pipeline
node_socialpipeline -->|"estimates state"| node_estimator
node_estimator -->|"uses features"| node_features
node_estimator -->|"produces state"| node_socialstate
node_socialpipeline -->|"proposes decision"| node_rules
node_socialpipeline -->|"resolves lock"| node_targetlock
node_socialpipeline -.->|"plans commands"| node_commands
node_collector -->|"dispatches decisions"| node_dispatch
node_replay -->|"reads recordings"| node_recording
node_llmpolicy -->|"requests inference"| node_ollama
node_llmpolicy -.->|"validates output"| node_decisioncontract
node_ollama -->|"parses decisions"| node_decisioncontract

click node_collector "https://github.com/hkim807/p4p/blob/main/robot/navel_client/main.py"
click node_adapter "https://github.com/hkim807/p4p/blob/main/robot/navel_client/adapter.py"
click node_transport "https://github.com/hkim807/p4p/blob/main/robot/navel_client/transport.py"
click node_server "https://github.com/hkim807/p4p/blob/main/app/server.py"
click node_frame "https://github.com/hkim807/p4p/blob/main/app/domain/models.py"
click node_recording "https://github.com/hkim807/p4p/blob/main/app/recording.py"
click node_pipeline "https://github.com/hkim807/p4p/blob/main/app/pipeline.py"
click node_tracks "https://github.com/hkim807/p4p/blob/main/app/state/tracks.py"
click node_estimator "https://github.com/hkim807/p4p/blob/main/app/state/estimator.py"
click node_features "https://github.com/hkim807/p4p/blob/main/app/state/features.py"
click node_socialstate "https://github.com/hkim807/p4p/blob/main/app/state/social_models.py"
click node_socialpipeline "https://github.com/hkim807/p4p/blob/main/app/social_pipeline.py"
click node_rules "https://github.com/hkim807/p4p/blob/main/app/policy/rules.py"
click node_targetlock "https://github.com/hkim807/p4p/blob/main/app/policy/target_lock.py"
click node_commands "https://github.com/hkim807/p4p/blob/main/app/commands.py"
click node_dispatch "https://github.com/hkim807/p4p/blob/main/robot/navel_client/decision_dispatch.py"
click node_replay "https://github.com/hkim807/p4p/blob/main/app/replay/__init__.py"
click node_llmpolicy "https://github.com/hkim807/p4p/blob/main/app/policy/llm.py"
click node_ollama "https://github.com/hkim807/p4p/blob/main/app/inference/ollama.py"
click node_decisioncontract "https://github.com/hkim807/p4p/blob/main/app/domain/model_decision.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_collector,node_adapter,node_transport toneBlue
class node_server,node_frame,node_recording toneAmber
class node_pipeline,node_tracks,node_estimator,node_features,node_socialstate,node_socialpipeline toneMint
class node_rules,node_targetlock,node_commands,node_dispatch toneRose
class node_replay,node_llmpolicy,node_ollama,node_decisioncontract,node_robot toneIndigo
```

## Components

### Robot collection

- [Sensor collector](https://github.com/hkim807/p4p/blob/main/robot/navel_client/main.py): `robot/navel_client/main.py`
- [SDK adapter](https://github.com/hkim807/p4p/blob/main/robot/navel_client/adapter.py): `robot/navel_client/adapter.py`
- [HTTP transport](https://github.com/hkim807/p4p/blob/main/robot/navel_client/transport.py): `robot/navel_client/transport.py`

### Receiver and records

- [HTTP receiver](https://github.com/hkim807/p4p/blob/main/app/server.py): `app/server.py`
- [Raw frame contract](https://github.com/hkim807/p4p/blob/main/app/domain/models.py): `app/domain/models.py`
- [JSONL recording](https://github.com/hkim807/p4p/blob/main/app/recording.py): `app/recording.py`

### Social processing

- [Tracking pipeline](https://github.com/hkim807/p4p/blob/main/app/pipeline.py): `app/pipeline.py`
- [UID track histories](https://github.com/hkim807/p4p/blob/main/app/state/tracks.py): `app/state/tracks.py`
- [Social estimator](https://github.com/hkim807/p4p/blob/main/app/state/estimator.py): `app/state/estimator.py`
- [Temporal features](https://github.com/hkim807/p4p/blob/main/app/state/features.py): `app/state/features.py`
- [Social state](https://github.com/hkim807/p4p/blob/main/app/state/social_models.py): `app/state/social_models.py`
- [Social pipeline](https://github.com/hkim807/p4p/blob/main/app/social_pipeline.py): `app/social_pipeline.py`

### Policy and actions

- [Rule policy](https://github.com/hkim807/p4p/blob/main/app/policy/rules.py): `app/policy/rules.py`
- [Target lock](https://github.com/hkim807/p4p/blob/main/app/policy/target_lock.py): `app/policy/target_lock.py`
- [Command planner](https://github.com/hkim807/p4p/blob/main/app/commands.py): `app/commands.py`
- [Robot decision dispatch](https://github.com/hkim807/p4p/blob/main/robot/navel_client/decision_dispatch.py): `robot/navel_client/decision_dispatch.py`

### Replay and models

- [Recording replay](https://github.com/hkim807/p4p/blob/main/app/replay/__init__.py): `app/replay/__init__.py`
- [LLM policy](https://github.com/hkim807/p4p/blob/main/app/policy/llm.py): `app/policy/llm.py`
- [Ollama client](https://github.com/hkim807/p4p/blob/main/app/inference/ollama.py): `app/inference/ollama.py`
- [Decision contract](https://github.com/hkim807/p4p/blob/main/app/domain/model_decision.py): `app/domain/model_decision.py`

### Other components

- **Navel robot**

## Connections

- Navel robot → Sensor collector: supplies packets (evidence: `README.md`)
- Sensor collector → SDK adapter: reads SDK (evidence: `robot/navel_client/main.py`)
- Sensor collector → HTTP transport: sends frames (evidence: `README.md`)
- HTTP transport → HTTP receiver: POSTs observations (evidence: `README.md`)
- HTTP receiver → Raw frame contract: validates (evidence: `app/server.py`)
- HTTP receiver → JSONL recording: records frames (evidence: `app/server.py`)
- HTTP receiver → Tracking pipeline: processes frames (evidence: `app/server.py`)
- Tracking pipeline → JSONL recording: writes raw frames (evidence: `app/pipeline.py`)
- Tracking pipeline → UID track histories: updates histories (evidence: `app/pipeline.py`)
- Social pipeline → Tracking pipeline: gets snapshots (evidence: `app/social_pipeline.py`)
- Social pipeline → Social estimator: estimates state (evidence: `app/social_pipeline.py`)
- Social estimator → Temporal features: uses features (evidence: `app/state/estimator.py`)
- Social estimator → Social state: produces state (evidence: `app/state/estimator.py`)
- Social pipeline → Rule policy: proposes decision (evidence: `app/social_pipeline.py`)
- Social pipeline → Target lock: resolves lock (evidence: `app/social_pipeline.py`)
- Social pipeline → Command planner: plans commands (evidence: `app/social_pipeline.py`)
- Sensor collector → Robot decision dispatch: dispatches decisions (evidence: `robot/navel_client/main.py`)
- Recording replay → JSONL recording: reads recordings (evidence: `README.md`)
- LLM policy → Ollama client: requests inference (evidence: `app/policy/llm.py`)
- LLM policy → Decision contract: validates output
- Ollama client → Decision contract: parses decisions (evidence: `app/inference/ollama.py`)
