# onnenon/habit_tracker architecture

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

- Interactive diagram: https://gitdiagram.com/onnenon/habit_tracker
- Repository: https://github.com/onnenon/habit_tracker

## Overview

##### Main Components
- Application Core (Business Logic): Represented by files under the “lib/habit_quest” directory. Here you find modules handling the application’s domain logic, scheduling, tasks, rewards, and children management.
- Web Interface: Located in “lib/habit_quest_web”. This includes controllers, live views (for interactive user experiences), components, layouts, routers, and endpoint definitions.
- Assets & Frontend: The “assets” folder holds CSS, JavaScript, Tailwind configuration, and vendor files, which define the client-side presentation and styling.
- Database and Persistence: The “priv/repo” directory contains migrations and seeds. The Ecto Repo is defined (in lib/habit_quest/repo.ex), providing database connectivity and data persistence.
- Configuration and Environment: The “config” folder contains environment-specific and general configuration files needed for setting up the Phoenix application.

##### Out Relationships and Interactions
- Frontend (Assets) communicates with the Web Interface via static assets served by Phoenix.
- The Web Interface (controllers, live views, components) handles incoming browser requests (via routes defined in “lib/habit_quest_web/router.ex”) and maps them to the underlying business logic.
- The Business Logic layer (modules in “lib/habit_quest”) interacts with the database through the Ecto Repo. It manages core functionalities like creating, updating, or querying tasks, rewards, children, and scheduling tasks.
- Scheduling and Task Management: There is specific logic handling tasks (found under “lib/habit_quest/tasks”) and scheduling (see “lib/habit_quest/scheduler.ex”), hinting at background jobs or periodic tasks that drive some of the application’s operations.
- The database itself acts as a central data store that the Business Logic uses for persisting data and supporting application state.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The splitting into “habit_quest” (core business logic) and “habit_quest_web” (presentation/web layer) aligns with the MVC pattern.
- Use of Phoenix LiveView: LiveView modules (for children, parent, task, reward management) indicate that the application leverages real-time, interactive pages without heavy reliance on traditional JavaScript frameworks.
- Modular Design: The file structure (subdirectories for tasks, children, rewards) shows that the application is modular, allowing easy extension or modifications.
- Clear Configuration Management: Different environments are handled through the “config” directory. This supports smooth transitions between development, test, and production.

##### Additional Notes
- Since the application uses Phoenix LiveView, include an annotation that highlights real-time interaction capabilities between the server and the client.
- That migration scripts in “priv/repo/migrations” are collectively represented under the Database component, showing how core entities (children, tasks, rewards) are structured.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client Layer
    UB["User Browser"]:::client

    %% Frontend Layer
    A["Assets & Frontend"]:::assets

    %% Web Layer
    W["Web Interface (Controllers, LiveViews, Router, etc.)"]:::web

    %% Business Logic Layer
    BL["Application Core (Business Logic)"]:::core
    S["Scheduler/Background Jobs"]:::core

    %% Persistence Layer
    subgraph "Persistence Layer"
        R["Database Connector (Ecto Repo)"]:::db
        M["Migrations & Seeds"]:::db
        R -->|"ManagesSchema"| M
    end

    %% Configuration and Testing (Support Components)
    C["Configuration & Environment"]:::config
    T["Testing Suite"]:::test

    %% Data Flow
    UB -->|"AccessesStatic"| A
    A -->|"DeliversContent"| W
    UB -->|"HTTPRequests"| W
    W -->|"InvokesLogic"| BL
    S -->|"TriggersTasks"| BL
    BL -->|"DBOperations"| R
    R -->|"ReturnsData"| BL

    %% Configuration Influence
    C -.->|"Configures"| A
    C -.->|"Configures"| W
    C -.->|"Configures"| BL
    C -.->|"Configures"| S
    C -.->|"Configures"| R
    C -.->|"Configures"| M

    %% Testing Relationships
    T -.->|"Tests"| W
    T -.->|"Tests"| BL

    %% Click Events
    click A "https://github.com/onnenon/habit_tracker/tree/main/assets"
    click W "https://github.com/onnenon/habit_tracker/tree/main/lib/habit_quest_web"
    click BL "https://github.com/onnenon/habit_tracker/tree/main/lib/habit_quest"
    click S "https://github.com/onnenon/habit_tracker/blob/main/lib/habit_quest/scheduler.ex"
    click R "https://github.com/onnenon/habit_tracker/blob/main/lib/habit_quest/repo.ex"
    click M "https://github.com/onnenon/habit_tracker/tree/main/priv/repo"
    click C "https://github.com/onnenon/habit_tracker/tree/main/config"
    click T "https://github.com/onnenon/habit_tracker/tree/main/test"

    %% Styles
    classDef client fill:#f4a261,stroke:#000,stroke-width:2px;
    classDef assets fill:#e9c46a,stroke:#000,stroke-width:2px;
    classDef web fill:#2a9d8f,stroke:#000,stroke-width:2px;
    classDef core fill:#e76f51,stroke:#000,stroke-width:2px;
    classDef db fill:#264653,stroke:#fff,stroke-width:2px;
    classDef config fill:#a8dadc,stroke:#000,stroke-width:2px;
    classDef test fill:#457b9d,stroke:#000,stroke-width:2px;
```
