|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +TrendWeight is a monorepo web application for tracking weight trends by integrating with smart scales from Withings and Fitbit. It consists of a React frontend and C# ASP.NET Core backend, deployed as Docker containers. |
| 8 | + |
| 9 | +**Repository for deepwiki mcp server**: ervwalter/trendweight |
| 10 | + |
| 11 | +## Architecture |
| 12 | + |
| 13 | +### Monorepo Structure |
| 14 | +- `apps/web/` - React 19 + TypeScript + Vite frontend with TanStack Router |
| 15 | +- `apps/api/` - C# ASP.NET Core 9.0 Web API backend |
| 16 | +- Uses Turborepo with npm workspaces for build orchestration |
| 17 | + |
| 18 | +### Key Technologies |
| 19 | +- **Frontend**: React 19, TypeScript, Vite, TailwindCSS v4, TanStack Router/Query, Clerk auth |
| 20 | +- **Backend**: ASP.NET Core 9.0, C#, Supabase (PostgreSQL), JWT authentication |
| 21 | +- **Deployment**: Docker containers, tmuxinator for development |
| 22 | + |
| 23 | +### Database Schema (Supabase) |
| 24 | +- `user_accounts` - Maps Clerk IDs to internal UUIDs |
| 25 | +- `profiles` - User profiles and settings (JSONB) |
| 26 | +- `provider_links` - OAuth tokens for integrations (JSONB) |
| 27 | +- `source_data` - Raw measurement data (JSONB) |
| 28 | + |
| 29 | +## Development Commands |
| 30 | + |
| 31 | +### Essential Commands (run from repository root) |
| 32 | +```bash |
| 33 | +# Start both frontend and backend dev servers via tmuxinator |
| 34 | +npm run dev |
| 35 | + |
| 36 | +# Stop development servers |
| 37 | +npm run dev:stop |
| 38 | + |
| 39 | +# Build all workspaces |
| 40 | +npm run build |
| 41 | + |
| 42 | +# Run all tests |
| 43 | +npm run test |
| 44 | + |
| 45 | +# Type checking and linting across all workspaces |
| 46 | +npm run check |
| 47 | + |
| 48 | +# Format code |
| 49 | +npm run format |
| 50 | + |
| 51 | +# Install dependencies for all workspaces |
| 52 | +npm install |
| 53 | + |
| 54 | +# Clean all build artifacts and dependencies |
| 55 | +npm run clean |
| 56 | +``` |
| 57 | + |
| 58 | +### Frontend Specific (apps/web/) |
| 59 | +```bash |
| 60 | +# Development server (port 5173) |
| 61 | +npm run -w apps/web dev |
| 62 | + |
| 63 | +# Run tests with coverage |
| 64 | +npm run -w apps/web test:coverage |
| 65 | + |
| 66 | +# Generate TanStack Router routes (run before typecheck) |
| 67 | +npm run -w apps/web generate-routes |
| 68 | + |
| 69 | +# Type checking with route generation |
| 70 | +npm run -w apps/web typecheck |
| 71 | + |
| 72 | +# Lint with ESLint |
| 73 | +npm run -w apps/web lint |
| 74 | +``` |
| 75 | + |
| 76 | +### Backend Specific (apps/api/) |
| 77 | +```bash |
| 78 | +# Development server with hot reload (port 5199) |
| 79 | +npm run -w apps/api dev |
| 80 | + |
| 81 | +# Build the solution |
| 82 | +npm run -w apps/api build |
| 83 | + |
| 84 | +# Run tests |
| 85 | +npm run -w apps/api test |
| 86 | + |
| 87 | +# Format C# code |
| 88 | +npm run -w apps/api format |
| 89 | + |
| 90 | +# Lint (build with warnings as errors) |
| 91 | +npm run -w apps/api lint |
| 92 | +``` |
| 93 | + |
| 94 | +### Docker |
| 95 | +```bash |
| 96 | +# Build production Docker image |
| 97 | +npm run docker:build |
| 98 | + |
| 99 | +# Run container locally (port 8080) |
| 100 | +npm run docker:run |
| 101 | +``` |
| 102 | + |
| 103 | +## Code Organization |
| 104 | + |
| 105 | +### Backend (Feature-Based) |
| 106 | +``` |
| 107 | +apps/api/TrendWeight/ |
| 108 | +├── Features/ # Feature-based organization |
| 109 | +│ ├── Auth/ # Authentication infrastructure |
| 110 | +│ ├── Profile/ # User profile management |
| 111 | +│ ├── Measurements/ # Weight data management |
| 112 | +│ └── Providers/ # Withings/Fitbit integrations |
| 113 | +└── Infrastructure/ # Cross-cutting concerns |
| 114 | + ├── Auth/ # JWT authentication handlers |
| 115 | + └── DataAccess/ # Supabase data access layer |
| 116 | +``` |
| 117 | + |
| 118 | +### Frontend (File-Based Routing) |
| 119 | +``` |
| 120 | +apps/web/src/ |
| 121 | +├── components/ # Shared UI components (PascalCase) |
| 122 | +│ └── ui/ # shadcn/ui components |
| 123 | +├── lib/ # Core utilities and API client |
| 124 | +│ ├── auth/ # Authentication utilities |
| 125 | +│ └── api/ # API client and hooks |
| 126 | +├── routes/ # TanStack Router pages (auto-generated routing) |
| 127 | +│ ├── __root.tsx # Root layout |
| 128 | +│ ├── dashboard.tsx # Main dashboard |
| 129 | +│ └── oauth/ # OAuth callback handlers |
| 130 | +└── types/ # TypeScript type definitions |
| 131 | +``` |
| 132 | + |
| 133 | +## Naming Conventions |
| 134 | + |
| 135 | +- **Project Name**: TrendWeight (capital T, capital W, no space) |
| 136 | +- **Frontend**: PascalCase for components, camelCase for variables/functions |
| 137 | +- **Backend**: PascalCase for public members, camelCase for private/parameters |
| 138 | +- **Database**: snake_case for table and column names |
| 139 | +- **Routes**: kebab-case for route files |
| 140 | + |
| 141 | +## Testing |
| 142 | + |
| 143 | +### Frontend (Vitest + React Testing Library) |
| 144 | +- Test files: `*.test.ts(x)` colocated with components |
| 145 | +- Setup: `src/test/setup.ts` |
| 146 | +- Coverage: `npm run -w apps/web test:coverage` |
| 147 | + |
| 148 | +### Backend (xUnit + FluentAssertions + Moq) |
| 149 | +- Integration tests use `WebApplicationFactory<Program>` |
| 150 | +- Run: `npm run -w apps/api test` |
| 151 | + |
| 152 | +## Authentication & Security |
| 153 | + |
| 154 | +- **Frontend**: Clerk React SDK with social logins (Google, Microsoft, Apple) |
| 155 | +- **Backend**: JWT validation via Clerk JWKS endpoints |
| 156 | +- **Database**: User mapping via `user_accounts` table |
| 157 | +- **Route Protection**: `requireAuth` guards at route level |
| 158 | + |
| 159 | +## Environment Setup |
| 160 | + |
| 161 | +Required environment variables (see `.env.example`): |
| 162 | +``` |
| 163 | +# Frontend (Vite) |
| 164 | +VITE_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key |
| 165 | +VITE_SUPABASE_URL=https://your-project-ref.supabase.co |
| 166 | +VITE_SUPABASE_ANON_KEY=your_supabase_anon_key |
| 167 | +
|
| 168 | +# Backend (ASP.NET Core) |
| 169 | +Clerk__Authority=https://your-instance.clerk.accounts.dev |
| 170 | +Clerk__SecretKey=your_clerk_secret_key |
| 171 | +Supabase__Url=https://your-project-ref.supabase.co |
| 172 | +Supabase__AnonKey=your_supabase_anon_key |
| 173 | +Supabase__ServiceKey=your_supabase_service_role_key |
| 174 | +``` |
| 175 | + |
| 176 | +## Important Notes |
| 177 | + |
| 178 | +- **Import Aliases**: Frontend uses `@/` alias for `src/` imports |
| 179 | +- **Route Generation**: TanStack Router routes auto-generated from file structure |
| 180 | +- **Hot Reload**: Backend uses `dotnet watch`, frontend uses Vite HMR |
| 181 | +- **Code Quality**: Husky pre-commit hooks run formatting and linting |
| 182 | +- **No PRs**: Changes are pushed directly to main branch by maintainer |
| 183 | + |
| 184 | +## Deployment |
| 185 | + |
| 186 | +- Production deploys as Docker container on port 8080 |
| 187 | +- Container serves both frontend static files and API endpoints |
| 188 | +- Uses YARP reverse proxy to route requests between API and static content |
| 189 | +- read the files in @docs/steering/ for guidance on the project |
0 commit comments