# kolabse/kolabsecarscan architecture

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

- Interactive diagram: https://gitdiagram.com/kolabse/kolabsecarscan
- Repository: https://github.com/kolabse/kolabsecarscan

## Overview

##### Project type and purpose
- This is an embedded Arduino library (“KolabseCarsCan”) for decoding CAN-bus messages and storing car state data.
- It provides a set of C++ classes (TemplateCar, PSACar, etc.) that parse raw CAN frames and expose structured data for sketches.

##### File structure
- Top-level:
– examples/getCarData/getCarData.ino → Arduino sketch demonstrating usage
– src/… → library source files and headers
– library.properties, keywords.txt → Arduino IDE metadata
- Key classes in src/:
– KolabseCarsCan.{cpp,h} → core interface, initialization, CAN frame dispatcher
– TemplateCar.{cpp,h} → abstract base for specific decoders
– PSACar, AllCars → concrete decoders & container for multiple car instances

##### README
- “Library for storing data about the state of the car and decoding this data from CAN bus messages.”

##### Main components & interactions
a. External Hardware/Services
– Arduino MCU (host)
– CAN Transceiver / CAN-bus network (external messages)
b. Library Core
– KolabseCarsCan class
- init(), begin(), dispatchFrame(CANFrame)
– TemplateCar (abstract)
- parseFrame(), storeData()
– PSACar (extends TemplateCar)
– Additional Car classes (e.g. your TemplateCar subclass)
– AllCars container
- holds multiple Car instances, iterates to dispatch frames
c. User Sketch
– calls library begin(), polls CAN frames, reads decoded data (e.g. speed, RPM)

##### Architectural patterns & design principles
- Strategy/Template Method: TemplateCar defines the parsing interface; PSACar provides concrete decoding logic.
- Single Responsibility: KolabseCarsCan handles dispatching frames; Car classes handle data parsing/storage.
- Open/Closed: New car types can be added by subclassing TemplateCar without modifying core code.
- Container: AllCars aggregates multiple decoders and centralizes dispatch.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware Layer
    subgraph "Hardware Layer"
        direction TB
        MCU["Arduino MCU"]:::hardware
        CANBUS["CAN Transceiver / CAN-bus"]:::hardware
    end

    %% Library Layer
    subgraph "KolabseCarsCan Library"
        direction TB
        subgraph "Library Core"
            direction TB
            KCC["KolabseCarsCan"]:::core
            AC["AllCars"]:::core
        end
        subgraph "Decoders"
            direction TB
            TC["TemplateCar"]:::ext
            PSA["PSACar"]:::ext
        end
    end

    %% User Sketch
    subgraph "User Sketch"
        direction TB
        SK["getCarData.ino"]:::user
    end

    %% Connections
    CANBUS -->|"Raw CAN frame"| KCC
    KCC -->|"dispatchFrame()"| AC
    AC -->|"iterate decoders"| TC
    TC -->|"parseFrame()"| PSA
    PSA -->|"storeData()"| TC
    SK -->|"begin(), getSpeed() etc."| KCC

    %% Click Events
    click KCC "https://github.com/kolabse/kolabsecarscan/blob/main/src/KolabseCarsCan.cpp"
    click TC "https://github.com/kolabse/kolabsecarscan/blob/main/src/TemplateCar.cpp"
    click PSA "https://github.com/kolabse/kolabsecarscan/blob/main/src/PSACar.cpp"
    click AC "https://github.com/kolabse/kolabsecarscan/blob/main/src/AllCars.cpp"
    click SK "https://github.com/kolabse/kolabsecarscan/blob/main/examples/getCarData/getCarData.ino"

    %% Styles
    classDef hardware fill:#dddddd,stroke:#333,stroke-width:1px
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef ext fill:#90EE90,stroke:#333,stroke-width:1px
    classDef user fill:#FFA500,stroke:#333,stroke-width:1px
```
