# hamza-ali-dev/habit-tracker architecture

> Architecture diagram of the GitHub repository hamza-ali-dev/habit-tracker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hamza-ali-dev/habit-tracker
- Repository: https://github.com/hamza-ali-dev/habit-tracker

## Overview

##### Project Type and Purpose
- The README and file tree indicate that this is a front-end habit tracker application built with React. Its main purpose is to allow users to track habits and calculate streaks (daily & weekly).
- The project uses modern toolchains including Vite (for fast builds and HMR), React for UI, Redux for state management, TypeScript for type safety, and Tailwind CSS for styling.

##### Analyzing the File Structure
- Top-Level Elements:
– Files like index.html, package.json, and vite.config.ts define the project’s entry, dependencies, and build configuration.
– Configuration files such as tailwind.config.js, .eslintrc.cjs, and tsconfig.* indicate code quality, styling, and type checks.
- The src Folder:
– Contains the entry point (App.tsx and main.tsx) and all the core logic.
– The components directory holds the visual building blocks of the interface. Notice components like DatePicker, Ribbon, TodoForm, TodoItem, and TodoList; these build up the user interface and likely relate to habit input and display.
– The hooks directory has custom hooks (useLocalStorage, useTodos) that encapsulate stateful logic – especially for managing persistent data (habit/todo data in local storage) and business logic.
– The services directory abstracts interactions with localStorage, ensuring data persistence beyond a single session.
– The state directory looks to be using Redux with slices (such as todosSlice.ts) and a centralized store (store.ts) to manage global application state.
- Additional Directories:
– Types and Utils folders define and support consistent data models and helper functions.

##### Key Architectural Components
a. /UI Layer
b. Business Logic and Hooks Layer
c. Data Persistence and Services Layer
– LocalStorage Service: Display this component as a service module that the hooks call to save/retrieve data.
d. State Management Layer
e. Supporting Modules
– Types & Utilities: Show a utility area that supplies type definitions (important since TypeScript is used) and helper functions/constants to ensure consistency across the system.

##### Relationships and Interactions
- Data Flow:
– User interactions in UI components trigger custom hooks, which in turn interact with the localStorage service and update or retrieve data.
– These changes are then reflected in the Redux store. The UI reacts to state changes via subscriptions provided by Redux.
- Feedback Loops:
– There is a feedback cycle from user input (via components) → hooks (business logic) → services/localStorage (persistence) and global state (Redux) → re-rendering of UI components.
- Data Binding:
– Show how React components are bound to state properties provided by the Redux store, while hooks abstract away the side effects.

##### Architectural Patterns and Design Principles
- Component-Based Architecture: A clear separation between UI (React components) and business/persistence logic (hooks, services, Redux state).
- Separation of Concerns:
– Visual components (components folder) are focused solely on rendering, while state management is isolated in the Redux slice and store.
– Utility functions and types support code reusability and maintainability.
- Unidirectional Data Flow: Reflecting how data flows (from actions and state updates) in Redux alongside the hooks managing side-effects with localStorage.

## Diagram (Mermaid)

```mermaid
graph TD
  %% UI Layer
  subgraph "UI Layer"
    A["App.tsx - Main Container"]:::ui
    B["DatePicker"]:::ui
    C["Ribbon"]:::ui
    D["TodoForm"]:::ui
    E["TodoList"]:::ui
    F["TodoItem"]:::ui
  end

  %% Business Logic Layer
  subgraph "Business Logic Layer"
    G["useLocalStorage - Custom Hook"]:::businessLogic
    H["useTodos - Custom Hook"]:::businessLogic
  end

  %% Data Persistence Layer
  subgraph "Data Persistence Layer"
    I["LocalStorage Service"]:::persistence
  end

  %% State Management Layer
  subgraph "State Management Layer"
    J["Redux Store"]:::state
    K["todosSlice"]:::state
  end

  %% Supporting Modules
  subgraph "Supporting Modules"
    L["Types Definition"]:::support
    M["Utility Functions"]:::support
  end

  %% UI Composition
  A -->|"includes"| B
  A -->|"includes"| C
  A -->|"includes"| D
  A -->|"includes"| E
  A -->|"includes"| F

  %% UI to Business Logic
  D -->|"triggers"| H

  %% Business Logic interactions
  H -->|"uses"| G
  H -->|"dispatches"| J
  H -->|"persistsData"| I
  G -->|"reads/writes"| I

  %% UI to State Management
  A -->|"dispatches"| J

  %% State Management internal
  J <-->|"manages"| K

  %% Supporting Modules connections
  H -->|"typedWith"| L
  I -->|"utilizes"| M

  %% Click Events
  click A "https://github.com/hamza-ali-dev/habit-tracker/blob/main/src/App.tsx"
  click B "https://github.com/hamza-ali-dev/habit-tracker/blob/main/src/components/DatePicker.tsx"
  click C "https://github.com/hamza-ali-dev/habit-tracker/blob/main/src/components/Ribbon.tsx"
  click D "https://github.com/hamza-ali-dev/habit-tracker/blob/main/src/components/TodoForm.tsx"
  click E "https://github.com/hamza-ali-dev/habit-tracker/blob/main/src/components/TodoList.tsx"
  click F "https://github.com/hamza-ali-dev/habit-tracker/blob/main/src/components/TodoItem.tsx"
  click G "https://github.com/hamza-ali-dev/habit-tracker/blob/main/src/hooks/useLocalStorage.ts"
  click H "https://github.com/hamza-ali-dev/habit-tracker/blob/main/src/hooks/useTodos.ts"
  click I "https://github.com/hamza-ali-dev/habit-tracker/blob/main/src/services/localStorageService.ts"
  click J "https://github.com/hamza-ali-dev/habit-tracker/blob/main/src/state/store.ts"
  click K "https://github.com/hamza-ali-dev/habit-tracker/blob/main/src/state/slices/todosSlice.ts"
  click L "https://github.com/hamza-ali-dev/habit-tracker/blob/main/src/types/index.ts"
  click M "https://github.com/hamza-ali-dev/habit-tracker/tree/main/src/utils"

  %% Styles
  classDef ui fill:#ffe6e6,stroke:#cc0000,stroke-width:2px;
  classDef businessLogic fill:#e6f0ff,stroke:#0066cc,stroke-width:2px;
  classDef persistence fill:#fff2cc,stroke:#ff9900,stroke-width:2px;
  classDef state fill:#e6ffe6,stroke:#009900,stroke-width:2px;
  classDef support fill:#e6f9ff,stroke:#009999,stroke-width:2px;
```
