# activitywatch/aw-tauri architecture

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

- Interactive diagram: https://gitdiagram.com/activitywatch/aw-tauri
- Repository: https://github.com/activitywatch/aw-tauri

## Overview

##### Project Overview and Purpose
- The project blends a web-based frontend (located in the root and (eventually) in the aw-webui folder) with a native Rust backend in the src-tauri folder, leveraging Tauri’s capabilities for desktop integration. It also uses Node.js for frontend dependency management and building.

##### Analyzing the File Structure
- Key top-level files and directories include:
- .github – Contains CI/CD configuration (workflows for build, lint, release, etc.).
- aw-webui – This directory holds the web UI code, even though it’s noted as “not yet the actual aw-webui code.”
- package.json and package-lock.json – Manage frontend dependencies.
- src-tauri – Contains all the Rust code and configuration for the Tauri backend.
▪ Within src-tauri, you see core Rust files (main.rs, lib.rs, logging.rs, manager.rs) that implement core functionality.
▪ The tauri.conf.json and several build/configuration files (Cargo.toml, build.rs, etc.) configure the runtime and the build for the native layer.
- Other files (Makefile, LICENSE, README.md) indicate standard project documentation/build scripts.
- This directory layout suggests an architecture where the Tauri application acts as a bridge between a modern web-based UI and a native Rust backend incorporating multiple features.

##### Identifying Major Components
- Tauri Application Container (Central Component):
- WebView/Frontend:
- Represents the web UI (aw-webui) that users interact with, built with Node.js and served inside a WebView provided by Tauri.
- Rust Backend:
- Contains the main executable logic (src-tauri/src/main.rs) and libraries (lib.rs, logging.rs, manager.rs) that implement:
- Module Manager: Handles the startup, management, and state of watcher modules.
- Integration with aw-server-rust: Runs ActivityWatch server logic as part of the main executable.
- Build and Configuration Ecosystem:
- CI/CD configuration under .github, Makefile for build scripts, and the Tauri configuration files (tauri.conf.json, Cargo.toml) that tie everything together.
- External Dependencies and Platforms:
- Node.js (for frontend development and building the web UI).
- Rust/Cargo (for compiling the backend).
- Operating System-specific components (Gtk on Linux, Tao on Windows/macOS, and potential mobile support under development).

##### Relationships and Interactions
- The "WebView/Frontend" component (representing the user interface from the aw-webui folder).
- Data flow from user interactions in the WebView triggering events in the Rust backend.
- The module manager starting, stopping, or managing watchers.
- Build and update flows from external build tools (Makefile, npx tauri build) into the Tauri Application.
- Relationships to emphasize dependency and flow among components.

##### Incorporating Architectural Patterns/Design Principles
- That the project uses a hybrid architecture where a web UI is embedded inside a native system wrapper (a typical Tauri design).
- Separation between presentation (web UI) and business logic (Rust backend) which is a variant of the separation-of-concerns principle.
- That modularity is key: the use of a module manager suggests a plug-in or modular design for dynamically handling watcher modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build & Config subgraph
    subgraph "Build & Config"
        TBC["Tauri Config"]:::config
        CBC["Cargo Build Config"]:::config
        BS["Build Script"]:::config
        CWF["CI/CD Workflows"]:::config
        BM["Build Automation"]:::config
    end

    %% External Dependencies subgraph
    subgraph "External Dependencies"
        ED1["Node.js"]:::external
        ED2["Rust/Cargo"]:::external
        ED3["Tauri Framework"]:::external
    end

    %% Central Application Components
    TA["Tauri Application"]:::tauri
    WV["WebView/Frontend"]:::frontend
    MAIN["Main Executable Logic"]:::backend
    RM["Module Manager"]:::backend
    TI["Tray Icon & Logging"]:::backend
    CR["Core Rust Library"]:::backend
    MS["aw-server-rust Integration"]:::backend

    %% Connections from Build & Config to Tauri Application (dotted arrows)
    TBC ---|"build"| TA
    CBC ---|"cargo"| TA
    BS ---|"script"| TA
    CWF ---|"automation"| TA
    BM ---|"automation"| TA

    %% External Dependencies connections
    ED1 ---|"builds UI"| WV
    ED2 ---|"compiles"| MAIN
    ED3 ---|"integrates"| TA

    %% Central Application Flow
    TA -->|"initializes"| WV
    WV -->|"userEvent"| MAIN
    MAIN -->|"manage"| RM
    MAIN -->|"trayCmd"| TI
    MAIN -->|"libraryCall"| CR
    MAIN -->|"serverCall"| MS
    MAIN -->|"feedbackEvent"| WV

    %% Styles and Classes
    classDef tauri fill:#FFD700,stroke:#B8860B,stroke-width:2px;
    classDef frontend fill:#ADD8E6,stroke:#00008B,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#006400,stroke-width:2px;
    classDef config fill:#FFB6C1,stroke:#8B0000,stroke-width:2px;
    classDef external fill:#FFFACD,stroke:#BDB76B,stroke-width:2px;

    %% Click Events for Build & Config components
    click TBC "https://github.com/activitywatch/aw-tauri/blob/master/src-tauri/tauri.conf.json"
    click CBC "https://github.com/activitywatch/aw-tauri/blob/master/src-tauri/Cargo.toml"
    click BS "https://github.com/activitywatch/aw-tauri/blob/master/src-tauri/build.rs"
    click CWF "https://github.com/activitywatch/aw-tauri/tree/master/.github/workflows"
    click BM "https://github.com/activitywatch/aw-tauri/tree/master/Makefile"

    %% Click Events for Central Application Components
    click TA "https://github.com/activitywatch/aw-tauri/tree/master/src-tauri"
    click WV "https://github.com/activitywatch/aw-tauri/tree/master/aw-webui"
    click MAIN "https://github.com/activitywatch/aw-tauri/blob/master/src-tauri/src/main.rs"
    click RM "https://github.com/activitywatch/aw-tauri/blob/master/src-tauri/src/manager.rs"
    click TI "https://github.com/activitywatch/aw-tauri/blob/master/src-tauri/src/logging.rs"
    click CR "https://github.com/activitywatch/aw-tauri/blob/master/src-tauri/src/lib.rs"
```
