# tuyangjs/windows_autotheme architecture

> Architecture diagram of the GitHub repository tuyangjs/windows_autotheme, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tuyangjs/windows_autotheme
- Repository: https://github.com/tuyangjs/windows_autotheme

## Overview

1. **Product shape**
   - This is a **Windows desktop app** built with **Tauri**: a **TypeScript/React frontend** runs in the webview, while a **Rust backend** performs OS-level work on Windows.
   - The app’s purpose is narrow and clear: **automatically switch Windows light/dark theme based on sunrise/sunset timing**.

2. **Top-level architecture**
   - The repository is split into two major runtime halves:
     - `src/` for the **UI and app logic**
     - `src-tauri/` for the **native backend, Windows integration, and packaging**
   - This boundary matters: the frontend handles configuration, display, and user interaction; the Rust side applies theme changes and manages OS-specific behavior.

3. **Frontend shell and navigation**
   - `src/main.tsx`, `App.tsx`, `Content.tsx`, and `TitleBar.tsx` form the app shell.
   - The UI appears to be a single-window desktop interface with a custom title bar rather than a browser-style multi-page app.
   - `src/com/ThemeSelector.tsx` and `ThemeThumb.tsx` suggest a theme-selection and preview area, likely for choosing appearance-related options.

4. **Core domain logic in the frontend**
   - The `src/mod/` folder holds most of the application logic:
     - `ThemeConfig.ts` for theme-related settings/state
     - `Crontab.ts` and `adjustTime.ts` for time-based scheduling and offsets
     - `Deviation.tsx` for time deviation or adjustment controls
     - `Mainoption.tsx` for primary settings/options
     - `WindowCode.ts` for window/app behavior or window-state handling
     - `applyTheme.ts` for invoking theme changes
     - `update.ts`, `RatingPrompt.tsx`, and `openStoreRating.ts` for update/review flows
     - `DataSave.ts` for persistence
   - This layer likely acts as the orchestration layer between user settings, time calculations, and backend actions.

5. **Weather/time source and scheduling flow**
   - The README says the app uses a **free API to get sunrise and sunset data**.
   - In code terms, the time-source concerns are probably handled in `searchCiti.tsx`, `sociti.ts`, and `adjustTime.ts`, where the app likely:
     1. resolves a city/location,
     2. fetches sunrise/sunset times,
     3. applies user offsets/deviation,
     4. schedules the next theme switch.
   - `Crontab.ts` suggests periodic or scheduled execution rather than continuous polling.

6. **Persistence and local state**
   - `DataSave.ts` plus `src/mod/utils/path.ts` and `tauri-file.ts` indicate local configuration storage on disk.
   - The app likely persists user preferences such as location, theme mode preferences, schedule settings, and language selection.
   - This is an important architectural boundary: configuration is stored locally and consumed by both UI and scheduling logic.

7. **Localization and UX structure**
   - `src/language/` contains JSON translation files for `en`, `es-ES`, `ja-JP`, `ru`, `zh-CN`, and `zh-HK`.
   - `src/language/index.tsx` likely centralizes language loading/selection.
   - This suggests the UI is localized through a client-side dictionary system rather than server-side rendering.

8. **Native backend responsibilities**
   - `src-tauri/src/main.rs` and `lib.rs` are the Tauri entry points.
   - `theme_apply.rs` and `windows_themes/` are the key native subsystem for **changing Windows theme settings**.
   - This backend is where the app crosses from “desktop UI” into “system control,” which is the main architectural boundary in the project.

9. **Windows-specific system integration**
   - The `src-tauri/capabilities/default.json` and `desktop.json` files define the permissions exposed to the frontend.
   - `build.rs` and the `icons/` / `img/` assets indicate packaging and Windows app branding.
   - The presence of `Appx/` and Microsoft Store references in the README show that distribution includes **Store/AppX packaging**, not just a local installer.

10. **Updates, store rating, and distribution flow**
   - `src/mod/update.ts` and `src/updates.tsx` indicate a dedicated update/announcement path in the frontend.
   - `openStoreRating.ts` and `RatingPrompt.tsx` suggest a Microsoft Store-aware review prompt.
   - The README explicitly mentions **Microsoft Store delivery and automatic updates**, so update and rating flows are part of the product architecture, not just UI extras.

