PersonAI
personai-api
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_missingobservation 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-themeswith 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
- Framework: Next.js 16 (App Router, React Server Components, Turbopack)
- Language: TypeScript 5
- UI: React 19, Tailwind CSS v4, shadcn/ui (
radix-lumastyle), HugeIcons - Auth: better-auth + PostgreSQL (
pg) - Camera & Pose:
react-camera-pro+ WebSocket adapter to a Python pose backend - Tooling: Bun (package manager & runtime), ESLint (flat config), Prettier with
prettier-plugin-tailwindcss
Getting Started
Prerequisites
- Bun 1.3.14 (matches CI;
bun.lockis 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
| Variable | Description | Default |
|---|---|---|
NEXT_PUBLIC_API_BASE | REST base URL for the PersonAI backend. | http://localhost:8000 |
NEXT_PUBLIC_WS_BASE | WebSocket base URL used by connectAnalyzeSocket for live pose streaming. | ws://localhost:8000 |
DATABASE_URL | PostgreSQL connection string consumed by better-auth. | — |
BETTER_AUTH_SECRET | Secret used to sign auth tokens (generate with openssl rand -base64 32). | — |
BETTER_AUTH_URL | Public base URL of this app (e.g. http://localhost:3000). | — |
AUTH_ISSUER | JWT issuer; must match the FastAPI setting. | http://localhost:3000 |
AUTH_AUDIENCE | JWT audience; must match the FastAPI setting. | personai-api |
Available Scripts
| Command | Description |
|---|---|
bun dev | Start the Next.js dev server with Turbopack. |
bun run build | Create a production build. |
bun start | Serve the production build. |
bun run lint | Run ESLint (flat config, eslint-config-next). |
bun run typecheck | Type-check the project with tsc --noEmit. |
bun run format | Format **/*.{ts,tsx} with Prettier. |
bun run test | Run Vitest component and contract tests. |
bun run test:coverage | Run V8 coverage gates and generate HTML / LCOV / JUnit. |
bun run test:e2e | Run Playwright browser tests. |
bun run auth:migrate | Create/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
- Apply
scripts/bootstrap-auth-schema.sqlto create the privatepersonai_authschema. - Run
bun run auth:migrate; Better Auth owns this schema. - Configure FastAPI with the matching issuer, audience, and
/api/auth/jwksURL.
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 viaprettier-plugin-tailwindcss— runbun run formatbefore 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.tsandsrc/lib/constants.tsrather than hardcoding strings. - Path alias:
@/* → ./src/*is the only alias configured intsconfig.json.
License
Released under the MIT License.
簡介
大學畢業專題學生團隊共同開發的 AI 健身教練,結合 Next.js 網頁前端與 FastAPI 後端,提供姿勢分析、動作計數與運動紀錄。
主題
版本
無版本資料