# parthapatel114-rgb/margin architecture

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

- Interactive diagram: https://gitdiagram.com/parthapatel114-rgb/margin
- Repository: https://github.com/parthapatel114-rgb/margin

## Overview

Margin is a local-first desktop study-time tracker. Users choose a subject and study type, run a stopwatch, Pomodoro, or countdown, then finish and review recorded sessions; the app restores unfinished timers on restart. History supports manual entry and correction, while statistics and calendars summarize recorded time. The graph separates the React workspace and study workflows from analytics and the Rust/SQLite persistence layer. Backup, appearance, daily targets, and native mini-timer capabilities are included as documented branches; unsampled backend wiring is represented only where the README supports it.

Main entry points: [`src/App.tsx`](https://github.com/parthapatel114-rgb/margin/blob/main/src/App.tsx) (App shell), [`src-tauri/src/lib.rs`](https://github.com/parthapatel114-rgb/margin/blob/main/src-tauri/src/lib.rs) (Native commands), [`src/lib/analytics.ts`](https://github.com/parthapatel114-rgb/margin/blob/main/src/lib/analytics.ts) (Analytics engine), [`src/components/Insights.tsx`](https://github.com/parthapatel114-rgb/margin/blob/main/src/components/Insights.tsx) (Statistics views)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workspace["Desktop workspace"]
  node_app["App shell<br/>[App.tsx]"]
  node_settings["Settings and backups<br/>[Settings.tsx]"]
  node_palette["Appearance presets<br/>[palette.ts]"]
end

subgraph group_study["Study workflows"]
  node_timerui["Timer UI<br/>[Timer.tsx]"]
  node_today["Today view<br/>[Today.tsx]"]
  node_subjects["Subjects and types<br/>[Subjects.tsx]"]
end

subgraph group_insights["History and insights"]
  node_history["Session history<br/>[History.tsx]"]
  node_editor["Session editor<br/>[SessionEditor.tsx]"]
  node_insightsui["Statistics views<br/>[Insights.tsx]"]
  node_calendar["Calendar and dates<br/>[Calendar.tsx]"]
  node_analytics["Analytics engine<br/>[analytics.ts]"]
  node_insightcalc["Insight summaries<br/>[insights.ts]"]
  node_dateutils["Date utilities<br/>[dates.ts]"]
end

subgraph group_native["Native data layer"]
  node_dbapi["Native commands<br/>[lib.rs]"]
  node_model["Domain models<br/>[model.rs]"]
  node_storage["Session persistence<br/>[db.rs]"]
  node_sqlite[("Local SQLite")]
end

node_student(("Student"))

node_student -->|"uses"| node_app
node_app -->|"shows"| node_today
node_app -->|"shows"| node_timerui
node_app -->|"shows"| node_history
node_app -->|"shows"| node_insightsui
node_app -->|"opens"| node_settings
node_today -.->|"hosts"| node_timerui
node_timerui -.->|"records sessions"| node_dbapi
node_subjects -.->|"saves choices"| node_dbapi
node_history -->|"edits sessions"| node_editor
node_history -->|"analyzes sessions"| node_analytics
node_editor -.->|"saves entries"| node_dbapi
node_insightsui -->|"analyzes sessions"| node_analytics
node_insightsui -->|"builds recaps"| node_insightcalc
node_insightsui -->|"shows calendar"| node_calendar
node_calendar -->|"uses date totals"| node_analytics
node_calendar -->|"uses date ranges"| node_dateutils
node_insightcalc -->|"summarizes"| node_analytics
node_dateutils -->|"uses date helpers"| node_analytics
node_settings -.->|"exports and restores"| node_dbapi
node_app -.->|"applies appearance"| node_palette
node_dbapi -->|"dispatches commands"| node_storage
node_storage -->|"reads and writes"| node_model
node_storage -->|"persists records"| node_sqlite

click node_app "https://github.com/parthapatel114-rgb/margin/blob/main/src/App.tsx"
click node_timerui "https://github.com/parthapatel114-rgb/margin/blob/main/src/components/Timer.tsx"
click node_today "https://github.com/parthapatel114-rgb/margin/blob/main/src/components/Today.tsx"
click node_subjects "https://github.com/parthapatel114-rgb/margin/blob/main/src/components/Subjects.tsx"
click node_history "https://github.com/parthapatel114-rgb/margin/blob/main/src/components/History.tsx"
click node_editor "https://github.com/parthapatel114-rgb/margin/blob/main/src/components/SessionEditor.tsx"
click node_insightsui "https://github.com/parthapatel114-rgb/margin/blob/main/src/components/Insights.tsx"
click node_calendar "https://github.com/parthapatel114-rgb/margin/blob/main/src/components/Calendar.tsx"
click node_analytics "https://github.com/parthapatel114-rgb/margin/blob/main/src/lib/analytics.ts"
click node_insightcalc "https://github.com/parthapatel114-rgb/margin/blob/main/src/lib/insights.ts"
click node_dateutils "https://github.com/parthapatel114-rgb/margin/blob/main/src/lib/dates.ts"
click node_settings "https://github.com/parthapatel114-rgb/margin/blob/main/src/components/Settings.tsx"
click node_dbapi "https://github.com/parthapatel114-rgb/margin/blob/main/src-tauri/src/lib.rs"
click node_model "https://github.com/parthapatel114-rgb/margin/blob/main/src-tauri/src/model.rs"
click node_storage "https://github.com/parthapatel114-rgb/margin/blob/main/src-tauri/src/db.rs"
click node_palette "https://github.com/parthapatel114-rgb/margin/blob/main/src/lib/palette.ts"

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_app,node_settings,node_palette toneBlue
class node_timerui,node_today,node_subjects toneAmber
class node_history,node_editor,node_insightsui,node_calendar,node_analytics,node_insightcalc,node_dateutils toneMint
class node_dbapi,node_model,node_storage,node_sqlite toneRose
class node_student toneIndigo
```

## Components

### Desktop workspace

- [App shell](https://github.com/parthapatel114-rgb/margin/blob/main/src/App.tsx): `src/App.tsx`
- [Settings and backups](https://github.com/parthapatel114-rgb/margin/blob/main/src/components/Settings.tsx): `src/components/Settings.tsx`
- [Appearance presets](https://github.com/parthapatel114-rgb/margin/blob/main/src/lib/palette.ts): `src/lib/palette.ts`

### Study workflows

- [Timer UI](https://github.com/parthapatel114-rgb/margin/blob/main/src/components/Timer.tsx): `src/components/Timer.tsx`
- [Today view](https://github.com/parthapatel114-rgb/margin/blob/main/src/components/Today.tsx): `src/components/Today.tsx`
- [Subjects and types](https://github.com/parthapatel114-rgb/margin/blob/main/src/components/Subjects.tsx): `src/components/Subjects.tsx`

### History and insights

- [Session history](https://github.com/parthapatel114-rgb/margin/blob/main/src/components/History.tsx): `src/components/History.tsx`
- [Session editor](https://github.com/parthapatel114-rgb/margin/blob/main/src/components/SessionEditor.tsx): `src/components/SessionEditor.tsx`
- [Statistics views](https://github.com/parthapatel114-rgb/margin/blob/main/src/components/Insights.tsx): `src/components/Insights.tsx`
- [Calendar and dates](https://github.com/parthapatel114-rgb/margin/blob/main/src/components/Calendar.tsx): `src/components/Calendar.tsx`
- [Analytics engine](https://github.com/parthapatel114-rgb/margin/blob/main/src/lib/analytics.ts): `src/lib/analytics.ts`
- [Insight summaries](https://github.com/parthapatel114-rgb/margin/blob/main/src/lib/insights.ts): `src/lib/insights.ts`
- [Date utilities](https://github.com/parthapatel114-rgb/margin/blob/main/src/lib/dates.ts): `src/lib/dates.ts`

### Native data layer

- [Native commands](https://github.com/parthapatel114-rgb/margin/blob/main/src-tauri/src/lib.rs): `src-tauri/src/lib.rs`
- [Domain models](https://github.com/parthapatel114-rgb/margin/blob/main/src-tauri/src/model.rs): `src-tauri/src/model.rs`
- [Session persistence](https://github.com/parthapatel114-rgb/margin/blob/main/src-tauri/src/db.rs): `src-tauri/src/db.rs`
- **Local SQLite**

### Other components

- **Student**

## Connections

- Student → App shell: uses (evidence: `README.md`)
- App shell → Today view: shows (evidence: `src/App.tsx`)
- App shell → Timer UI: shows (evidence: `src/App.tsx`)
- App shell → Session history: shows (evidence: `src/App.tsx`)
- App shell → Statistics views: shows (evidence: `src/App.tsx`)
- App shell → Settings and backups: opens (evidence: `src/App.tsx`)
- Today view → Timer UI: hosts
- Timer UI → Native commands: records sessions
- Subjects and types → Native commands: saves choices
- Session history → Session editor: edits sessions (evidence: `src/components/History.tsx`)
- Session history → Analytics engine: analyzes sessions (evidence: `src/components/History.tsx`)
- Session editor → Native commands: saves entries
- Statistics views → Analytics engine: analyzes sessions (evidence: `src/components/Insights.tsx`)
- Statistics views → Insight summaries: builds recaps (evidence: `src/components/Insights.tsx`)
- Statistics views → Calendar and dates: shows calendar (evidence: `src/components/Insights.tsx`)
- Calendar and dates → Analytics engine: uses date totals (evidence: `src/components/Calendar.tsx`)
- Calendar and dates → Date utilities: uses date ranges (evidence: `src/components/Calendar.tsx`)
- Insight summaries → Analytics engine: summarizes (evidence: `src/lib/insights.ts`)
- Date utilities → Analytics engine: uses date helpers (evidence: `src/lib/dates.ts`)
- Settings and backups → Native commands: exports and restores
- App shell → Appearance presets: applies appearance
- Native commands → Session persistence: dispatches commands (evidence: `src-tauri/src/lib.rs`)
- Session persistence → Domain models: reads and writes (evidence: `src-tauri/src/db.rs`)
- Session persistence → Local SQLite: persists records (evidence: `README.md`)
