# alexprinse/project_o architecture

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

- Interactive diagram: https://gitdiagram.com/alexprinse/project_o
- Repository: https://github.com/alexprinse/project_o

## Overview

1. **Overall shape**
   This repo is a layered robotics mission pipeline. The top-level Python app accepts a natural-language command, turns it into a structured mission, validates it against safety rules, and then dispatches it to either ROS 2 robot control, a multi-robot coordination layer, or a mock/offline backend.

2. **Entry points and modes**
   `main.py` is the primary runtime entrypoint. It selects the robot profile, reads the prompt, and switches between `--ros` execution and `--mock-llm` offline mode. `Dockerfile`, `docker-compose.yml`, and `setup_simulation.sh` support two deployment paths: native ROS/Gazebo on the host or a fully containerized simulator stack.

3. **Natural-language to mission translation**
   The `llm/` package is the parsing boundary. `llm/client.py` wraps the Gemini API, while `llm/prompts.py` builds a dynamic system prompt from configuration and waypoint catalogs. The important input data comes from `config/waypoints_*.yaml` and `config/settings.yaml`, which let the model resolve named places like patrol routes or waypoint labels into mission fields.

4. **Validation as a hard gate**
   `validator/schema.py` defines the mission contract, and `validator/validator.py` enforces it before any robot action occurs. This is the repository’s safety boundary: malformed JSON, out-of-range coordinates, invalid loop counts, or unsupported mission shapes are rejected before execution.

5. **Deterministic execution layer**
   `executor/executor.py` converts validated missions into concrete robot actions. It is the orchestration boundary that decides whether a mission is a simple navigation task, a multi-robot task, or a vision-follow task, and then routes control to the right subsystem.

6. **Robot abstraction and backends**
   The `robot/` package hides the physical/simulated backend behind controller implementations in `base.py`, `ros2_controller.py`, `mock_controller.py`, and the legacy `ebot_controller.py`. This makes the mission engine independent from the underlying robot stack while still supporting both TurtleBot3/Nav2 and the older e-Yantra ebot path.

7. **Multi-robot coordination subsystem**
   The `robot/formation/` modules implement squad behavior: `squad_commander.py` routes the mission, `manager.py` manages formation state and live re-planning, `tasks.py` handles route splitting and regroup logic, and `formations.py` defines formation geometry. This layer is only activated when the parsed mission targets multiple robots, so it sits between mission execution and individual robot navigation.

8. **Navigation and SLAM boundary**
   For TurtleBot3, the ROS 2 stack is built around Nav2 and SLAM Toolbox. `config/nav2_params.yaml` tunes navigation behavior, `config/launch/multi_slam_launch.py` starts namespaced SLAM instances for multi-robot operation, and the warehouse map/world files in `config/maps/` and `config/worlds/` define the static simulation environment. The robot controller adapts its behavior depending on whether AMCL or SLAM Toolbox is active.

9. **Vision-based follow subsystem**
   Target detection and pursuit live inside `robot/ros2_controller.py`. It uses YOLOv8 for object detection, converts ROS camera images directly into OpenCV frames, publishes annotated output for RViz, and controls motion based on target position and size. `scripts/swap_object.py` is the companion tool used to spawn or swap Gazebo objects for testing.

10. **Simulation assets and ROS workspace layout**
   The `eyrc_ws/src/` tree contains the simulation-specific ROS packages and assets: `ur_description`, `ur_simulation_gz`, `ebot_description`, `eyantra_warehouse`, `linkattacher_msgs`, and `ur5_control`. These packages provide robot descriptions, launch files, Gazebo models, custom services, and legacy task scaffolding. They are support infrastructure around the mission pipeline rather than the pipeline itself.

11. **Legacy ebot versus TurtleBot3 boundary**
   The repo supports two distinct robot ecosystems, but they are intentionally separated. TurtleBot3 is the primary architecture for Nav2, SLAM, and vision tasks; ebot is retained only for the core single-robot task and uses a different simulation and control model. The README explicitly treats them as non-coexistable stacks.

