You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# GymFlow - Gym Management System
A comprehensive, full-stack gym management system built with Next.js, TypeScript, Tailwind CSS, and Supabase PostgreSQL.
## Features
- **Role-Based Access Control**: Admin, Trainer, and Member roles with appropriate permissions
- **Member Management**: Complete member profiles, memberships, and status tracking
- **Trainer Management**: Trainer profiles, certifications, and member assignments
- **Membership Plans**: Flexible plans with duration and pricing
- **Attendance Tracking**: Member check-ins and trainer shift management
- **Payment Processing**: Invoice generation, payment tracking, and status management
- **Equipment Management**: Inventory tracking and maintenance scheduling
- **Class Scheduling**: Fitness classes with booking system and capacity management
- **Dashboard Analytics**: KPIs, charts, and business insights
- **CSV Export**: Export members, attendance, and payment data
## Tech Stack
- **Frontend**: Next.js 13 (App Router), React 18, TypeScript
- **Styling**: Tailwind CSS, shadcn/ui components
- **Database**: Supabase PostgreSQL
- **Charts**: Recharts
- **Authentication**: Custom auth with Supabase
- **State Management**: React Context API
## Database Schema
### Core Tables
- `roles` - User roles (Admin, Trainer, Member)
- `users` - User authentication and profile data
- `members` - Extended member information
- `trainers` - Extended trainer information
- `membership_plans` - Available membership plans
- `member_memberships` - Active/historical memberships
- `trainer_members` - Trainer-member assignments
- `attendance` - Check-in records
- `invoices` - Billing records
- `payments` - Payment records
- `equipment` - Equipment inventory
- `maintenance_logs` - Equipment maintenance history
- `classes` - Scheduled fitness classes
- `class_bookings` - Member class bookings
## Getting Started
### Prerequisites
- Node.js 18+ installed
- A Supabase account and project
### Installation
1. Clone the repository
2. Install dependencies:
```bash
npm install
```
3. Set up environment variables:
Create a `.env.local` file with your Supabase credentials:
```
NEXT_PUBLIC_SUPABASE_URL=your_supabase_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
```
4. Run the database migrations:
- The migration file is located at `scripts/create_gym_management_schema.sql`
- Apply it through the Supabase dashboard or CLI
5. Seed the database:
```bash
# Run the seed script through Supabase dashboard or CLI
# File: scripts/seed.sql
```
6. Start the development server:
```bash
npm run dev
```
7. Open [http://localhost:3000](http://localhost:3000)
### Demo Accounts
After seeding the database, use these credentials:
- **Admin**: admin@gymflow.com / password123
- **Trainer**: trainer1@gymflow.com / password123
- **Member**: member1@example.com / password123
## Project Structure
```
├── app/ # Next.js app directory
│ ├── attendance/ # Attendance tracking page
│ ├── classes/ # Class scheduling page
│ ├── contact/ # Contact/support page
│ ├── dashboard/ # Main dashboard with analytics
│ ├── equipment/ # Equipment management page
│ ├── login/ # Login page
│ ├── members/ # Member management page
│ ├── payments/ # Payment and invoice page
│ ├── plans/ # Membership plans page
│ ├── profile/ # User profile page
│ ├── trainers/ # Trainer management page
│ └── page.tsx # Home page
├── components/ # React components
│ ├── nav.tsx # Main navigation
│ └── ui/ # shadcn/ui components
├── lib/ # Utility functions
│ ├── auth-context.tsx # Authentication context
│ ├── supabase.ts # Supabase client
│ └── utils.ts # Helper functions
└── scripts/ # Database scripts
└── seed.sql # Sample data seeding
## API Endpoints (via Supabase)
All data operations are performed through Supabase's auto-generated REST API:
### Members
- `GET /rest/v1/members` - List all members
- `POST /rest/v1/members` - Create a new member
- `PATCH /rest/v1/members?id=eq.{id}` - Update a member
- `DELETE /rest/v1/members?id=eq.{id}` - Delete a member
### Trainers
- `GET /rest/v1/trainers` - List all trainers
- `POST /rest/v1/trainers` - Create a new trainer
### Membership Plans
- `GET /rest/v1/membership_plans` - List all plans
- `POST /rest/v1/membership_plans` - Create a new plan
### Attendance
- `GET /rest/v1/attendance` - List attendance records
- `POST /rest/v1/attendance` - Record a check-in
### Invoices
- `GET /rest/v1/invoices` - List all invoices
- `POST /rest/v1/invoices` - Create an invoice
### Payments
- `GET /rest/v1/payments` - List all payments
- `POST /rest/v1/payments` - Record a payment
### Classes
- `GET /rest/v1/classes` - List all classes
- `POST /rest/v1/classes` - Create a new class
### Class Bookings
- `GET /rest/v1/class_bookings` - List bookings
- `POST /rest/v1/class_bookings` - Book a class
- `PATCH /rest/v1/class_bookings` - Update booking status
## Dashboard KPIs
The dashboard calculates and displays:
- Total Members (active vs inactive)
- Active Trainers
- Monthly Revenue (MRR)
- Year-to-Date Revenue
- Overdue Invoices
- Today's Check-ins
- Equipment Maintenance Due
- Member Retention Rate
- Weekly Attendance Trends
- Membership Distribution
- Revenue Trends
## Security Features
- Row-Level Security (RLS) policies on all tables
- Role-based access control
- Password hashing (handled in application layer)
- Secure session management
- Protected API routes
## Export Features
The following pages support CSV export:
- Members list
- Attendance records
- Payment/invoice history
## Building for Production
```bash
npm run build
npm run start
```
The application uses Next.js static export mode for deployment.
## Database Queries
### Active Members Count
```sql
SELECT COUNT(*) FROM members
WHERE status = 'Active'
AND id IN (
SELECT member_id FROM member_memberships
WHERE is_active = true
);
```
### Monthly Recurring Revenue
```sql
SELECT SUM(price * 30.0 / duration_days) as mrr
FROM membership_plans mp
JOIN member_memberships mm ON mp.id = mm.plan_id
WHERE mm.is_active = true;
```
### Overdue Invoices
```sql
SELECT COUNT(*) FROM invoices
WHERE status = 'overdue'
OR (status = 'due' AND due_date < CURRENT_DATE);
```
## Contributing
This is a demonstration project. For production use, consider:
- Implementing proper password hashing with bcrypt
- Adding rate limiting
- Implementing email notifications
- Adding payment gateway integration (Stripe)
- Enhanced error handling and logging
- Comprehensive testing suite
- API documentation with Swagger
## License
MIT License
## Support
For questions or issues, please contact support@gymflow.com or use the in-app contact form.
```
# FlexO