# vaishnav-sabari-girish/hayasen architecture

> Architecture diagram of the GitHub repository vaishnav-sabari-girish/hayasen, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vaishnav-sabari-girish/hayasen
- Repository: https://github.com/vaishnav-sabari-girish/hayasen

## Overview

##### Project type and purpose
- This is an Embedded-Rust library crate (hayasen) whose sole purpose is to provide unified, type-safe drivers for IMU sensors (currently MPU6050 and MPU9250).
- It is _not_ a full-stack app but a reusable library that sits between an embedded application and the hardware sensors via an I²C bus.

##### File structure
- **src/**
- lib.rs  – crate entry point and `prelude` exports
- error.rs – unified error types and conversion logic
- functions.rs – registrar for runtime-configurable functions (hooking into operations)
- mpu6050.rs & mpu9250.rs – sensor-specific implementations, default configs, read routines
- **examples/** – sample applications showing how client code calls into the crate
- **docs/** – mdBook sources and theme assets for published documentation
- Cargo.toml & Cargo.lock – dependency list (e.g. embedded-hal, heapless, nb)
- Other top-level files (README, LICENSES) provide meta information.

##### README for additional insights
- Confirms supported sensors, usage pattern (client sets up an I²C peripheral, invokes `create_default`, then calls `read_all`).
- Roadmap shows planned extensions (new sensor modules, async support, no-alloc mode).

##### Diagramming recommendations
- dependency (Client → Library)
- data flow (Library → I²C bus → Sensors → Library → Client)
- build/doc generation (Cargo → mdBook → Docs)
– Blue for external interfaces (embedded-hal)
– Gray for hardware
– Yellow for documentation workflow

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Application
    ClientApp["Client Application"]:::code

    %% Hayasen Library Modules
    subgraph "Hayasen Library"
        direction TB
        CrateEntry["Crate Entry Point & Prelude (lib.rs)"]:::code
        ErrorModule["Error Module"]:::code
        FunctionsRegistry["Functions Registry"]:::code
        MPU6050Driver["MPU6050 Driver Module"]:::code
        MPU9250Driver["MPU9250 Driver Module"]:::code
    end

    %% External Interface
    EmbeddedHal["embedded-hal I²C Interface"]:::external

    %% Hardware Sensors
    subgraph "Physical Sensors (I²C Bus)" 
        direction TB
        Sensor6050["MPU6050"]:::hardware
        Sensor9250["MPU9250"]:::hardware
    end

    %% Auxiliary Artifacts
    subgraph "Auxiliary Artifacts"
        direction TB
        Examples["Example Applications"]:::code
        subgraph "Documentation Pipeline (mdBook)"
            direction TB
            BookConfig["docs/book.toml"]:::docs
            DocsSrc["docs/src/"]:::docs
            DocsTheme["docs/theme/"]:::docs
        end
        CargoPkg["Cargo Package Config (Cargo.toml)"]:::docs
        Readme["Project README & Meta Info (README.md)"]:::docs
    end

    %% Relationships
    ClientApp -->|"calls public API"| CrateEntry
    CrateEntry --> ErrorModule
    CrateEntry --> FunctionsRegistry
    CrateEntry --> MPU6050Driver
    CrateEntry --> MPU9250Driver

    ErrorModule -->|"uses generic I²C error"| EmbeddedHal
    FunctionsRegistry -->|"hooks into operations"| CrateEntry
    MPU6050Driver -->|"I²C Read/Write transactions"| EmbeddedHal
    MPU9250Driver -->|"I²C Read/Write transactions"| EmbeddedHal

    EmbeddedHal -->|"transacts over I²C bus"| Sensor6050
    EmbeddedHal -->|"transacts over I²C bus"| Sensor9250

    Sensor6050 -->|"returns sensor data"| MPU6050Driver
    Sensor9250 -->|"returns sensor data"| MPU9250Driver

    MPU6050Driver -->|"returns Result<T, Error>"| ClientApp
    MPU9250Driver -->|"returns Result<T, Error>"| ClientApp

    Examples -->|"illustrate usage of"| CrateEntry
    Examples -->|references| ErrorModule
    BookConfig -->|"build docs via mdBook"| DocsSrc
    DocsSrc -->|"themes applied from"| DocsTheme
    CargoPkg -->|"defines dependencies for"| CrateEntry
    Readme -->|"describes usage of"| CrateEntry

    %% Click Events
    click ErrorModule "https://github.com/vaishnav-sabari-girish/hayasen/blob/main/src/error.rs"
    click FunctionsRegistry "https://github.com/vaishnav-sabari-girish/hayasen/blob/main/src/functions.rs"
    click MPU6050Driver "https://github.com/vaishnav-sabari-girish/hayasen/blob/main/src/mpu6050.rs"
    click MPU9250Driver "https://github.com/vaishnav-sabari-girish/hayasen/blob/main/src/mpu9250.rs"
    click CrateEntry "https://github.com/vaishnav-sabari-girish/hayasen/blob/main/src/lib.rs"
    click Examples "https://github.com/vaishnav-sabari-girish/hayasen/tree/main/examples/"
    click BookConfig "https://github.com/vaishnav-sabari-girish/hayasen/blob/main/docs/book.toml"
    click DocsSrc "https://github.com/vaishnav-sabari-girish/hayasen/tree/main/docs/src/"
    click DocsTheme "https://github.com/vaishnav-sabari-girish/hayasen/tree/main/docs/theme/"
    click CargoPkg "https://github.com/vaishnav-sabari-girish/hayasen/blob/main/Cargo.toml"
    click Readme "https://github.com/vaishnav-sabari-girish/hayasen/blob/main/README.md"

    %% Styles
    classDef code fill:#e0ffe0,stroke:#2d7a2d,color:#000;
    classDef external fill:#e0f0ff,stroke:#1d4e8c,color:#000;
    classDef hardware fill:#f0f0f0,stroke:#666666,color:#000;
    classDef docs fill:#fff4cc,stroke:#a67c00,color:#000;
```
