# hungphamtan/recorder architecture

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

- Interactive diagram: https://gitdiagram.com/hungphamtan/recorder
- Repository: https://github.com/hungphamtan/recorder

## Overview

##### Main Components of the System
- User Interface (UI) Layer: This includes the entry point (index.html and src/main.tsx) and the React component hierarchy defined in src. This is broken down into many smaller UI components (e.g., RecordButton, CameraSelect, Teleprompter, LayoutSwitcher, etc.) contained within the src/components folder.
- State Management / Context Layer: Several React contexts (found in src/contexts) control the shared states such as camera settings, recording status, media device configuration, layout settings, screenshare, and picture-in-picture.
- Service and Utility Layer: Under src/services and src/hooks, you have business logic and helper functions for handling media devices, recording preferences, formatting, and custom hooks (like useCamera, useKeyboardShortcut, etc). This layer abstracts the interactions with browser APIs and implements the functionality (such as conversion from WEBM to MP4 and format utilities).
- Theming and Styles: The project also features a theme system (under src/theme) with style definitions, which defines how the UI looks and can be represented to show separation between logic and presentation.
- Build and Configuration: The project uses Vite for development (vite.config.ts) and has various linting and formatting configuration files (e.g., .eslintrc, .prettierrc, stylelint-config). Though not runtime components, they are important for the overall system architecture.
- Third-Party Integrations: Look at the README and services – incorporation of FFMPEG.wasm for media conversion and possibly external libraries for state management and styling.

##### Relationships and Interactions
- The UI Components interact with each other and with the state provided by the React Contexts. For example, the RecordButton will trigger state changes related to recording status, while components like Picture-in-Picture or Teleprompter monitor and update their states accordingly.
- The contexts act as the glue between the view and services: UI handlers call hooks (e.g., useCamera or useMicrophone) which in turn call services to communicate with the underlying media APIs.
- The utility services process data on formats or media devices before passing those values back to the components.

##### Architectural Patterns and Design Principles
- Component-Based Architecture: The project has a clear separation of UI components by functionality (each in its own folder) which makes it composable and maintainable.
- Separation of Concerns: UI, state management, business logic, and styling are clearly divided into different sections/directories.
- React Context for Global State: Shared states (camera, recording, media devices, etc.) are managed via React Contexts ensuring a clear data flow and centralized management.
- Client-Side-Only with Browser API Integration: The application directly utilizes web media APIs in a privacy-friendly manner (no backend), stressing the importance of user security and performance.
- Progressive Enhancement: Different features (like teleprompter, layout switching, recording conversion) are modular and can independently evolve.

b. Interactions:

c. Visual Distinction:

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser / Client
    subgraph "Browser/Client"
        Browser("Browser/Client (User Device)"):::client
    end

    %% UI Layer
    subgraph "UI Layer"
        A("index.html"):::ui
        B("src/main.tsx"):::ui
        C("src/App.tsx"):::ui
        D("React Components\\n(RecordButton,CameraSelect,Teleprompter,LayoutSwitcher,...)"):::ui
    end

    %% State Management
    subgraph "State Management"
        E("React Contexts\\n(cameraShape, recording, layout, etc)"):::state
    end

    %% Service and Utility Layer
    subgraph "Service & Utility Layer"
        F("Services\\n(mediaDevices,composer,format,preference)"):::service
        G("Custom Hooks\\n(useCamera,useKeyboardShortcut,...)"):::service
    end

    %% Theming and Styling
    subgraph "Theming / Styling"
        H("Theme Configuration"):::theme
        I("UI Component Styles\\n(CSS Modules)"):::theme
    end

    %% Build and Configuration
    subgraph "Build & Config"
        J("Build Tool\\n(vite.config.ts)"):::build
        K("Linting&Formatting\\n(.eslintrc,.prettierrc,.stylelintrc,stylelint-config)"):::build
        L("TypeScript Configs\\n(tsconfig.json,tsconfig.node.json)"):::build
    end

    %% Third-Party Integration
    subgraph "Third-Party Integrations"
        M("FFMPEG.wasm"):::third
    end

    %% Arrows / Data Flow
    Browser -->|"userEvents"| A
    Browser -->|"userEvents"| D
    A -->|"bootstraps"| B
    B -->|"loads"| C
    C -->|"renders"| D
    D -->|"updatesState"| E
    E -->|"triggers"| F
    E -->|"invokesHooks"| G
    G -->|"utilizeAPIs"| F
    D -->|"styledBy"| I
    I -->|"decorates"| H
    D <-->|"styledBy"| H
    C -.->|"buildTime"| J
    C -.->|"buildTime"| K
    C -.->|"buildTime"| L
    F -->|"mediaConversion"| M

    %% Click Events
    click A "https://github.com/hungphamtan/recorder/blob/main/index.html"
    click B "https://github.com/hungphamtan/recorder/blob/main/src/main.tsx"
    click C "https://github.com/hungphamtan/recorder/blob/main/src/App.tsx"
    click D "https://github.com/hungphamtan/recorder/tree/main/src/components"
    click E "https://github.com/hungphamtan/recorder/tree/main/src/contexts"
    click F "https://github.com/hungphamtan/recorder/tree/main/src/services"
    click G "https://github.com/hungphamtan/recorder/tree/main/src/hooks"
    click H "https://github.com/hungphamtan/recorder/tree/main/src/theme"
    click J "https://github.com/hungphamtan/recorder/blob/main/vite.config.ts"
    click K "https://github.com/hungphamtan/recorder/blob/main/.eslintrc"
    click L "https://github.com/hungphamtan/recorder/blob/main/tsconfig.json"

    %% Class Definitions
    classDef client fill:#FFECB3,stroke:#FF9800,stroke-width:2px;
    classDef ui fill:#B3E5FC,stroke:#039BE5,stroke-width:2px;
    classDef state fill:#C8E6C9,stroke:#43A047,stroke-width:2px;
    classDef service fill:#E1BEE7,stroke:#8E24AA,stroke-width:2px;
    classDef theme fill:#F0F4C3,stroke:#7CB342,stroke-width:2px;
    classDef build fill:#FFCDD2,stroke:#E53935,stroke-width:2px;
    classDef third fill:#D7CCC8,stroke:#5D4037,stroke-width:2px;
```
