@@ -8,6 +8,7 @@ This document provides guidelines and instructions for contributing to the Worko
88
99- [ Node.js] ( https://nodejs.org/ ) (LTS version recommended)
1010- [ pnpm] ( https://pnpm.io/ ) (for package management)
11+ - [ Supabase CLI] ( https://supabase.com/docs/guides/cli ) (for database migrations)
1112
1213### Getting Started
1314
@@ -24,16 +25,112 @@ This document provides guidelines and instructions for contributing to the Worko
2425 pnpm install
2526 ```
2627
27- 3 . Start the development server
28+ 3 . Set up Supabase (optional, for backend development)
29+
30+ If you're working with the Supabase backend, you'll need to set up your local environment:
31+
32+ ``` bash
33+ # Install Supabase CLI if you haven't already
34+ npm install -g supabase
35+
36+ # Login to Supabase
37+ supabase login
38+
39+ # Link to your Supabase project (get the reference ID from the project settings)
40+ supabase link --project-ref your-project-ref
41+ ```
42+
43+ 4 . Start the development server
2844 ``` bash
2945 pnpm dev
3046 ```
3147
3248The application will be available at ` http://localhost:5173 ` by default.
3349
50+ ## Working with Supabase
51+
52+ ### Database Migrations
53+
54+ The project uses Supabase migrations to manage database schema changes. Migrations are stored in the ` supabase/migrations/ ` directory.
55+
56+ #### Creating a New Migration
57+
58+ To create a new migration:
59+
60+ ``` bash
61+ cd app
62+ supabase migration new name_of_migration
63+ ```
64+
65+ This will create a new SQL file in the ` supabase/migrations/ ` directory with a timestamp prefix.
66+
67+ #### Checking Migration Status
68+
69+ To see which migrations have been applied locally and remotely:
70+
71+ ``` bash
72+ supabase migration list
73+ ```
74+
75+ #### Applying Migrations
76+
77+ To apply pending migrations to your local database:
78+
79+ ``` bash
80+ supabase migration up
81+ ```
82+
83+ To push migrations to the remote Supabase instance:
84+
85+ ``` bash
86+ supabase db push
87+ ```
88+
89+ #### Troubleshooting Migrations
90+
91+ If you encounter issues with migration synchronization between local and remote databases:
92+
93+ 1 . List the current migration status:
94+ ``` bash
95+ supabase migration list
96+ ```
97+
98+ 2 . Repair migration history if needed:
99+ ``` bash
100+ # Mark a migration as reverted
101+ supabase migration repair --status reverted < migration_version>
102+
103+ # Mark a migration as applied
104+ supabase migration repair --status applied < migration_version>
105+ ```
106+
107+ 3 . Pull the current database schema:
108+ ``` bash
109+ supabase db pull
110+ ```
111+
112+ ### Environment Variables for Supabase
113+
114+ Create a ` .env ` file in the ` app ` directory with your Supabase credentials:
115+
116+ ``` bash
117+ # Supabase connection
118+ SUPABASE_URL=your_supabase_url
119+ SUPABASE_ANON_KEY=your_supabase_anon_key
120+ SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
121+
122+ # For subscription functionality
123+ STRIPE_SECRET_KEY=your_stripe_secret_key
124+ STRIPE_WEBHOOK_SECRET=your_stripe_webhook_secret
125+ ```
126+
127+ See ` STRIPE_SETUP.md ` for more details on setting up the subscription system.
128+
34129## Project Structure
35130
36- - ` src/lib/ ` - Contains core functionality:
131+ The project code is in the ` app/ ` directory. All commands should be run from this directory. Console commands will automatically be run in the app/ directory.
132+
133+ - ` src/lib/ ` - Contains core functionality (service layer):
37134
38135 - ` types.ts ` - TypeScript type definitions
39136 - ` database.ts ` - IndexedDB database interactions via Dexie
@@ -43,16 +140,35 @@ The application will be available at `http://localhost:5173` by default.
43140 - ` equipment.ts ` - Equipment enums
44141 - ` components/ ` - Reusable Svelte components
45142 - ` exercise_data/ ` - Exercise definitions by category
143+ - ` server/ ` - Server-side code for API endpoints
46144
47145- ` src/routes/ ` - SvelteKit routes:
48146 - ` / ` - Home page
49147 - ` /exercises/ ` - Exercise catalog
50148 - ` /workout/ ` - Workout planning and tracking
51149 - ` /history/ ` - Exercise history and reporting
52150 - ` /guidelines/ ` - Training guidelines
151+ - ` /api/ ` - Server API endpoints
152+
153+ Business logic should reside mainly in the lib folder (service layer) so templates can remain thin.
53154
54155## Coding Standards
55156
157+ ### Package Management
158+
159+ This project uses pnpm for package management. Always use pnpm commands for installing, updating, or removing dependencies:
160+
161+ ``` bash
162+ # Install dependencies
163+ pnpm install
164+
165+ # Add a new dependency
166+ pnpm add < package-name>
167+
168+ # Add a dev dependency
169+ pnpm add -D < package-name>
170+ ```
171+
56172### Svelte 5 Runes
57173
58174This project uses Svelte 5 with the new runes syntax. Use ` $state() ` , ` $derived() ` , etc. instead of the older ` $: ` reactive syntax:
@@ -72,6 +188,8 @@ This project uses Svelte 5 with the new runes syntax. Use `$state()`, `$derived(
72188### Imports
73189
74190- Prefer absolute imports from ` $lib ` over relative imports
191+ - Don't mix absolute and relative imports
192+ - Relative imports in the same directory are acceptable
75193- Use consistent import ordering (built-ins, then external packages, then internal modules)
76194
77195``` ts
@@ -86,6 +204,10 @@ import type { WorkoutItem } from "../lib/types"; // Bad: relative import
86204import { saveCompletedExercise } from " $lib/database" ;
87205```
88206
207+ ### UI Components
208+
209+ We use Tailwind CSS for styles and daisyUI for semantic components. Where possible, prefer daisyUI components for clean template code.
210+
89211### Semantic Element Naming
90212
91213Add semantic classes or IDs to important DOM elements for testing and self-documentation:
@@ -111,16 +233,16 @@ Add semantic classes or IDs to important DOM elements for testing and self-docum
111233Run only unit tests during development (faster than running all tests):
112234
113235``` bash
114- cd app
115236pnpm test:unit
116237```
117238
239+ When improving unit test coverage, run only the unit tests since running e2e tests may be unnecessary.
240+
118241### End-to-End Tests
119242
120243Run end-to-end tests when needed:
121244
122245``` bash
123- cd app
124246pnpm test:e2e
125247```
126248
@@ -129,7 +251,6 @@ pnpm test:e2e
129251Run all tests before submitting PRs:
130252
131253``` bash
132- cd app
133254pnpm test
134255```
135256
0 commit comments