12. **End-to-end data flow**
   The main flow is: user prompt → LLM prompt construction → structured mission JSON → Pydantic validation → mission executor → robot controller → Nav2/Gazebo or vision loop. The key architectural feature is that language understanding is decoupled from actuation by a validation gate, so no robot-side action can happen without passing through the schema and safety constraints first.

Main entry points: [`robot/ros2_controller.py`](https://github.com/alexprinse/project_o/blob/main/robot/ros2_controller.py) (ROS 2 controller), [`executor/executor.py`](https://github.com/alexprinse/project_o/blob/main/executor/executor.py) (Executor), [`main.py`](https://github.com/alexprinse/project_o/blob/main/main.py) (main.py), [`robot/base.py`](https://github.com/alexprinse/project_o/blob/main/robot/base.py) (Base controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Mission app"]
  node_main["main.py<br/>entrypoint<br/>[main.py]"]
  node_llm_client["LLM client<br/>api wrapper<br/>[client.py]"]
  node_llm_prompts["Prompt builder<br/>prompt assembly<br/>[prompts.py]"]
  node_schema["Mission schema<br/>contract<br/>[schema.py]"]
  node_mission_validator["Validator<br/>safety gate<br/>[validator.py]"]
  node_executor["Executor<br/>orchestrator<br/>[executor.py]"]
end

subgraph group_robot["Robot backends"]
  node_base_controller["Base controller<br/>backend abstraction<br/>[base.py]"]
  node_ros2_controller["ROS 2 controller<br/>nav2 + vision<br/>[ros2_controller.py]"]
  node_mock_controller["Mock controller<br/>offline backend<br/>[mock_controller.py]"]
  node_ebot_controller["ebot controller<br/>legacy backend<br/>[ebot_controller.py]"]
end

subgraph group_formation["Coordination"]
  node_squad_commander["Squad commander<br/>multi-robot router<br/>[squad_commander.py]"]
  node_formation_manager["Formation manager<br/>state + replanning<br/>[manager.py]"]
  node_formation_tasks["Formation tasks<br/>route splitting<br/>[tasks.py]"]
  node_formations["Formations<br/>geometry rules<br/>[formations.py]"]
end

subgraph group_rosws["ROS workspace"]
  node_eyrc_warehouse["Eyantra warehouse<br/>ros package"]
  node_ur_description["UR description<br/>ros package"]
  node_ur_simulation_gz["UR sim gz<br/>ros package"]
  node_link_msgs["Link msgs<br/>ros interfaces"]
end

subgraph group_assets["Config and assets"]
  node_nav2_params["Nav2 params<br/>navigation config<br/>[nav2_params.yaml]"]
  node_settings["Settings<br/>mission config<br/>[settings.yaml]"]
  node_waypoints["Waypoints<br/>catalog"]
  node_multi_slam["Multi SLAM<br/>launch"]
  node_warehouse_map["Warehouse map<br/>map asset<br/>[warehouse_map.yaml]"]
  node_warehouse_world["Warehouse world<br/>simulation world<br/>[warehouse.world]"]
end

node_main -->|"build prompt"| node_llm_prompts
node_main -->|"request mission"| node_llm_client
node_llm_prompts -->|"reads"| node_settings
node_llm_prompts -->|"reads"| node_waypoints
node_llm_client -->|"mission json"| node_executor
node_executor -->|"checks contract"| node_schema
node_executor -->|"validate"| node_mission_validator
node_mission_validator -->|"enforces"| node_schema
node_executor -->|"dispatch via"| node_base_controller
node_base_controller -->|"implements"| node_ros2_controller
node_base_controller -->|"implements"| node_mock_controller
node_base_controller -->|"implements"| node_ebot_controller
node_executor -->|"multi-robot"| node_squad_commander
node_squad_commander -->|"manage"| node_formation_manager
node_formation_manager -->|"plan tasks"| node_formation_tasks
node_formation_tasks -->|"shape rules"| node_formations
node_ros2_controller -->|"tunes"| node_nav2_params
node_ros2_controller -->|"launches"| node_multi_slam
node_ros2_controller -->|"navigates on"| node_warehouse_map
node_ros2_controller -->|"simulates in"| node_warehouse_world
node_ros2_controller -->|"attach/detach"| node_link_msgs
node_ros2_controller -->|"robot model"| node_ur_description
node_ur_simulation_gz -->|"depends on"| node_ur_description
node_eyrc_warehouse -->|"launches"| node_warehouse_world
node_eyrc_warehouse -->|"uses"| node_link_msgs
node_main -->|"mock mode"| node_mock_controller
node_main -->|"ros mode"| node_ros2_controller

click node_main "https://github.com/alexprinse/project_o/blob/main/main.py"
click node_llm_client "https://github.com/alexprinse/project_o/blob/main/llm/client.py"
click node_llm_prompts "https://github.com/alexprinse/project_o/blob/main/llm/prompts.py"
click node_schema "https://github.com/alexprinse/project_o/blob/main/validator/schema.py"
click node_mission_validator "https://github.com/alexprinse/project_o/blob/main/validator/validator.py"
click node_executor "https://github.com/alexprinse/project_o/blob/main/executor/executor.py"
click node_base_controller "https://github.com/alexprinse/project_o/blob/main/robot/base.py"
click node_ros2_controller "https://github.com/alexprinse/project_o/blob/main/robot/ros2_controller.py"
click node_mock_controller "https://github.com/alexprinse/project_o/blob/main/robot/mock_controller.py"
click node_ebot_controller "https://github.com/alexprinse/project_o/blob/main/robot/ebot_controller.py"
click node_squad_commander "https://github.com/alexprinse/project_o/blob/main/robot/formation/squad_commander.py"
click node_formation_manager "https://github.com/alexprinse/project_o/blob/main/robot/formation/manager.py"
click node_formation_tasks "https://github.com/alexprinse/project_o/blob/main/robot/formation/tasks.py"
click node_formations "https://github.com/alexprinse/project_o/blob/main/robot/formation/formations.py"
click node_nav2_params "https://github.com/alexprinse/project_o/blob/main/config/nav2_params.yaml"
click node_settings "https://github.com/alexprinse/project_o/blob/main/config/settings.yaml"
click node_waypoints "https://github.com/alexprinse/project_o/blob/main/config/waypoints_turtlebot3.yaml"
click node_multi_slam "https://github.com/alexprinse/project_o/blob/main/config/launch/multi_slam_launch.py"
click node_warehouse_map "https://github.com/alexprinse/project_o/blob/main/config/maps/warehouse_map.yaml"
click node_warehouse_world "https://github.com/alexprinse/project_o/blob/main/config/worlds/warehouse.world"
click node_eyrc_warehouse "https://github.com/alexprinse/project_o/tree/main/eyrc_ws/src/eyantra_warehouse"
click node_ur_description "https://github.com/alexprinse/project_o/tree/main/eyrc_ws/src/ur_description"
click node_ur_simulation_gz "https://github.com/alexprinse/project_o/tree/main/eyrc_ws/src/ur_simulation_gz"
click node_link_msgs "https://github.com/alexprinse/project_o/tree/main/eyrc_ws/src/linkattacher_msgs"

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_main,node_llm_client,node_llm_prompts,node_schema,node_mission_validator,node_executor toneBlue
class node_base_controller,node_ros2_controller,node_mock_controller,node_ebot_controller toneAmber
class node_squad_commander,node_formation_manager,node_formation_tasks,node_formations toneMint
class node_eyrc_warehouse,node_ur_description,node_ur_simulation_gz,node_link_msgs toneRose
class node_nav2_params,node_settings,node_waypoints,node_multi_slam,node_warehouse_map,node_warehouse_world toneIndigo
```

## Components

### Mission app

Top-level mission parsing, validation, and execution pipeline.

- [main.py](https://github.com/alexprinse/project_o/blob/main/main.py): entrypoint · Runtime entrypoint that selects mode, robot profile, and prompt input. · `main.py`
- [LLM client](https://github.com/alexprinse/project_o/blob/main/llm/client.py): api wrapper · Wraps the Gemini API for natural-language mission generation. · `llm/client.py`
- [Prompt builder](https://github.com/alexprinse/project_o/blob/main/llm/prompts.py): prompt assembly · Builds system prompts from settings and waypoint catalogs. · `llm/prompts.py`
- [Mission schema](https://github.com/alexprinse/project_o/blob/main/validator/schema.py): contract · Defines the structured mission contract used for validation. · `validator/schema.py`
- [Validator](https://github.com/alexprinse/project_o/blob/main/validator/validator.py): safety gate · Rejects malformed or unsafe missions before execution. · `validator/validator.py`
- [Executor](https://github.com/alexprinse/project_o/blob/main/executor/executor.py): orchestrator · Dispatches validated missions to the appropriate execution path. · `executor/executor.py`

### Robot backends

Robot abstraction layers and runtime controllers.

- [Base controller](https://github.com/alexprinse/project_o/blob/main/robot/base.py): backend abstraction · Common controller interface behind robot-specific implementations. · `robot/base.py`
- [ROS 2 controller](https://github.com/alexprinse/project_o/blob/main/robot/ros2_controller.py): nav2 + vision · Primary TurtleBot3 controller for navigation and vision-follow behavior. · `robot/ros2_controller.py`
- [Mock controller](https://github.com/alexprinse/project_o/blob/main/robot/mock_controller.py): offline backend · Offline or simulated execution backend for non-ROS runs. · `robot/mock_controller.py`
- [ebot controller](https://github.com/alexprinse/project_o/blob/main/robot/ebot_controller.py): legacy backend · Legacy controller path for the older ebot stack. · `robot/ebot_controller.py`

### Coordination

Multi-robot squad coordination subsystem.

- [Squad commander](https://github.com/alexprinse/project_o/blob/main/robot/formation/squad_commander.py): multi-robot router · Routes multi-robot missions into the coordination subsystem. · `robot/formation/squad_commander.py`
- [Formation manager](https://github.com/alexprinse/project_o/blob/main/robot/formation/manager.py): state + replanning · Maintains formation state and live re-planning decisions. · `robot/formation/manager.py`
- [Formation tasks](https://github.com/alexprinse/project_o/blob/main/robot/formation/tasks.py): route splitting · Splits routes and handles regroup logic for squad missions. · `robot/formation/tasks.py`
- [Formations](https://github.com/alexprinse/project_o/blob/main/robot/formation/formations.py): geometry rules · Defines squad formation shapes and spacing geometry. · `robot/formation/formations.py`

### ROS workspace

Simulation and legacy ROS packages in eyrc_ws/src.

- [Eyantra warehouse](https://github.com/alexprinse/project_o/tree/main/eyrc_ws/src/eyantra_warehouse): ros package · Simulation package with warehouse task launches and models. · `eyrc_ws/src/eyantra_warehouse`
- [UR description](https://github.com/alexprinse/project_o/tree/main/eyrc_ws/src/ur_description): ros package · UR robot description, URDF/xacro, and visualization assets. · `eyrc_ws/src/ur_description`
- [UR sim gz](https://github.com/alexprinse/project_o/tree/main/eyrc_ws/src/ur_simulation_gz): ros package · Gazebo simulation package for UR arm control and spawning. · `eyrc_ws/src/ur_simulation_gz`
- [Link msgs](https://github.com/alexprinse/project_o/tree/main/eyrc_ws/src/linkattacher_msgs): ros interfaces · Custom attach/detach link services for simulation tasks. · `eyrc_ws/src/linkattacher_msgs`

### Config and assets

Mission config, navigation, and environment resources.

- [Nav2 params](https://github.com/alexprinse/project_o/blob/main/config/nav2_params.yaml): navigation config · Tuning for TurtleBot3 navigation behavior. · `config/nav2_params.yaml`
- [Settings](https://github.com/alexprinse/project_o/blob/main/config/settings.yaml): mission config · Runtime configuration for profiles and prompt assembly. · `config/settings.yaml`
- [Waypoints](https://github.com/alexprinse/project_o/blob/main/config/waypoints_turtlebot3.yaml): catalog · Named waypoint catalogs for robot profiles. · `config/waypoints_turtlebot3.yaml`
- [Multi SLAM](https://github.com/alexprinse/project_o/blob/main/config/launch/multi_slam_launch.py): launch · Launches namespaced SLAM instances for multi-robot operation. · `config/launch/multi_slam_launch.py`
- [Warehouse map](https://github.com/alexprinse/project_o/blob/main/config/maps/warehouse_map.yaml): map asset · Static warehouse map used by navigation and simulation. · `config/maps/warehouse_map.yaml`
- [Warehouse world](https://github.com/alexprinse/project_o/blob/main/config/worlds/warehouse.world): simulation world · Gazebo warehouse world definition. · `config/worlds/warehouse.world`

## Connections

- main.py → Prompt builder: build prompt · Constructs the command prompt from settings and waypoint catalogs.
- main.py → LLM client: request mission · Sends the prompt to the language model unless mock mode is used.
- Prompt builder → Settings: reads · Uses runtime configuration to shape the prompt.
- Prompt builder → Waypoints: reads · Injects waypoint labels and route hints into the prompt.
- LLM client → Executor: mission json · Returns structured mission content into the execution pipeline.
- Executor → Mission schema: checks contract · Relies on the mission schema for mission shape and field expectations.
- Executor → Validator: validate · Runs the hard safety gate before any robot action.
- Validator → Mission schema: enforces · Validates JSON structure, bounds, and mission constraints.
- Executor → Base controller: dispatch via · Uses the common controller interface for all backends.
- Base controller → ROS 2 controller: implements · Primary ROS 2/TurtleBot3 control implementation.
- Base controller → Mock controller: implements · Offline or non-ROS execution implementation.
- Base controller → ebot controller: implements · Legacy ebot control implementation.
- Executor → Squad commander: multi-robot · Routes multi-robot missions into squad coordination.
- Squad commander → Formation manager: manage · Tracks formation state and replanning.
- Formation manager → Formation tasks: plan tasks · Splits routes and handles regroup behavior.
- Formation tasks → Formations: shape rules · Applies formation geometry and spacing constraints.
- ROS 2 controller → Nav2 params: tunes · Uses navigation parameters for movement behavior.
- ROS 2 controller → Multi SLAM: launches · Interacts with multi-robot SLAM launch configuration when needed.
- ROS 2 controller → Warehouse map: navigates on · Uses the warehouse map for localization and pathing.
- ROS 2 controller → Warehouse world: simulates in · Operates against the warehouse Gazebo world.
- ROS 2 controller → Link msgs: attach/detach · Uses custom ROS services for simulation task interactions.
- ROS 2 controller → UR description: robot model · Consumes robot descriptions and visual assets for ROS/Gazebo integration.
- UR sim gz → UR description: depends on · Simulation package builds on the UR model and descriptions.
- Eyantra warehouse → Warehouse world: launches · Starts warehouse-specific scenarios and environments.
- Eyantra warehouse → Link msgs: uses · Uses custom services in warehouse task flows.
- main.py → Mock controller: mock mode · Offline mode bypasses robot actuation.
- main.py → ROS 2 controller: ros mode · ROS mode activates the primary robot backend.
