### Frontend Setup (Local Development)
Source: https://codewithcj.github.io/SparkyFitness/developer/getting-started
Steps to set up the frontend application locally, including dependency installation and starting the development server.
```bash
# Navigate to project root
cd ..
# Install dependencies
npm install
# Start development server
npm run dev
```
--------------------------------
### Backend Setup (Local Development)
Source: https://codewithcj.github.io/SparkyFitness/developer/getting-started
Steps to set up the backend server locally, including dependency installation, environment configuration, and starting the server.
```bash
# Navigate to server directory
cd SparkyFitnessServer
# Install dependencies
npm install
# Copy and configure environment
cp .env.example .env
# Edit .env with your database credentials
# Run database migrations
npm run migrate
# Start development server
npm run dev
```
--------------------------------
### Production Environment Setup
Source: https://codewithcj.github.io/SparkyFitness/developer/getting-started
Starting the production stack using Docker, with details on the available service and features.
```bash
# Start production stack
./docker/docker-helper.sh prod up
# Service available:
# - Application: http://localhost:3004 (nginx proxy)
```
--------------------------------
### Development Environment Setup
Source: https://codewithcj.github.io/SparkyFitness/developer/getting-started
Starting the development stack using Docker, with details on available services and features.
```bash
# Start development stack
./docker/docker-helper.sh dev up
# Services available:
# - Frontend: http://localhost:8080 (live reload)
# - Backend: http://localhost:3010 (direct access)
# - Database: localhost:5432 (direct access)
```
--------------------------------
### Quick Start with Docker
Source: https://codewithcj.github.io/SparkyFitness/developer/getting-started
Cloning the repository, setting up the environment, and starting the development server using Docker.
```bash
# Clone the repository
git clone https://github.com/CodeWithCJ/SparkyFitness.git
cd SparkyFitness
# Copy environment template
cp docker/.env.example .env
# Start development environment (with live reloading)
./docker/docker-helper.sh dev up
# Access the application at http://localhost:8080
```
--------------------------------
### Quick Start Development Environment Setup
Source: https://codewithcj.github.io/SparkyFitness/developer/contributing
Commands to fork, clone, set up environment variables, and start the development environment.
```bash
git clone https://github.com/CodeWithCJ/SparkyFitness.git
cd SparkyFitness
cp docker/.env.example .env
./docker/docker-helper.sh dev up
```
--------------------------------
### Database Setup (Local Development)
Source: https://codewithcj.github.io/SparkyFitness/developer/getting-started
SQL commands to create the database and user for local development.
```sql
CREATE DATABASE sparkyfitness;
CREATE USER sparky WITH PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE sparkyfitness TO sparky;
```
--------------------------------
### Copy Environment Template
Source: https://codewithcj.github.io/SparkyFitness/developer/getting-started
Command to copy the example environment file for configuration.
```bash
cp docker/.env.example .env
```
--------------------------------
### Start SparkyFitness Application
Source: https://codewithcj.github.io/SparkyFitness/install/docker-compose
Pulls the latest Docker images and starts the application services in detached mode.
```bash
docker compose pull && docker compose up -d
```
--------------------------------
### Download Docker Compose and Environment Files
Source: https://codewithcj.github.io/SparkyFitness/install/docker-compose
Creates a directory, navigates into it, and downloads the production Docker Compose file and an example environment file.
```bash
mkdir sparkyfitness && cd sparkyfitness
curl -o docker-compose.yml https://github.com/CodeWithCJ/SparkyFitness/releases/latest/download/docker-compose.prod.yml
curl -L -o .env https://github.com/CodeWithCJ/SparkyFitness/releases/latest/download/default.env.example
```
--------------------------------
### Environment Configuration Example
Source: https://codewithcj.github.io/SparkyFitness/install/external-database
Example of how to configure the .env file to point to an external PostgreSQL database.
```dotenv
SPARKY_FITNESS_DB_HOST=your-db-host
SPARKY_FITNESS_DB_NAME=sparkyfitness_db
SPARKY_FITNESS_DB_USER=sparky_admin
SPARKY_FITNESS_DB_PASSWORD=your_secure_password
SPARKY_FITNESS_DB_PORT=5432
```
--------------------------------
### Manual Docker Compose Commands
Source: https://codewithcj.github.io/SparkyFitness/developer/getting-started
Commands for managing the Docker Compose environment, including production and development setups, stopping services, and viewing logs.
```bash
# Production deployment
docker-compose -f docker/docker-compose.prod.yml up -d
# Development with live reloading
docker-compose -f docker/docker-compose.dev.yml up
# Stop services
docker-compose down
# View logs
docker-compose logs -f [service_name]
```
--------------------------------
### PostgreSQL Extensions Installation
Source: https://codewithcj.github.io/SparkyFitness/install/external-database
SQL commands to connect to the database and create required PostgreSQL extensions, along with granting execute permissions.
```sql
\c sparkyfitness_db
-- Standard extensions
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
-- Performance monitoring
CREATE EXTENSION IF NOT EXISTS "pg_stat_statements";
-- Grant with grant to functions that extensions add as they are still owned by postgres
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO "sparky_admin" WITH GRANT OPTION;
```
--------------------------------
### Example Translation JSON
Source: https://codewithcj.github.io/SparkyFitness/developer/translations
An example of a translation.json file structure, showing nested objects for organizing translations.
```json
{
"nav": {
"diary": "Diary",
"checkin": "Check-In"
},
"settings": {
"profileInformation": {
"title": "Profile Information"
}
}
}
```
--------------------------------
### Docker Helper Script Commands
Source: https://codewithcj.github.io/SparkyFitness/developer/getting-started
Common commands for managing the SparkyFitness development and production environments using the Docker helper script.
```bash
# Show all available commands and help
./docker/docker-helper.sh help
# Start development environment
./docker/docker-helper.sh dev up
# Start production environment
./docker/docker-helper.sh prod up
# View logs
./docker/docker-helper.sh logs
# Stop services
./docker/docker-helper.sh down
# Clean up everything
./docker/docker-helper.sh clean
```
--------------------------------
### Start SparkyFitness Services
Source: https://codewithcj.github.io/SparkyFitness/administration/manual_backup_restore
Command to start the SparkyFitness services using Docker Compose.
```bash
docker compose up -d
```
--------------------------------
### Repository Pattern Example
Source: https://codewithcj.github.io/SparkyFitness/developer/contributing
Example demonstrating the repository pattern for database operations, including transaction management.
```javascript
// All database operations use repository pattern
const userRepository = {
async createUser(userData) {
const client = await pool.connect();
try {
await client.query('BEGIN');
// Database operations
await client.query('COMMIT');
return result;
} catch (error) {
await client.query('ROLLBACK');
throw error;
} finally {
client.release();
}
}
};
```
--------------------------------
### Helm Installation Commands
Source: https://codewithcj.github.io/SparkyFitness/install/kubernetes
Commands to install SparkyFitness using Helm, either directly from OCI registry or from source, with an option for custom values.
```bash
# 1. Install with default settings (bundled PostgreSQL, no ingress)
helm install sparkyfitness oci://ghcr.io/codewithcj/charts/sparkyfitness
# -- OR install directly from source --
git clone https://github.com/CodeWithCJ/SparkyFitness.git
helm install sparkyfitness ./SparkyFitness/helm/chart
# 2. (Optional) Customize values
helm install sparkyfitness ./SparkyFitness/helm/chart -f my-values.yaml
# 3. Access the application in browser via Ingress or HTTPRoute you've specified in values
```
--------------------------------
### Stop and Remove SparkyFitness Services and Volumes
Source: https://codewithcj.github.io/SparkyFitness/install/docker-compose
Stops and removes all services, networks, and volumes, including database data.
```bash
docker compose down -v
```
--------------------------------
### Weight Data Example
Source: https://codewithcj.github.io/SparkyFitness/developer/api-reference
Example of submitting weight data.
```json
[
{
"value": 70.5,
"type": "weight",
"date": "2025-08-19"
}
]
```
--------------------------------
### Claude Desktop Example Configuration
Source: https://codewithcj.github.io/SparkyFitness/features/mcp-server
Example configuration for connecting Claude Desktop to the SparkyFitness MCP server, including server URL and authorization header.
```json
{
"mcpServers": {
"sparky-fitness": {
"serverURL": "http://localhost:3001/mcp",
"headers": {
"Authorization": "Bearer YOUR_SPARKY_FITNESS_API_KEY"
}
}
}
}
```
--------------------------------
### Bring Up All Containers
Source: https://codewithcj.github.io/SparkyFitness/install/postgres-upgrade
Starts the 'sparkyfitness-db' container in detached mode.
```bash
docker compose up -d sparkyfitness-db
```
--------------------------------
### Steps Data Example
Source: https://codewithcj.github.io/SparkyFitness/developer/api-reference
Example of submitting step count data.
```json
[
{
"value": 10000,
"type": "step",
"date": "2025-08-19"
}
]
```
--------------------------------
### Port Conflict Troubleshooting
Source: https://codewithcj.github.io/SparkyFitness/developer/getting-started
Commands to check which processes are using specific ports, useful for resolving port conflicts.
```bash
# Check port usage
lsof -i :8080 # Frontend
lsof -i :3010 # Backend
lsof -i :5432 # Database
```
--------------------------------
### Database and User Configuration
Source: https://codewithcj.github.io/SparkyFitness/install/external-database
SQL commands to create the database, the database owner user, and grant necessary ownership and privileges.
```sql
-- 1. Create the Database
CREATE DATABASE sparkyfitness_db;
-- 2. Create the DB Owner user (referenced in .env as SPARKY_FITNESS_DB_USER)
CREATE USER sparky_admin WITH PASSWORD 'your_secure_password';
-- 3. Grant database ownership
ALTER DATABASE sparkyfitness_db OWNER TO sparky_admin;
-- 4. Grant Role Creation privilege
-- This allows the DB Owner to automatically create the App User during setup
ALTER USER sparky_admin CREATEROLE;
-- 5. Special Note for PostgreSQL 15+
-- Since PG 15, the default 'public' schema permissions have changed.
-- You may need to explicitly grant create permissions to the owner:
GRANT ALL ON SCHEMA public TO sparky_admin;
```
--------------------------------
### Execute commands in containers
Source: https://codewithcj.github.io/SparkyFitness/developer/troubleshooting
Examples of executing shell commands within different SparkyFitness Docker containers.
```bash
# Frontend container
docker exec -it sparkyfitness-frontend-1 sh
# Backend container
docker exec -it sparkyfitness-server-1 sh
# Database container
docker exec -it sparkyfitness-db-1 psql -U sparky -d sparkyfitness_db
```
--------------------------------
### Adding User to Docker Group
Source: https://codewithcj.github.io/SparkyFitness/developer/getting-started
Command to add the current user to the Docker group to resolve potential permission issues.
```bash
sudo usermod -aG docker $USER
# Log out and back in
```
--------------------------------
### Water Intake Data Example
Source: https://codewithcj.github.io/SparkyFitness/developer/api-reference
Example of submitting water intake data.
```json
[
{
"value": 500,
"type": "water",
"date": "2025-08-19"
}
]
```
--------------------------------
### Active Calories Data Example
Source: https://codewithcj.github.io/SparkyFitness/developer/api-reference
Example of submitting active calories data.
```json
[
{
"value": 500,
"type": "Active Calories",
"date": "2025-08-19"
}
]
```
--------------------------------
### Transaction Management in Migrations
Source: https://codewithcj.github.io/SparkyFitness/developer/database
Example of using BEGIN and COMMIT for atomic database migrations.
```sql
BEGIN;
-- All migration statements here
-- If any statement fails, entire migration rolls back
COMMIT;
```
--------------------------------
### Example Migration SQL
Source: https://codewithcj.github.io/SparkyFitness/developer/database
SQL content for a new migration file, including table creation, RLS policy, and version tracking.
```sql
-- Migration: Add meal planning functionality
-- Version: 2024_03_15_14_20
BEGIN;
-- Create meal plans table
CREATE TABLE meal_plans (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
name VARCHAR(255) NOT NULL,
planned_date DATE NOT NULL,
total_calories DECIMAL(10,2),
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Enable RLS
ALTER TABLE meal_plans ENABLE ROW LEVEL SECURITY;
-- Create RLS policy
CREATE POLICY meal_plans_user_policy ON meal_plans
FOR ALL USING (user_id = auth.uid());
-- Create indexes
CREATE INDEX idx_meal_plans_user_date ON meal_plans(user_id, planned_date);
-- Update migration version
INSERT INTO migrations (version, applied_at)
VALUES ('2024_03_15_14_20', NOW());
COMMIT;
```
--------------------------------
### Migration File Naming Convention
Source: https://codewithcj.github.io/SparkyFitness/developer/database
Example of the naming pattern for migration files.
```bash
YYYY_MM_DD_HH_MM_description.sql
```
--------------------------------
### Check rate limit configuration
Source: https://codewithcj.github.io/SparkyFitness/developer/troubleshooting
Example of rate limiting configuration in nginx.conf.template.
```nginx
limit_req_zone $binary_remote_addr zone=login_signup_zone:10m rate=5r/s;
```
--------------------------------
### Backend Zod Schema Validation Example
Source: https://codewithcj.github.io/SparkyFitness/developer/contributing
Example demonstrating how to define Zod schemas for request validation in a Node.js/Express backend.
```typescript
import { z } from 'zod';
// Define schemas
const createUserSchema = z.object({
email: z.string().email(),
name: z.string().min(1),
password: z.string().min(8)
});
// Use in route
app.post('/api/users', async (req, res) => {
const validated = createUserSchema.parse(req.body);
// ... rest of handler
});
```
--------------------------------
### Progress Summary Response Template
Source: https://codewithcj.github.io/SparkyFitness/developer/advanced/ai-command-patterns
A template for displaying a user's daily progress summary, including consumed amounts versus goals for key metrics.
```string
"Here's your progress for today:
**Calories:** [consumed]/[goal] ([percentage]%)
**Protein:** [consumed]g/[goal]g ([percentage]%)
**Carbs:** [consumed]g/[goal]g ([percentage]%)
**Fat:** [consumed]g/[goal]g ([percentage]%)
[motivational message based on progress]"
```
--------------------------------
### Integration into React Application
Source: https://codewithcj.github.io/SparkyFitness/developer/translations
The main entry point (src/main.tsx) showing how to import the i18n configuration and wrap the application with Suspense for translation loading.
```typescript
import { createRoot } from 'react-dom/client'
import App from './App.tsx'
import './index.css'
import { BrowserRouter } from 'react-router-dom';
import { AuthProvider } from './hooks/useAuth.tsx';
import './i18n'; // Import the i18n configuration
import { Suspense } from 'react';
createRoot(document.getElementById("root")!).render(