# ziadtamer52/habits architecture

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

- Interactive diagram: https://gitdiagram.com/ziadtamer52/habits
- Repository: https://github.com/ziadtamer52/habits

## Overview

##### Project type and purpose
- This is a single-page, front-end–only web application.

##### File structure
- Top‐level files:
- index.html – the main HTML shell
- style.css – styling (including theme switching)
- script.js – core JavaScript logic
- Chart.js (via CDN in index.html) – external visualization library
- localStorage (browser-built-in) for persistence
- No backend or external APIs beyond Chart.js and the browser runtime.

##### Extract insights from the README
- Tech stack: HTML5, CSS3, vanilla JavaScript, Chart.js, localStorage.
- Key functional areas: habit CRUD (Create, Read, Update, Delete), progress tracking, chart rendering, theme toggle.

##### Main components and interactions
a. Components
1. Browser / User Agent
2. UI Layer (HTML + CSS)
3. Application Logic (script.js)
– Habit Manager (adds/deletes marks habits)
– Theme Controller (toggles light/dark)
– Chart Controller (feeds data to Chart.js)
4. Data Store (localStorage)
5. Visualization Library (Chart.js)
b. Relationships & Data Flow
1. User → UI Layer (click “Add Habit”, “✔”, “❌”, theme switch)
2. UI Layer → Application Logic
3. App Logic ↔ localStorage (read/write habit data)
4. App Logic → Chart.js API (updates bar chart)
5. Chart.js → UI Layer (renders canvas)
c. Architectural patterns
– Separation of concerns:
- UI (structure & style)
- Logic (habit, theme, chart controllers)
- Persistence (localStorage)
– Single‐page app pattern (all in one HTML file)
d. Key technologies
– HTML5, CSS3 (UI)
– Vanilla JS (DOM manipulation & controllers)
– Chart.js (visualization)
– localStorage (persistence)

##### Putting it all together
- Habit Manager
- Theme Controller
- Chart Controller

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User((User)):::user

    %% UI Layer
    subgraph "UI Layer"
        HTML["UI Layer (HTML)"]:::ui
        CSS["UI Layer (CSS)"]:::ui
    end

    %% Application Logic
    subgraph "Application Logic"
        HM["Habit Manager"]:::logic
        TC["Theme Controller"]:::logic
        CC["Chart Controller"]:::logic
    end

    %% Storage and External
    Storage(("localStorage")):::storage
    ChartLib["Chart.js"]:::external

    %% Data Flows
    User -->|"Click Add/✔/❌"| HTML
    User -->|"Toggle Theme"| CSS
    HTML -->|"UI Event"| HM
    HTML -->|"UI Event"| TC
    HTML -->|"UI Event"| CC
    HM -->|"Read/Write Data"| Storage
    Storage -->|"Data"| HM
    CC -->|"Render Chart"| ChartLib
    ChartLib -->|"Canvas Render"| HTML
    TC -->|"Toggle Theme"| CSS

    %% Click Events
    click HTML "https://github.com/ziadtamer52/habits/blob/main/index.html"
    click CSS "https://github.com/ziadtamer52/habits/blob/main/style.css"
    click HM "https://github.com/ziadtamer52/habits/blob/main/script.js"
    click TC "https://github.com/ziadtamer52/habits/blob/main/script.js"
    click CC "https://github.com/ziadtamer52/habits/blob/main/script.js"
    click Storage "https://github.com/ziadtamer52/habits/blob/main/script.js"
    click ChartLib "https://github.com/ziadtamer52/habits/blob/main/index.html"

    %% Styles
    classDef user fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef ui fill:#B3CDE0,stroke:#333,stroke-width:1px;
    classDef logic fill:#6497B1,stroke:#333,stroke-width:1px;
    classDef storage fill:#BFD8B8,stroke:#333,stroke-width:1px;
    classDef external fill:#C397D8,stroke:#333,stroke-width:1px;
```