11. **Overall data flow**
   - User changes settings in the React UI.
   - Settings are saved locally and used by the scheduling logic.
   - The app fetches sunrise/sunset data for the chosen location, adjusts it by user preference, and computes the next switch time.
   - When the trigger time arrives, the frontend/backend boundary is crossed and the Rust layer applies the Windows theme change.
   - The result is a closed loop: configuration → time calculation → OS action → persisted state.

12. **What to show in an architecture diagram**
   - A clean diagram should have four main blocks:
     - **React/TypeScript UI**
     - **Local settings/scheduler logic**
     - **Tauri/Rust native commands**
     - **Windows OS + external sunrise/sunset API**
   - The main arrows are:
     - UI to local config/state
     - UI to Rust commands
     - scheduler/time logic to external API
     - Rust backend to Windows theme settings
   - This repository is best understood as a **desktop automation client** with a thin native system-control layer behind a rich settings UI.

Main entry points: [`src/Content.tsx`](https://github.com/tuyangjs/windows_autotheme/blob/main/src/Content.tsx) (Content), [`src/App.tsx`](https://github.com/tuyangjs/windows_autotheme/blob/main/src/App.tsx) (App Shell), [`src/mod/ThemeConfig.ts`](https://github.com/tuyangjs/windows_autotheme/blob/main/src/mod/ThemeConfig.ts) (Theme Config), [`src/mod/Crontab.ts`](https://github.com/tuyangjs/windows_autotheme/blob/main/src/mod/Crontab.ts) (Schedule)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend UI"]
  node_src_main["Entry<br/>[main.tsx]"]
  node_app_shell["App Shell<br/>ui shell<br/>[App.tsx]"]
  node_content_view["Content<br/>ui view<br/>[Content.tsx]"]
  node_title_bar["Title Bar<br/>desktop chrome<br/>[TitleBar.tsx]"]
  node_theme_picker["Theme Picker<br/>selection ui<br/>[ThemeSelector.tsx]"]
  node_theme_thumb["Preview Thumb<br/>preview component<br/>[ThemeThumb.tsx]"]
  node_theme_config["Theme Config<br/>settings model<br/>[ThemeConfig.ts]"]
  node_schedule_logic["Schedule<br/>timing logic<br/>[Crontab.ts]"]
  node_time_adjust["Adjust Time<br/>time calc<br/>[adjustTime.ts]"]
  node_location_lookup["Location Lookup<br/>api client<br/>[searchCiti.tsx]"]
  node_sun_data["Sun Data<br/>api data<br/>[sociti.ts]"]
  node_storage[("Local Store<br/>persistence<br/>[DataSave.ts]")]
  node_localization["Language Pack<br/>i18n<br/>[index.tsx]"]
  node_updates_ui["Updates<br/>release flow<br/>[updates.tsx]"]
  node_rating_flow["Rating Prompt<br/>store flow<br/>[RatingPrompt.tsx]"]
end

subgraph group_backend["Native Backend"]
  node_runtime_cmds["Tauri Commands<br/>bridge layer<br/>[lib.rs]"]
  node_app_entry["Native Entry<br/>tauri entry<br/>[main.rs]"]
  node_theme_apply_rs["Theme Apply<br/>native command<br/>[theme_apply.rs]"]
  node_windows_theme["Windows Themes<br/>os integration<br/>[mod.rs]"]
end

node_windows_os["Windows OS<br/>operating system"]
node_sunrise_api["Sunrise API<br/>external api"]

node_src_main -->|"mounts"| node_app_shell
node_app_shell -->|"contains"| node_content_view
node_app_shell -->|"contains"| node_title_bar
node_content_view -->|"uses"| node_theme_picker
node_theme_picker -->|"previews"| node_theme_thumb
node_content_view -->|"binds"| node_theme_config
node_content_view -->|"configures"| node_schedule_logic
node_schedule_logic -->|"adjusts with"| node_time_adjust
node_time_adjust -->|"uses"| node_location_lookup
node_location_lookup -->|"requests"| node_sun_data
node_sun_data -->|"calls"| node_sunrise_api
node_theme_config -->|"persists"| node_storage
node_schedule_logic -->|"loads"| node_storage
node_content_view -->|"localizes"| node_localization
node_updates_ui -->|"prompts"| node_rating_flow
node_content_view -->|"shows"| node_updates_ui
node_theme_config -->|"invokes"| node_runtime_cmds
node_runtime_cmds -->|"dispatches"| node_theme_apply_rs
node_app_entry -->|"exposes"| node_runtime_cmds
node_theme_apply_rs -->|"uses"| node_windows_theme
node_windows_theme -->|"changes"| node_windows_os

click node_src_main "https://github.com/tuyangjs/windows_autotheme/blob/main/src/main.tsx"
click node_app_shell "https://github.com/tuyangjs/windows_autotheme/blob/main/src/App.tsx"
click node_content_view "https://github.com/tuyangjs/windows_autotheme/blob/main/src/Content.tsx"
click node_title_bar "https://github.com/tuyangjs/windows_autotheme/blob/main/src/TitleBar.tsx"
click node_theme_picker "https://github.com/tuyangjs/windows_autotheme/blob/main/src/com/ThemeSelector.tsx"
click node_theme_thumb "https://github.com/tuyangjs/windows_autotheme/blob/main/src/com/ThemeThumb.tsx"
click node_theme_config "https://github.com/tuyangjs/windows_autotheme/blob/main/src/mod/ThemeConfig.ts"
click node_schedule_logic "https://github.com/tuyangjs/windows_autotheme/blob/main/src/mod/Crontab.ts"
click node_time_adjust "https://github.com/tuyangjs/windows_autotheme/blob/main/src/mod/adjustTime.ts"
click node_location_lookup "https://github.com/tuyangjs/windows_autotheme/blob/main/src/mod/searchCiti.tsx"
click node_sun_data "https://github.com/tuyangjs/windows_autotheme/blob/main/src/mod/sociti.ts"
click node_storage "https://github.com/tuyangjs/windows_autotheme/blob/main/src/mod/DataSave.ts"
click node_runtime_cmds "https://github.com/tuyangjs/windows_autotheme/blob/main/src-tauri/src/lib.rs"
click node_app_entry "https://github.com/tuyangjs/windows_autotheme/blob/main/src-tauri/src/main.rs"
click node_theme_apply_rs "https://github.com/tuyangjs/windows_autotheme/blob/main/src-tauri/src/theme_apply.rs"
click node_windows_theme "https://github.com/tuyangjs/windows_autotheme/blob/main/src-tauri/src/windows_themes/mod.rs"
click node_localization "https://github.com/tuyangjs/windows_autotheme/blob/main/src/language/index.tsx"
click node_updates_ui "https://github.com/tuyangjs/windows_autotheme/blob/main/src/updates.tsx"
click node_rating_flow "https://github.com/tuyangjs/windows_autotheme/blob/main/src/mod/RatingPrompt.tsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_src_main,node_app_shell,node_content_view,node_title_bar,node_theme_picker,node_theme_thumb,node_theme_config,node_schedule_logic,node_time_adjust,node_location_lookup,node_sun_data,node_storage,node_localization,node_updates_ui,node_rating_flow toneBlue
class node_runtime_cmds,node_app_entry,node_theme_apply_rs,node_windows_theme toneAmber
class node_windows_os,node_sunrise_api toneNeutral
```

## Components

### Frontend UI

React/TypeScript desktop shell, settings, scheduling, and localization.

- [Entry](https://github.com/tuyangjs/windows_autotheme/blob/main/src/main.tsx): react entry · Bootstraps the webview app. · `src/main.tsx`
- [App Shell](https://github.com/tuyangjs/windows_autotheme/blob/main/src/App.tsx): ui shell · Main window layout and application framing. · `src/App.tsx`
- [Content](https://github.com/tuyangjs/windows_autotheme/blob/main/src/Content.tsx): ui view · Primary content area and screen composition. · `src/Content.tsx`
- [Title Bar](https://github.com/tuyangjs/windows_autotheme/blob/main/src/TitleBar.tsx): desktop chrome · Custom window title bar for the desktop app. · `src/TitleBar.tsx`
- [Theme Picker](https://github.com/tuyangjs/windows_autotheme/blob/main/src/com/ThemeSelector.tsx): selection ui · Theme selection and preview controls. · `src/com/ThemeSelector.tsx`
- [Preview Thumb](https://github.com/tuyangjs/windows_autotheme/blob/main/src/com/ThemeThumb.tsx): preview component · Small theme preview rendering. · `src/com/ThemeThumb.tsx`
- [Theme Config](https://github.com/tuyangjs/windows_autotheme/blob/main/src/mod/ThemeConfig.ts): settings model · Theme-related configuration and state. · `src/mod/ThemeConfig.ts`
- [Schedule](https://github.com/tuyangjs/windows_autotheme/blob/main/src/mod/Crontab.ts): timing logic · Time-based switching and cron-like scheduling. · `src/mod/Crontab.ts`
- [Adjust Time](https://github.com/tuyangjs/windows_autotheme/blob/main/src/mod/adjustTime.ts): time calc · Applies user offsets and deviations to switch times. · `src/mod/adjustTime.ts`
- [Location Lookup](https://github.com/tuyangjs/windows_autotheme/blob/main/src/mod/searchCiti.tsx): api client · Resolves city or location for sunrise/sunset data. · `src/mod/searchCiti.tsx`
- [Sun Data](https://github.com/tuyangjs/windows_autotheme/blob/main/src/mod/sociti.ts): api data · Fetches sunrise and sunset timing data. · `src/mod/sociti.ts`
- [Local Store](https://github.com/tuyangjs/windows_autotheme/blob/main/src/mod/DataSave.ts): persistence · Persists user settings and runtime state locally. · `src/mod/DataSave.ts`
- [Language Pack](https://github.com/tuyangjs/windows_autotheme/blob/main/src/language/index.tsx): i18n · Client-side translation loading and selection. · `src/language/index.tsx`
- [Updates](https://github.com/tuyangjs/windows_autotheme/blob/main/src/updates.tsx): release flow · Update and announcement UI flow. · `src/updates.tsx`
- [Rating Prompt](https://github.com/tuyangjs/windows_autotheme/blob/main/src/mod/RatingPrompt.tsx): store flow · Microsoft Store review prompt and open-store action. · `src/mod/RatingPrompt.tsx`

### Native Backend

Tauri Rust commands and Windows theme integration.

- [Tauri Commands](https://github.com/tuyangjs/windows_autotheme/blob/main/src-tauri/src/lib.rs): bridge layer · Frontend-facing commands and native integration boundary. · `src-tauri/src/lib.rs`
- [Native Entry](https://github.com/tuyangjs/windows_autotheme/blob/main/src-tauri/src/main.rs): tauri entry · Starts the Rust side of the desktop application. · `src-tauri/src/main.rs`
- [Theme Apply](https://github.com/tuyangjs/windows_autotheme/blob/main/src-tauri/src/theme_apply.rs): native command · Applies the chosen Windows light or dark theme. · `src-tauri/src/theme_apply.rs`
- [Windows Themes](https://github.com/tuyangjs/windows_autotheme/blob/main/src-tauri/src/windows_themes/mod.rs): os integration · Windows-specific theme implementation details. · `src-tauri/src/windows_themes/mod.rs`

### Other components

- **Windows OS**: operating system · System theme settings and desktop environment.
- **Sunrise API**: external api · External source for sunrise and sunset timing.

## Connections

- Entry → App Shell: mounts · Bootstraps the main application shell.
- App Shell → Content: contains · Renders the main content region.
- App Shell → Title Bar: contains · Provides custom desktop window chrome.
- Content → Theme Picker: uses · Displays theme selection controls.
- Theme Picker → Preview Thumb: previews · Shows theme appearance previews.
- Content → Theme Config: binds · Reads and edits theme settings.
- Content → Schedule: configures · Sets when automatic switching runs.
- Schedule → Adjust Time: adjusts with · Applies offset/deviation to computed times.
- Adjust Time → Location Lookup: uses · Resolves the target location first.
- Location Lookup → Sun Data: requests · Fetches sunrise/sunset timing data.
- Sun Data → Sunrise API: calls · Reads timing data from the external service.
- Theme Config → Local Store: persists · Saves user preferences locally.
- Schedule → Local Store: loads · Restores schedule and runtime state.
- Content → Language Pack: localizes · Loads UI language resources.
- Updates → Rating Prompt: prompts · Routes users toward store review actions.
- Content → Updates: shows · Surfaces update and announcement flow.
- Theme Config → Tauri Commands: invokes · Sends native commands across the Tauri boundary.
- Tauri Commands → Theme Apply: dispatches · Routes theme-change requests to Rust.
- Native Entry → Tauri Commands: exposes · Initializes native command handling.
- Theme Apply → Windows Themes: uses · Delegates to Windows-specific theme code.
- Windows Themes → Windows OS: changes · Applies the system theme on Windows.
