Skip to content

Commit 6a85900

Browse files
docs: Create component inventory and barrel files (#1518)
docs: create component inventory and barrel files This commit introduces new documentation and code organization improvements to enhance the developer experience for both human and AI contributors. - Creates a `docs/` directory with `COMPONENT_INVENTORY.md` and `FILE_STRUCTURE.md` to provide a clear map of the codebase. - Adds barrel export files (`index.ts`) to the `components/`, `hooks/`, and `utils/` directories to enable cleaner, centralized imports. - Updates the `README.md` to remove the outdated file list and link to the new, more detailed documentation. docs: add import path guidelines This commit adds a new `docs/IMPORT_GUIDELINES.md` file to address the feedback from the code review. This file documents the recommended import patterns, including how to use the new barrel exports and avoid common anti-patterns. fix: manually remove semicolons to fix linting errors This commit manually removes the semicolons from the barrel export files (`components/index.ts`, `hooks/index.ts`, `utils/index.ts`) to resolve the persistent linting errors. The automated `--fix` command was not working as expected. fix: resolve build error by removing empty hook This commit fixes a build failure caused by an empty `hooks/useSwipeGesture.ts` file. The empty file was not a valid module, leading to an error in the barrel export. - Deletes the empty `hooks/useSwipeGesture.ts` file. - Removes the corresponding export from `hooks/index.ts`. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 29c9943 commit 6a85900

8 files changed

Lines changed: 148 additions & 20 deletions

File tree

README.md

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -247,26 +247,19 @@ only required when you want to inspect the output ahead of time.
247247

248248
## Project Structure
249249

250-
- **`server.ts`**: Custom Express + Next.js + WebSocket entry point
251-
- **`app/page.tsx`**: Main dashboard with timer, HR tiles, Spotify controls, and Google Doc viewer
252-
- **`app/client/control/ControlPanel.tsx`**: Mobile control panel container for timer/Spotify controls and Tabata configuration
253-
- **`app/client/control/components/TimerControls.tsx`**: Dedicated Tabata/Stopwatch control surface with sticky layout
254-
- **`app/client/control/components/SpotifyControls.tsx`**: Mobile-friendly Spotify playback controls and synced volume slider
255-
- **`app/client/mock/page.tsx`**: Mock HRM data sender for testing
256-
- **`app/client/connect/page.tsx`**: Bluetooth HRM connector with user name/age input
257-
- **`services/tabataTimer.ts`**: Dual-mode timer service (Tabata/Stopwatch) with audio cues
258-
- **`services/spotifyPolling.ts`**: Spotify API polling and playback control service
259-
- **`utils/audioManager.ts`**: Audio system for timer beep sounds
260-
- **`hooks/useWebSocket.ts`**: Client-side WebSocket connection hook
261-
- **`hooks/useAudio.ts`**: Audio playback hook with volume control
262-
- **`hooks/useVolumePreference.ts`**: Synchronized volume preference across tabs
263-
- **`components/TimerDisplay.tsx`**: Large timer display with rotated side labels
264-
- **`components/HrmTiles.tsx`**: Dashboard wrapper that renders live heart rate tiles with skeleton fallbacks
265-
- **`components/HrTile.tsx`**: Reusable heart rate percentage tile component
266-
- **`components/SpotifyDisplay.tsx`**: Fixed bottom playback bar with volume/device controls
267-
- **`utils/socketManager.ts`**: Server-side WebSocket message router
268-
- **`types/index.ts`**: Shared UI prop types and timer enums
269-
- **`tests/playwright/core-functionality.spec.ts`**: Screenshot-based tests
250+
This project follows a standard Next.js application structure with a few key additions to support its real-time, stateful nature. For a detailed guide to the project's architecture, file organization, and component inventory, please see the documentation in the `docs/` directory.
251+
252+
- **[File Structure Guide](docs/FILE_STRUCTURE.md)**: A comprehensive overview of the directories and their purposes.
253+
- **[Component Inventory](docs/COMPONENT_INVENTORY.md)**: A map of the major UI components and their locations.
254+
255+
### Key Directories
256+
257+
- **`/app`**: Core Next.js pages, layouts, and API routes.
258+
- **`/components`**: Reusable React components.
259+
- **`/context`**: Global state management with React Context.
260+
- **`/hooks`**: Custom React hooks for shared logic.
261+
- **`/services`**: Backend business logic (e.g., Tabata timer, Spotify polling).
262+
- **`/utils`**: Helper functions and utilities.
270263

271264
## Available Commands
272265

components/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export * from './BottomNavBar'
2+
export * from './ConnectHRMonitorButton'
3+
export * from './ErrorBoundary'
4+
export * from './ErrorDisplay'
5+
export * from './ErrorFallback'
6+
export * from './Footer'
7+
export * from './FooterControls'
8+
export * from './GoogleDocViewer'
9+
export * from './HRMonitorStatusIndicator'
10+
export * from './HeartRateZones'
11+
export * from './HrTile'
12+
export * from './HrmConnectionPanel'
13+
export * from './HrmTiles'
14+
export * from './LoadingIndicator'
15+
export * from './Providers'
16+
export * from './SpotifyDeviceSelectorWrapper'
17+
export * from './SpotifyDisplay'
18+
export * from './SpotifyLoginButton'
19+
export * from './TimerDisplay'
20+
export * from './TimerSoundProvider'
21+
export * from './WorkoutColumns'
22+
export * from './WorkoutTableViewer'
23+
export * from './PlaybackControls/VolumeSlider'
24+
export * from './Spotify/PlaylistSelector'
25+
export * from './Spotify/VolumeControl'
26+
export * from './ThemeRegistry/ThemeRegistry'
27+
export * from './shared/StyledCard'

docs/COMPONENT_INVENTORY.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Component File Map
2+
3+
### Core UI Components
4+
- **Toast System**: `context/ToastContext.tsx` (to be created, currently using `ErrorContext.tsx`)
5+
- **Error Handling**: `components/ErrorBoundary.tsx` (confirmed location)
6+
- **Theme Configuration**: `lib/theme.ts` (confirmed location)
7+
8+
### Layout Components
9+
- **Navigation**: `components/BottomNavBar.tsx`
10+
- **Loading**: `components/LoadingIndicator.tsx` (confirmed location)
11+
12+
### Feature Components
13+
- **HRM**: `components/HrTile.tsx`, `hooks/useBluetoothHRM.ts`
14+
- **Spotify**: `components/Spotify/` directory structure
15+
- **Timer**: `components/TimerDisplay.tsx`, `services/tabataTimer.ts`

docs/FILE_STRUCTURE.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# HRM App File Structure Guide
2+
3+
This document provides a high-level overview of the file and directory structure for the Heart Rate Monitor (HRM) application. Its purpose is to help developers, including AI assistants, quickly understand the codebase layout, locate relevant files, and adhere to established organizational conventions.
4+
5+
## Top-Level Directories
6+
7+
The project is organized into the following primary directories:
8+
9+
- **`/app`**: Contains the core Next.js application, including pages, layouts, and API routes. All frontend-facing code resides here.
10+
11+
- **`/components`**: Houses reusable React components that are used across the application. This includes both small, atomic components and larger, composite ones.
12+
13+
- **`/constants`**: Stores application-wide constant values, such as default settings, magic numbers, or string literals that are used in multiple places.
14+
15+
- **`/context`**: Includes React Context providers that manage global state for features like WebSockets, user settings, and error handling.
16+
17+
- **`/docs`**: Contains project documentation, including this file, the component inventory, and other guides to help developers understand the codebase.
18+
19+
- **`/hooks`**: Home to custom React hooks that encapsulate reusable logic, such as interacting with browser APIs (e.g., Bluetooth, `localStorage`), managing side effects, or handling complex state.
20+
21+
- **`/lib`**: A directory for libraries and configurations that are foundational to the application. This includes the MUI theme, validation schemas, and NextAuth configuration.
22+
23+
- **`/logs`**: Stores log files generated by the application, such as server logs or Spotify token persistence data. This directory is excluded from version control.
24+
25+
- **`/public`**: Contains static assets that are served directly by the web server, such as images, fonts, and web workers.
26+
27+
- **`/scripts`**: A collection of utility scripts for development and deployment tasks, such as database seeding, environment setup, and running tests.
28+
29+
- **`/services`**: Holds the backend business logic for the application. This includes services for managing the Tabata timer, polling the Spotify API, and handling real-time data.
30+
31+
- **`/tests`**: Contains all tests for the application, subdivided into `unit` (Jest) and `playwright` (E2E and visual regression) directories.
32+
33+
- **`/types`**: Home to shared TypeScript type definitions and interfaces that are used across both the frontend and backend.
34+
35+
- **`/utils`**: A collection of helper functions and utility modules that provide common, reusable functionality, such as date formatting, URL manipulation, and logging.
36+
37+
## Key Files
38+
39+
- **`server.ts`**: The entry point for the custom Express server that manages the WebSocket connections and handles some API routes.
40+
41+
- **`next.config.js`**: The configuration file for the Next.js framework.
42+
43+
- **`docker-compose.yml`**: Defines the services, networks, and volumes for the Docker-based development environment.
44+
45+
- **`ecosystem.config.cjs`**: The configuration file for the PM2 process manager, used for running the application in production.
46+
47+
- **`playwright.config.ts`**: The configuration file for the Playwright test runner.
48+
49+
- **`jest.config.cjs`**: The configuration file for the Jest test runner.

docs/IMPORT_GUIDELINES.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Import Path Conventions
2+
3+
To maintain consistency and leverage the centralized barrel exports, please follow these import patterns:
4+
5+
### 1. From Barrel Exports (Recommended for common components, hooks, utils):
6+
7+
```typescript
8+
import { HrTile, BottomNavBar } from '@/components';
9+
import { useAudio, useLocalStorage } from '@/hooks';
10+
import { logger, dateUtils } from '@/utils';
11+
```
12+
13+
### 2. Direct Imports (For specific modules not in barrel exports):
14+
15+
```typescript
16+
import { ToastProvider } from '@/context/ToastContext'; // Correct path for ToastContext
17+
import theme from '@/lib/theme'; // Correct path for theme configuration
18+
```
19+
20+
### 3. Avoid (Incorrect/Deprecated Patterns):
21+
22+
```typescript
23+
import { ToastContainer } from '@/components/Toast'; // ❌ This component does not exist
24+
import { theme } from '@/styles/theme'; // ❌ Incorrect path, use '@/lib/theme'
25+
import HrTile from '../../components/HrTile'; // ❌ Avoid relative paths for top-level components
26+
```

hooks/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export * from './useAudio'
2+
export * from './useAutoConnect'
3+
export * from './useBluetoothHRM'
4+
export * from './useDebounce'
5+
export * from './useLocalStorage'
6+
export * from './useSpotifyRemoteExecution'
7+
export * from './useSpotifyWebPlayback'
8+
export * from './useUserPreferences'
9+
export * from './useVolumePreference'
10+
export * from './useWorkoutSession'

hooks/useSwipeGesture.ts

Whitespace-only changes.

utils/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export * from './audioManager'
2+
export * from './broadcast'
3+
export * from './constants'
4+
export * from './dateUtils'
5+
export * from './logger'
6+
export * from './socketManager'
7+
export * from './urls'
8+
export * from './visualization'

0 commit comments

Comments
 (0)