# peterbay/camera-control architecture

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

- Interactive diagram: https://gitdiagram.com/peterbay/camera-control
- Repository: https://github.com/peterbay/camera-control

## Overview

##### Project type and purpose
- This is a single-executable, command-line (terminal/NCurses-based) application written in C.
- Purpose: allow users to query and change V4L2 camera controls, load/save presets and config files, and navigate settings via keyboard.

##### File structure
- Top level:
- Makefile – build script
- camera-ctl.c – entire application source
- README.md – project documentation
- LICENSE – legal
- No subdirectories or separate modules: the code is monolithic, with logical separation only in functions within camera-ctl.c.

##### README for architecture clues
- Dependencies: ncurses for UI, V4L2 kernel interface for camera controls
- Config and preset file I/O
- Keyboard-driven UI with stateful navigation

##### Main components
a. UI Layer (NCurses)
b. Core Control Logic
c. V4L2 Interface Module
d. Config & Preset File I/O Module
e. Build & Deployment (Makefile)
f. External systems (Linux V4L2 driver, filesystem)

##### Relationships and data flows
- UI Layer ↔ Core Control Logic: user events in, UI updates out
- Core Logic ↔ V4L2 Interface: read/write camera controls via ioctl calls
- Core Logic ↔ File I/O Module: load/save settings from config/preset files
- File I/O Module ↔ Filesystem: read/write on disk
- Build tool (Makefile) → camera-ctl binary

##### Architectural patterns and design principles
- Layered architecture:
- Presentation (NCurses UI)
- Application Core (control state, preset management)
- Integration (V4L2, file system)
- Single process, synchronous I/O, event-driven loop for keyboard handling.

##### Technologies and libraries
- NCurses: terminal UI (windows, keyboard handling)
- V4L2 API: camera control via /dev/video* and ioctl
- Standard C library: file I/O, string parsing, memory management
- Makefile: orchestrates gcc compilation

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Build Tool
    Build["Makefile / gcc"]:::build
    click Build "https://github.com/peterbay/camera-control/tree/main/Makefile"

    %% Application Executable
    App["camera-ctl (C executable)"]:::app
    Build -->|"compile"| App

    %% Modules inside the executable
    UI["NCurses UI"]:::ui
    Core["Control Logic & State Management"]:::core
    V4L2["V4L2 Interface (ioctl)"]:::ext
    FileIO["Config & Preset File I/O"]:::ext

    App --> UI
    App --> Core
    App --> V4L2
    App --> FileIO

    %% Internal data flows
    UI <-->|"keyboard events"| Core
    Core -->|"ioctl(VIDIOC_S_CTRL)"| V4L2
    Core -->|"fopen()/fwrite()"| FileIO

    %% External systems
    Driver["Linux V4L2 Driver"]:::ext
    FS["Filesystem"]:::ext

    V4L2 -->|"device node I/O"| Driver
    FileIO -->|"file read/write"| FS

    %% Documentation and Licensing
    Doc["README.md"]:::doc
    click Doc "https://github.com/peterbay/camera-control/blob/main/README.md"
    Lic["LICENSE"]:::doc
    click Lic "https://github.com/peterbay/camera-control/tree/main/LICENSE"
    Doc -.-> App
    Lic -.-> App

    %% Click events for modules
    click UI "https://github.com/peterbay/camera-control/blob/main/camera-ctl.c"
    click Core "https://github.com/peterbay/camera-control/blob/main/camera-ctl.c"
    click V4L2 "https://github.com/peterbay/camera-control/blob/main/camera-ctl.c"
    click FileIO "https://github.com/peterbay/camera-control/blob/main/camera-ctl.c"

    %% Styles
    classDef ui fill:#a8d0ff,stroke:#000,color:#000;
    classDef core fill:#c3f584,stroke:#000,color:#000;
    classDef ext fill:#ffb370,stroke:#000,color:#000;
    classDef build fill:#d3d3d3,stroke:#000,color:#000;
    classDef app fill:#e0e0e0,stroke:#000,color:#000;
    classDef doc fill:#d0c4ff,stroke:#000,color:#000;
```
