How javierldiazg/exercises works
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).