# javierldiazg/exercises architecture

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

- Interactive diagram: https://gitdiagram.com/javierldiazg/exercises
- Repository: https://github.com/javierldiazg/exercises

## Overview

##### Main Components
- Next.js Frontend – This is our “client” layer. The src/app directory hosts subdirectories for each exercise (exercise1, exercise2, exercise3) where the respective page.tsx files are defined. These pages are the entry points to the UI.
- UI Components – Located in the src/components directory, key components such as Header and the suite of Range components (Range, RangeInput, RangeLabel, RangeTrack, RangeFull) represent the atomic building blocks for constructing the views.
- Business Logic (Hooks & Services) – Custom hooks (e.g., useRange, useRangeInputs, useRangeData, useFullRange) in src/hooks encapsulate UI logic (state management, input handling, data processing). Meanwhile, API integration is managed in src/api (with services.ts and mockServices.ts) where external data fetch operations are encapsulated.
- Utilities & Types – The src/utils directory contains helper functions and type definitions (constants, types) which support the application’s logic.
- Styling – Global styles and module-specific CSS files (e.g., globals.css, exerciseOne.module.css) reside in src/styles and alongside each component, ensuring visual consistency and modular styling.

##### Relationships and Interactions
- The Next.js pages (found in each exercise folder) are rendered as distinct screens. They import UI components (like Range) and configure them with values suitable for that particular exercise.
- UI components are “dumb” presentation pieces that delegate logic to the custom hooks. For example, the Range component coordinates data flow by invoking useRange and useRangeInputs to handle events like dragging or input field changes.
- The hooks may call API services (in src/api) to retrieve external data (via GET requests to endpoints provided, such as http://demo0111712.mockable.io/normal-range). Data flows from the API layer back into the hooks and then is provided to the UI.
- Testing files are interspersed alongside their respective components and hooks to ensure isolation and testability. Although not part of the “runtime” system, they are important for understanding how the components interact and validate the logic.

##### Architectural Patterns and Design Principles
- Modular Design – The project is organized by domain (each “exercise” being a module) to encourage separation of responsibilities and easier maintainability.
- Separation of Concerns – UI components focus solely on presentation, custom hooks encapsulate behavior and state management, and API services manage data retrieval. This separation facilitates unit testing and independent feature evolution.
- Reusability – Common components and hooks are built to be reused across multiple exercises.
- Testability – By isolating logic in hooks and keeping UI components free of business logic, the architecture promotes easier testing (as seen by the presence of dedicated test files alongside components and hooks).

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Presentation Layer
    subgraph "Presentation Layer"
        subgraph "Next.js Frontend"
            Ex1["Exercise1 Page"]:::presentation
            Ex2["Exercise2 Page"]:::presentation
            Ex3["Exercise3 Page"]:::presentation
        end
        subgraph "UI Components"
            Header["Header"]:::presentation
            Range["Range"]:::presentation
            RangeInput["Range Input"]:::presentation
            RangeLabel["Range Label"]:::presentation
            RangeTrack["Range Track"]:::presentation
            RangeFull["Range Full"]:::presentation
        end
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        Hook1["useRange"]:::business
        Hook2["useRangeInputs"]:::business
        Hook3["useRangeData"]:::business
        Hook4["useFullRange"]:::business
    end

    %% Data, Utilities & Styling
    subgraph "Data & Utilities"
        subgraph "API Services"
            API1["API Service"]:::api
            API2["Mock API Service"]:::api
        end
        subgraph "Utilities"
            Constants["Constants"]:::utils
            Types["Type Definitions"]:::utils
        end
        subgraph "Styling"
            GlobalStyles["Global Styles"]:::styles
            ExerciseOneStyles["Exercise1 Styles"]:::styles
            ExerciseTwoStyles["Exercise2 Styles"]:::styles
            ExerciseThreeStyles["Exercise3 Styles"]:::styles
            HomeStyles["Home Page Styles"]:::styles
        end
    end

    %% Relationships - Presentation to UI Components
    Ex1 -->|"renders"| Header
    Ex1 -->|"renders"| Range
    Ex2 -->|"renders"| Header
    Ex2 -->|"renders"| Range
    Ex3 -->|"renders"| Header
    Ex3 -->|"renders"| RangeFull

    %% UI Components composition
    Range -->|"composes"| RangeInput
    Range -->|"composes"| RangeLabel
    Range -->|"composes"| RangeTrack

    %% UI Components invoking Business Logic (Hooks)
    Range -->|"invokes"| Hook1
    Range -->|"invokes"| Hook2
    Range -->|"invokes"| Hook3
    RangeFull -->|"invokes"| Hook4

    %% Business Logic calling API Services
    Hook1 -->|"fetches"| API1
    Hook1 -->|"fetches"| API2
    Hook2 -->|"fetches"| API1
    Hook2 -->|"fetches"| API2
    Hook3 -->|"fetches"| API1
    Hook3 -->|"fetches"| API2
    Hook4 -->|"fetches"| API1
    Hook4 -->|"fetches"| API2

    %% Styling support to UI Components
    GlobalStyles -.->|"styles"| Header
    GlobalStyles -.->|"styles"| Range
    GlobalStyles -.->|"styles"| RangeFull

    %% Click Events for Next.js Pages
    click Ex1 "https://github.com/javierldiazg/exercises/blob/main/src/app/exercise1/page.tsx"
    click Ex2 "https://github.com/javierldiazg/exercises/blob/main/src/app/exercise2/page.tsx"
    click Ex3 "https://github.com/javierldiazg/exercises/blob/main/src/app/exercise3/page.tsx"

    %% Click Events for UI Components
    click Header "https://github.com/javierldiazg/exercises/blob/main/src/components/Header/Header.tsx"
    click Range "https://github.com/javierldiazg/exercises/blob/main/src/components/Range/Range.tsx"
    click RangeInput "https://github.com/javierldiazg/exercises/blob/main/src/components/Range/RangeInput.tsx"
    click RangeLabel "https://github.com/javierldiazg/exercises/blob/main/src/components/Range/RangeLabel.tsx"
    click RangeTrack "https://github.com/javierldiazg/exercises/blob/main/src/components/Range/RangeTrack.tsx"
    click RangeFull "https://github.com/javierldiazg/exercises/blob/main/src/components/RangeFull/RangeFull.tsx"

    %% Click Events for Business Logic Hooks
    click Hook1 "https://github.com/javierldiazg/exercises/blob/main/src/hooks/useRange.ts"
    click Hook2 "https://github.com/javierldiazg/exercises/blob/main/src/hooks/useRangeInputs.ts"
    click Hook3 "https://github.com/javierldiazg/exercises/blob/main/src/hooks/useRangeData.ts"
    click Hook4 "https://github.com/javierldiazg/exercises/blob/main/src/hooks/useFullRange.ts"

    %% Click Events for API Services
    click API1 "https://github.com/javierldiazg/exercises/blob/main/src/api/services.ts"
    click API2 "https://github.com/javierldiazg/exercises/blob/main/src/api/mockServices.ts"

    %% Click Events for Utilities
    click Constants "https://github.com/javierldiazg/exercises/blob/main/src/utils/constants.ts"
    click Types "https://github.com/javierldiazg/exercises/blob/main/src/utils/types.ts"

    %% Click Events for Styling
    click GlobalStyles "https://github.com/javierldiazg/exercises/blob/main/src/styles/globals.css"
    click ExerciseOneStyles "https://github.com/javierldiazg/exercises/blob/main/src/app/exercise1/exerciseOne.module.css"
    click ExerciseTwoStyles "https://github.com/javierldiazg/exercises/blob/main/src/app/exercise2/exerciseTwo.module.css"
    click ExerciseThreeStyles "https://github.com/javierldiazg/exercises/blob/main/src/app/exercise3/exerciseThree.module.css"
    click HomeStyles "https://github.com/javierldiazg/exercises/blob/main/src/styles/home.module.css"

    %% Styles
    classDef presentation fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef business fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef api fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef utils fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef styles fill:#e2e3e5,stroke:#333,stroke-width:2px;
```
