PersonAI

personai-api

閱讀 PersonAI 開發紀錄

PersonAI

English | 繁體中文

An AI-powered personal fitness companion — real-time pose analysis, workout tracking, and body composition insights in one streamlined web app.

PersonAI is the web frontend for an AI personal trainer. It pairs a live camera-based pose pipeline with a workout history dashboard and body-composition tools, giving users actionable feedback on form, reps, and progress without leaving the browser.

Key Features

  • Live Pose Analysis — Processes camera video locally, streams 33 pose landmarks or an explicit pose_missing observation to the Python backend, and renders a HUD with rep count, FSM state, joint angles, calorie estimate, and real-time form-error callouts.
  • 1v1 Exercise PK — Authenticated two-player rooms reuse the live pose pipeline and exchange only readiness and rep-count state through a separate WebSocket.
  • Dashboard — Daily metric cards, weekly activity chart, posture quality, and today's workout list at a glance.
  • Workout History — Activity heatmap, per-exercise summaries, and a chronological workout log.
  • Body Profile — Optional basic height/weight and separate body-composition measurements, with unknown values preserved and API-provided derived metrics.
  • Theming — Light/dark mode powered by next-themes with OKLCH design tokens.
  • Authenticated data flow — Better Auth email/password sessions use HttpOnly cookies; short-lived JWKS JWTs authorize every FastAPI REST and WebSocket request.
  • Localized UI — All user-facing copy is in Traditional Chinese (zh-TW); backend enums are translated at the edge via canonical label maps.

Tech Stack

Getting Started

Prerequisites

  • Bun 1.3.14 (matches CI; bun.lock is the source of truth)
  • Node.js 22.12 or newer supported LTS for the test tooling
  • A running PersonAI backend for live pose analysis and REST data
  • PostgreSQL for Better Auth (Supabase Session Pooler in production)

Installation

# Clone
git clone https://github.com/YinCheng0106/personai-web.git
cd personai-web

# Install dependencies
bun install --frozen-lockfile

Environment Variables

Copy .env.sample to .env.local and fill in the values:

cp .env.sample .env.local
VariableDescriptionDefault
NEXT_PUBLIC_API_BASEREST base URL for the PersonAI backend.http://localhost:8000
NEXT_PUBLIC_WS_BASEWebSocket base URL used by connectAnalyzeSocket for live pose streaming.ws://localhost:8000
DATABASE_URLPostgreSQL connection string consumed by better-auth.—
BETTER_AUTH_SECRETSecret used to sign auth tokens (generate with openssl rand -base64 32).—
BETTER_AUTH_URLPublic base URL of this app (e.g. http://localhost:3000).—
AUTH_ISSUERJWT issuer; must match the FastAPI setting.http://localhost:3000
AUTH_AUDIENCEJWT audience; must match the FastAPI setting.personai-api

Available Scripts

CommandDescription
bun devStart the Next.js dev server with Turbopack.
bun run buildCreate a production build.
bun startServe the production build.
bun run lintRun ESLint (flat config, eslint-config-next).
bun run typecheckType-check the project with tsc --noEmit.
bun run formatFormat **/*.{ts,tsx} with Prettier.
bun run testRun Vitest component and contract tests.
bun run test:coverageRun V8 coverage gates and generate HTML / LCOV / JUnit.
bun run test:e2eRun Playwright browser tests.
bun run auth:migrateCreate/update Better Auth tables in personai_auth.

See CONTRIBUTING.md for the development workflow and docs/TESTING.md for test setup, Codecov, and mock versus real integration boundaries.

Open http://localhost:3000 once the dev server is running.

Adding shadcn/ui Components

bunx shadcn@latest add <component>

Components land in src/components/ui/ using the radix-luma style with neutral base color and HugeIcons.

Authentication database setup

  1. Apply scripts/bootstrap-auth-schema.sql to create the private personai_auth schema.
  2. Run bun run auth:migrate; Better Auth owns this schema.
  3. Configure FastAPI with the matching issuer, audience, and /api/auth/jwks URL.

REST and pose pages use the authenticated API. Tests isolate API and hardware boundaries with MSW, controlled transports, and browser routes.

Deployment gate

Do not publish the Vercel frontend until the NAS API is available through HTTPS/WSS. Use .env.production.example as the secret checklist; never expose the database password or Better Auth secret through NEXT_PUBLIC_* variables.

Project Structure

personai-web/
├── public/                       # Static assets
├── src/
│   ├── app/                      # Next.js App Router
│   │   ├── layout.tsx            # Root layout (ThemeProvider + Navbar)
│   │   ├── page.tsx              # Dashboard
│   │   ├── analyze/              # Live camera + pose HUD
│   │   ├── pk/                   # Authenticated two-player exercise rooms
│   │   ├── history/              # Heatmap + workout log
│   │   ├── inbody/               # Body composition + calorie tools
│   │   └── globals.css           # Tailwind v4 @theme tokens (OKLCH)
│   ├── components/
│   │   ├── ui/                   # shadcn primitives & wrappers
│   │   ├── layout/               # Navbar, PageContainer
│   │   ├── dashboard/            # Dashboard composites
│   │   ├── fitness/              # Pose HUD (camera, overlay, rep counter, …)
│   │   ├── history/              # History views
│   │   ├── inbody/               # InBody views
│   │   └── theme-provider.tsx    # next-themes wrapper
│   ├── hooks/
│   │   └── use-pose-analysis.ts  # MediaPipe + authenticated Analyze socket
│   ├── lib/
│   │   ├── api.ts                # REST client (request<T>() helper)
│   │   ├── socket.ts             # WebSocket adapter + frame normalization
│   │   ├── auth.ts               # better-auth init
│   │   ├── pose-messages.ts      # Landmark / pose_missing observations
│   │   ├── constants.ts          # Label maps (zh-TW translations)
│   │   ├── format.ts             # Display formatters
│   │   └── utils.ts              # cn() and shared utilities
│   └── types/                    # Domain types: pose, workout, inbody, user
├── components.json               # shadcn/ui config
├── eslint.config.mjs             # ESLint flat config
├── next.config.mjs               # Next.js config
├── postcss.config.mjs            # PostCSS (Tailwind v4)
├── tsconfig.json                 # Path alias: @/* → ./src/*
└── package.json

Conventions

  • Formatting: no semicolons, double quotes, 2-space indent, trailingComma: es5, 80-column lines. Tailwind class ordering is enforced via prettier-plugin-tailwindcss — run bun run format before committing UI changes.
  • Styling: reference semantic tokens (bg-background, text-muted-foreground, border-border, text-success, text-warning, text-info) so dark mode works automatically.
  • Localization: UI copy is zh-TW. Translate backend enums via the label maps in src/types/pose.ts and src/lib/constants.ts rather than hardcoding strings.
  • Path alias: @/* → ./src/* is the only alias configured in tsconfig.json.

License

Released under the MIT License.

簡介

大學畢業專題學生團隊共同開發的 AI 健身教練,結合 Next.js 網頁前端與 FastAPI 後端,提供姿勢分析、動作計數與運動紀錄。

主題

mediapipemediapipe-pose

版本

無版本資料

語言

TypeScript97.8 %
CSS1.9 %
JavaScript0.3 %
© 2026 YinCheng. 版權所有.