# happy-jm/tomato-do architecture

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

- Interactive diagram: https://gitdiagram.com/happy-jm/tomato-do
- Repository: https://github.com/happy-jm/tomato-do

## Overview

##### Project Type & Purpose
- This is a client‐side single-page web application (SPA) without a separate server backend.
- Purpose: Provide a Pomodoro timer, persistent To-Do list (via IndexedDB), user profile (name/photo), badges based on accumulated focus time, and day/night theming.

##### File Structure
Top-level files & folders:
- index.html, tomato-do.css – the main UI shell & styles
- index.js – application bootstrap & routing to individual modules
- database.js – data‐access layer for IndexedDB (stores: todolist, time, userInfo, report)
- timer.js – Pomodoro timer logic, alarm triggers
- badge.js – computes badge eligibility from “time” store
- inputName.js, inputPropicture.js – UI flows for profile setup
- snd/ – audio assets for alarms
- img/ – static UI images

##### README
- Confirms IndexedDB schema and explains main features: CRUD To-Do, timer with voice alerts, time tracking, badges, theme toggle.
- No external server or API calls—entirely browser/client‐side.

##### Main Components & Their Interactions
a. UI Layer (index.html + tomato-do.css)
– Contains placeholders/divs for To-Do list, timer display, badge panel, profile, theme toggle
b. Controller/Module Layer (JavaScript)
– index.js: Initializes modules, orchestrates navigation between views
– inputName.js & inputPropicture.js: Handle user profile setup UI & write to IndexedDB
– timer.js: Implements Pomodoro cycles; on cycle end, invokes snd/*.mp3 via Web Audio API
– badge.js: Reads “time” store, calculates badge levels, updates UI
– database.js: Abstracts IndexedDB operations (open, CRUD for todolist, report, userInfo, time)
c. Data Layer (IndexedDB)
– Four object stores: todolist, time, userInfo, report
– Database.js mediates all reads/writes
d. Assets
– snd folder (alarm audio)

##### Architectural Patterns & Principles
- Module-based separation of concerns (DAO, UI controllers, business logic)
- Client-side persistence (IndexedDB) in lieu of server
- Event-driven interactions (timer events, user inputs, theme toggle)
- MVC‐lite:
– Model: IndexedDB stores via database.js
– View: index.html + CSS and dynamic DOM updates
– Controller: JavaScript modules

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Browser (Client-side)"
        subgraph "UI Layer"
            UI_Shell["UI Shell<br/>(index.html)"]:::ui
            UI_Styles["Styles<br/>(tomato-do.css)"]:::ui
        end
        subgraph "Controller Modules"
            IndexJS["App Bootstrap & Router<br/>(index.js)"]:::logic
            NameJS["Name Input Module<br/>(inputName.js)"]:::logic
            PhotoJS["Photo Input Module<br/>(inputPropicture.js)"]:::logic
            TimerJS["Pomodoro Timer Module<br/>(timer.js)"]:::logic
            BadgeJS["Badge Calculation Module<br/>(badge.js)"]:::logic
        end
        subgraph "Data Access Layer"
            DatabaseJS["IndexedDB DAO<br/>(database.js)"]:::data
            IndexedDB["IndexedDB"]:::data
        end
        subgraph "Assets"
            AudioAssets["Audio Assets<br/>(snd/)"]:::asset
            ImageAssets["Image Assets<br/>(img/)"]:::asset
        end
        subgraph "Documentation"
            README["Project Documentation<br/>(README.md)"]:::doc
        end
    end

    UI_Shell -->|initializes| IndexJS
    UI_Styles -->|applies to| UI_Shell

    IndexJS -->|handles profile setup| NameJS
    IndexJS -->|handles profile setup| PhotoJS
    IndexJS -->|starts timer| TimerJS
    IndexJS -->|updates badges| BadgeJS

    NameJS -->|writes userInfo| DatabaseJS
    PhotoJS -->|writes userInfo| DatabaseJS
    TimerJS -->|logs sessions| DatabaseJS
    BadgeJS -->|reads time store| DatabaseJS

    DatabaseJS -->|stores data in| IndexedDB

    TimerJS -->|plays alarm| AudioAssets
    BadgeJS -->|updates UI| UI_Shell
    NameJS -->|updates UI| UI_Shell
    PhotoJS -->|updates UI| UI_Shell

    README -.->|reference| IndexJS
    README -.->|reference| DatabaseJS
    README -.->|reference| UI_Shell

    click UI_Shell "https://github.com/happy-jm/tomato-do/blob/main/index.html"
    click UI_Styles "https://github.com/happy-jm/tomato-do/blob/main/tomato-do.css"
    click IndexJS "https://github.com/happy-jm/tomato-do/blob/main/index.js"
    click DatabaseJS "https://github.com/happy-jm/tomato-do/blob/main/database.js"
    click TimerJS "https://github.com/happy-jm/tomato-do/blob/main/timer.js"
    click BadgeJS "https://github.com/happy-jm/tomato-do/blob/main/badge.js"
    click NameJS "https://github.com/happy-jm/tomato-do/blob/main/inputName.js"
    click PhotoJS "https://github.com/happy-jm/tomato-do/blob/main/inputPropicture.js"
    click AudioAssets "https://github.com/happy-jm/tomato-do/tree/main/snd/"
    click ImageAssets "https://github.com/happy-jm/tomato-do/tree/main/img/"
    click README "https://github.com/happy-jm/tomato-do/blob/main/README.md"

    classDef ui fill:#cce5ff,stroke:#004085,color:#004085,stroke-width:1px;
    classDef logic fill:#d4edda,stroke:#155724,color:#155724,stroke-width:1px;
    classDef data fill:#fff3cd,stroke:#856404,color:#856404,stroke-width:1px;
    classDef asset fill:#e2e3e5,stroke:#6c757d,color:#6c757d,stroke-width:1px;
    classDef doc fill:#f8d7da,stroke:#721c24,color:#721c24,stroke-width:1px;
```
