# omar-basheer/farmbots architecture

> Architecture diagram of the GitHub repository omar-basheer/farmbots, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/omar-basheer/farmbots
- Repository: https://github.com/omar-basheer/farmbots

## Overview

##### Project Breakdown and Main Components
- Server Component:
– Represented by files like bots/server.py and farmbots/server_script.py.
– The server is responsible for task assignment, managing farm state, and communicating with clients.
- Client/Robotic Units:
– Represented by bots/client.py and farmbots/client_script.py.
– They implement open-loop control, follow movement patterns, and execute tasks as assigned.
- Communication Layer:
– Modules like bots/communication.py and farmbots/comms.py are crucial for client-server messaging.
– Highlight that Bluetooth is used for connectivity between the central server and the robots.
- Movement, Planning, and Farm-Specific Helpers:
– Files such as bots/movement.py, bots/planning.py, farmbots/movement.py, farmbots/planning.py, and farmbots/localization.py indicate modular handling of movement, navigational planning, and localization.
– There is also a farm module (bots/farm.py) and helper scripts (farmbots/farm_helpers.py) that capture the specifics of the farm layout and fruit placement.
- Control and Coordination:
– farmbots/control.py likely contains the logic to coordinate various aspects of robot behavior like starting, stopping, and task execution.

##### Relationships and Data Flow
- Flow from planning and movement modules contained in each Client as a process that executes the commands received from the Server.

##### Architectural Patterns and Design Principles
- The architecture follows a modular design separating concerns for navigation, planning, communication, and control.
- It uses a client-server communication model with dynamic task assignment indicating a distributed system.
- That the system design accounts for scalability: multiple robotic clients can be added, and the server adapts its task assignment based on real-time factors (e.g., distance, fruit locations).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Central Server Subgraph
    subgraph "Central Server"
        Server["Task Manager / Server"]:::server
        ServerComm["Server Communication Module"]:::comm
        Server -->|"usescomms"| ServerComm
    end

    %% Robot Client Subgraph
    subgraph "Robot Client"
        Client["Robot Client"]:::client
        ClientPlanning["Planning Module"]:::module
        ClientMovement["Movement Module"]:::module
        ClientLocalization["Localization Module"]:::module
        ClientControl["Control Module"]:::module
        ClientComm["Client Communication Module"]:::comm

        Client -->|"handles"| ClientPlanning
        Client -->|"handles"| ClientMovement
        Client -->|"handles"| ClientLocalization
        Client -->|"handles"| ClientControl
        Client -->|"handles"| ClientComm
    end

    %% Farm Environment Subgraph
    subgraph "Farm Environment"
        Farm["Farm Layout & Helpers"]:::farm
    end

    %% Inter-component Communication
    Server -->|"assignstasks"| Client
    Client -->|"sendsstatus"| Server
    ServerComm -->|"messages"| ClientComm
    Server -->|"managesfarmstate"| Farm
    ClientMovement -->|"navigatesfarm"| Farm

    %% Click Events for Server Component
    click Server "https://github.com/omar-basheer/farmbots/blob/main/bots/server.py"
    click Server "https://github.com/omar-basheer/farmbots/blob/main/farmbots/server_script.py"

    %% Click Events for Client/Robotic Units
    click Client "https://github.com/omar-basheer/farmbots/blob/main/bots/client.py"
    click Client "https://github.com/omar-basheer/farmbots/blob/main/farmbots/client_script.py"

    %% Click Events for Communication Layer
    click ServerComm "https://github.com/omar-basheer/farmbots/blob/main/bots/communication.py"
    click ClientComm "https://github.com/omar-basheer/farmbots/blob/main/farmbots/comms.py"

    %% Click Events for Movement Module
    click ClientMovement "https://github.com/omar-basheer/farmbots/blob/main/bots/movement.py"
    click ClientMovement "https://github.com/omar-basheer/farmbots/blob/main/farmbots/movement.py"

    %% Click Events for Planning Module
    click ClientPlanning "https://github.com/omar-basheer/farmbots/blob/main/bots/planning.py"
    click ClientPlanning "https://github.com/omar-basheer/farmbots/blob/main/farmbots/planning.py"

    %% Click Event for Localization Module
    click ClientLocalization "https://github.com/omar-basheer/farmbots/blob/main/farmbots/localization.py"

    %% Click Events for Farm-specific Helpers
    click Farm "https://github.com/omar-basheer/farmbots/blob/main/bots/farm.py"
    click Farm "https://github.com/omar-basheer/farmbots/blob/main/farmbots/farm_helpers.py"

    %% Click Event for Control and Coordination
    click ClientControl "https://github.com/omar-basheer/farmbots/blob/main/farmbots/control.py"

    %% Styles Definitions
    classDef server fill:#ffcccb,stroke:#d62728,stroke-width:2px;
    classDef client fill:#cce5ff,stroke:#00509e,stroke-width:2px;
    classDef comm fill:#d5f5e3,stroke:#239b56,stroke-width:2px;
    classDef module fill:#e8daef,stroke:#8e44ad,stroke-width:2px;
    classDef farm fill:#fff2cc,stroke:#d4ac0d,stroke-width:2px;
```
