# kenquiros64/oxygen architecture

> Architecture diagram of the GitHub repository kenquiros64/oxygen, 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/kenquiros64/oxygen
- Repository: https://github.com/kenquiros64/oxygen

## Overview

##### Main Components
- Frontend (React + Typescript):
- The UI is built using React (see directories like src/components, src/pages, src/models, and src/states).
- Vite is used as the bundler (indicated by vite.config.ts and tsconfig files).
- Backend (Tauri / Rust):
- The src-tauri directory holds all Rust source code, configuration, and build scripts for the inner application logic.
- Submodules include:
▪ Commands (src-tauri/src/commands) – these serve as the entry point for actions the UI can trigger.
▪ Database modules (src-tauri/src/db) – supporting different backends (Mongo, Sled, SQLite, etc.).
▪ Models and enums (src-tauri/src/models and src-tauri/src/enums) – representing core data structures and error handling.
▪ Repository layers (src-tauri/src/repository/local and remote) – abstracting data interactions.
▪ Services (src-tauri/src/services) – encapsulating business logic such as authentication, connectivity, printing, and synchronization.
- Additional Components:
- Configuration and project management files (e.g., Cargo.toml, tauri.conf.json, package.json) to setup the environment for both Rust and Node ecosystems.

##### Relationships and Interactions
- The Frontend interacts with the Tauri backend via commands (RPC-like calls exposed by Tauri). These calls may trigger authentication, data synchronization, or database operations.
- Within the Tauri backend:
- The Commands layer is the integration point that translates UI-initiated actions into service calls.
- The Services layer handles the core logic and delegates tasks to the Repository and Database layers.
- The Repository layer abstracts data source differences (local vs remote) and interacts with different database implementations.
- Models and Enums structure the data flow and error handling across the system.
- Overall, the data flow starts at the React UI, which sends requests that are handled by Tauri commands. Commands then invoke services, which in turn use the repository and database modules to perform operations.

##### Important Architectural Patterns and Design Principles
- Clear Layer Separation: The project follows a layered approach separating the UI, command-handling, service logic, data access (repositories), and domain models.
- Modularity: Subdirectories in the Tauri source split the code into logical domains (commands, db, models, repository, and services), easing maintenance and potential extensibility to support multiple database backends.
- Cross-boundary Communication: The commands help bridge the frontend (JavaScript/Typescript) with the backend (Rust), representing a tightly coordinated integration common in Tauri apps.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Section
    subgraph "Frontend (React + Typescript UI)"
        FE["React UI (src)"]:::frontend
        FEComponents["Components (src/components)"]:::frontend
        FEPages["Pages (src/pages)"]:::frontend
        FEModels["Models (src/models)"]:::frontend
        FEStates["States (src/states)"]:::frontend
        FEApp["App (src/App.tsx)"]:::frontend
        FEMain["Main (src/main.tsx)"]:::frontend
        FEVite["Bundler (Vite) (vite.config.ts)"]:::config
        FEConfig["TSConfig (tsconfig.json)"]:::config
    end

    %% Backend Section
    subgraph "Backend (Tauri / Rust)"
        TAURI["Tauri Backend (src-tauri)"]:::backend
        TauriCommands["Commands (src-tauri/src/commands)"]:::backend
        TauriServices["Services (src-tauri/src/services)"]:::backend
        TauriRepoLocal["Local Repositories (src-tauri/src/repository/local)"]:::backend
        TauriRepoRemote["Remote Repositories (src-tauri/src/repository/remote)"]:::backend
        TauriDB["Database Modules (src-tauri/src/db)"]:::data
        TauriModels["Models (src-tauri/src/models)"]:::backend
        TauriEnums["Enums (src-tauri/src/enums)"]:::backend
    end

    %% Project Configurations Section
    subgraph "Project Configurations"
        ConfigPkg["package.json"]:::config
        ConfigCargo["Cargo.toml (src-tauri/Cargo.toml)"]:::config
        ConfigTauri["tauri.conf.json (src-tauri/tauri.conf.json)"]:::config
        ConfigTS["tsconfig.node.json"]:::config
    end

    %% Connections between Frontend and Backend
    FE -->|"RPC_call"| TauriCommands
    TauriCommands -->|"Invoke_services"| TauriServices
    TauriServices -->|"DataAccess_local"| TauriRepoLocal
    TauriServices -->|"DataAccess_remote"| TauriRepoRemote
    TauriRepoLocal -->|"DB_operations"| TauriDB
    TauriRepoRemote -->|"DB_operations"| TauriDB
    TauriServices -->|"Use_models"| TauriModels
    TauriServices -->|"Use_enums"| TauriEnums

    %% Internal Frontend Groupings
    FEComponents --- FE
    FEPages --- FE
    FEModels --- FE
    FEStates --- FE
    FEApp --- FE
    FEMain --- FE
    FEVite --- FE
    FEConfig --- FE

    %% Project Config connections
    FE --- ConfigPkg
    TAURI --- ConfigCargo
    TAURI --- ConfigTauri
    FE --- ConfigTS

    %% Click Events
    click FE "https://github.com/kenquiros64/oxygen/tree/master/src"
    click FEComponents "https://github.com/kenquiros64/oxygen/tree/master/src/components"
    click FEPages "https://github.com/kenquiros64/oxygen/tree/master/src/pages"
    click FEModels "https://github.com/kenquiros64/oxygen/tree/master/src/models"
    click FEStates "https://github.com/kenquiros64/oxygen/tree/master/src/states"
    click FEApp "https://github.com/kenquiros64/oxygen/blob/master/src/App.tsx"
    click FEMain "https://github.com/kenquiros64/oxygen/blob/master/src/main.tsx"
    click FEVite "https://github.com/kenquiros64/oxygen/blob/master/vite.config.ts"
    click FEConfig "https://github.com/kenquiros64/oxygen/blob/master/tsconfig.json"
    click TAURI "https://github.com/kenquiros64/oxygen/tree/master/src-tauri"
    click TauriCommands "https://github.com/kenquiros64/oxygen/tree/master/src-tauri/src/commands"
    click TauriServices "https://github.com/kenquiros64/oxygen/tree/master/src-tauri/src/services"
    click TauriDB "https://github.com/kenquiros64/oxygen/tree/master/src-tauri/src/db"
    click TauriModels "https://github.com/kenquiros64/oxygen/tree/master/src-tauri/src/models"
    click TauriEnums "https://github.com/kenquiros64/oxygen/tree/master/src-tauri/src/enums"
    click TauriRepoLocal "https://github.com/kenquiros64/oxygen/tree/master/src-tauri/src/repository/local"
    click TauriRepoRemote "https://github.com/kenquiros64/oxygen/tree/master/src-tauri/src/repository/remote"
    click ConfigCargo "https://github.com/kenquiros64/oxygen/blob/master/src-tauri/Cargo.toml"
    click ConfigTauri "https://github.com/kenquiros64/oxygen/blob/master/src-tauri/tauri.conf.json"
    click ConfigTS "https://github.com/kenquiros64/oxygen/blob/master/tsconfig.node.json"

    %% Styles
    classDef frontend fill:#D0E6F7,stroke:#0B3D91,stroke-width:2px;
    classDef backend fill:#C1E1C1,stroke:#2E8B57,stroke-width:2px;
    classDef data fill:#FFF3B0,stroke:#DAA520,stroke-width:2px;
    classDef config fill:#F7D6E0,stroke:#C71585,stroke-width:2px;
```
