npm package: @lid-vizion/pose-analysis
Description: Pose analysis library with MediaPipe, Gemini-powered custom exercises, and MongoDB persistence
Author: LidVizion
Latest version: 0.1.4

# Pose Analysis Library

This library provides real-time human pose analysis using MediaPipe. It includes React components for video and live camera analysis, along with standalone logic for counting repetitions and providing feedback for specific exercises.

## 📂 Project Structure

```
libraries/pose-analysis/
├── src/
│   ├── analyzers/         # Core exercise logic (pure TypeScript)
│   │   ├── squat.ts       # Squat form analysis
│   │   ├── kettlebell.ts  # Single Hand Snatch analysis
│   │   ├── long_cycle.ts  # Long Cycle (Double Kettlebell) analysis
│   │   └── types.ts       # Shared interfaces
│   ├── components/        # React UI components
│   │   ├── AnalysisPage.tsx # Video/Image upload & analysis
│   │   ├── ExercisePage.tsx # Live webcam exercise tracking
│   │   └── BottomNav.tsx    # Navigation component
│   ├── hooks/             # Custom React hooks
│   │   └── usePoseDetection.ts # MediaPipe integration hook
│   ├── lib/               # Utilities
│   │   └── utils.ts       # Helper functions (cn, etc.)
│   └── index.ts           # Public API exports
├── dev-app/               # Standalone Vite development app
├── start-dev.sh           # Script to build & run dev-app
├── package.json           # Library dependencies
└── tsconfig.json          # TypeScript configuration
```

## 🏋️ implemented Exercises

### 1. Squat Form (`squat.ts`)
- **Logic**: Calculates the angle between Hip, Knee, and Ankle.
- **States**: `UP` -> `DOWN` -> `UP`.
- **Feedback**: Checks depth (< 90 degrees) and full extension.

### 2. Single Hand Kettlebell Snatch (`kettlebell.ts`)
- **Logic**: Tracks wrist position relative to shoulder (top) and hip (bottom).
- **States**: Independent `UP`/`DOWN` states for Left and Right arms.
- **Feedback**: "Left Up!", "Right Rep Complete!", etc.

### 3. Long Cycle (Double Kettlebell) (`long_cycle.ts`)
- **Logic**: Tracks **BOTH** hands simultaneously.
- **Requirement**: Both wrists must move from below hips to above shoulders and back down together.
- **Feedback**: "Lift both hands!", "Rep Complete!".

## 🚀 Standalone Development

You can run this library in isolation without the main app.

1.  **Navigate to directory**:
    ```bash
    cd libraries/pose-analysis
    ```
2.  **Run the dev script**:
    ```bash
    ./start-dev.sh
    # Or on Windows Git Bash:
    bash start-dev.sh
    ```
    This will:
    - Install dependencies for the `dev-app`.
    - Build the library.
    - Start a local Vite server at `http://localhost:5173`.

## 🔌 Integration Guide

### Frontend (React App)

To use these components in the main `baas` application:

1.  **Add Dependency**:
    Add to root `package.json`:
    ```json
    "@lid-vizion/pose-analysis": "workspace:*"
    ```
2.  **Install**:
    ```bash
    npm install
    ```
3.  **Import & Route**:
    In `src/App.tsx`:
    ```typescript
    import { AnalysisPage, ExercisePage } from "@lid-vizion/pose-analysis";
    
    // In Routes:
    <Route path="/analysis" element={<AnalysisPage />} />
    <Route path="/exercise" element={<ExercisePage />} />
    ```

### Backend (AWS Lambda)

To run analysis logic on the server (e.g., for processing uploaded videos):

1.  **Handler**:
    A handler file has been created at `lambda/src/handlers/pose-analysis.ts`.
    - It imports the analyzers (`SquatAnalyzer`, etc.) directly.
    - Uncomment the code in this file to enable it.

2.  **Infrastructure (SAM)**:
    A resource definition has been added to `lambda/workspace-template.yml`.
    - Uncomment the `PoseAnalysisFunction` section to provision the Lambda.

3.  **Dependencies**:
    Add `@lid-vizion/pose-analysis` to `lambda/package.json` if you want to share the exact same logic code between frontend and backend.

## 🛠 Dependencies

- **@mediapipe/pose**: AI model for body tracking.
- **react-webcam**: For handling camera input.
- **lucide-react**: UI icons.
- **tailwindcss**: Styling (via `clsx` and `tailwind-merge`).