# Gym Membership Management System A comprehensive FastAPI-based platform for gyms to manage member data and subscriptions with integrated payment processing. ## Features - **User Management**: User registration, authentication, and profile management - **Gym Management**: Multi-gym support with gym registration and management - **Membership Plans**: Flexible membership plan creation and management - **Subscription Management**: Handle user subscriptions to membership plans - **Payment Integration**: Support for Stripe and Paystack payment gateways - **Multi-level Admin Access**: - Admin: Can manage users, gyms, memberships, and subscriptions - Super Admin: Full access including financial data and admin management - **Role-based Access Control**: Different permission levels for users, admins, and super admins ## Tech Stack - **Backend**: FastAPI (Python) - **Database**: SQLite with SQLAlchemy ORM - **Authentication**: JWT tokens with bcrypt password hashing - **Migrations**: Alembic for database migrations - **Payment Gateways**: Stripe and Paystack integration - **Code Quality**: Ruff for linting and formatting ## Project Structure ``` ├── app/ │ ├── api/v1/endpoints/ # API endpoints │ ├── core/ # Core configurations and security │ ├── db/ # Database configuration │ ├── models/ # SQLAlchemy models │ ├── schemas/ # Pydantic schemas │ └── services/ # Business logic services ├── alembic/ # Database migrations ├── main.py # FastAPI application entry point └── requirements.txt # Python dependencies ``` ## API Endpoints ### Authentication - `POST /api/v1/auth/register` - User registration - `POST /api/v1/auth/login` - User login ### Users - `GET /api/v1/users/me` - Get current user profile - `PUT /api/v1/users/me` - Update user profile - `GET /api/v1/users/me/memberships` - Get user gym memberships - `GET /api/v1/users/me/subscriptions` - Get user subscriptions ### Gyms - `GET /api/v1/gyms/` - List all gyms - `GET /api/v1/gyms/{gym_id}` - Get gym details - `POST /api/v1/gyms/{gym_id}/join` - Join a gym - `GET /api/v1/gyms/{gym_id}/membership-plans` - Get gym membership plans - `POST /api/v1/gyms/` - Create gym (Admin only) - `PUT /api/v1/gyms/{gym_id}` - Update gym (Admin only) ### Membership Plans - `GET /api/v1/memberships/plans` - List membership plans - `GET /api/v1/memberships/plans/{plan_id}` - Get plan details - `POST /api/v1/memberships/plans` - Create plan (Admin only) - `PUT /api/v1/memberships/plans/{plan_id}` - Update plan (Admin only) - `DELETE /api/v1/memberships/plans/{plan_id}` - Deactivate plan (Admin only) ### Subscriptions - `GET /api/v1/subscriptions/` - Get user subscriptions - `GET /api/v1/subscriptions/{subscription_id}` - Get subscription details - `POST /api/v1/subscriptions/` - Create subscription - `POST /api/v1/subscriptions/{subscription_id}/cancel` - Cancel subscription - `PUT /api/v1/subscriptions/{subscription_id}` - Update subscription (Admin only) ### Payments - `POST /api/v1/payments/initialize` - Initialize payment - `POST /api/v1/payments/verify/{transaction_id}` - Verify payment - `GET /api/v1/payments/transactions` - Get user transactions ### Admin - `GET /api/v1/admin/users` - List all users (Admin only) - `GET /api/v1/admin/users/{user_id}` - Get user details (Admin only) - `GET /api/v1/admin/users/{user_id}/subscriptions` - Get user subscriptions (Admin only) - `GET /api/v1/admin/users/{user_id}/transactions` - Get user transactions (Super Admin only) - `GET /api/v1/admin/stats/overview` - Get overview statistics (Admin only) - `GET /api/v1/admin/stats/financial` - Get financial statistics (Super Admin only) - `GET /api/v1/admin/transactions` - Get all transactions (Super Admin only) - `POST /api/v1/admin/invite-admin` - Invite new admin (Super Admin only) - `DELETE /api/v1/admin/remove-admin/{admin_id}` - Remove admin (Super Admin only) - `GET /api/v1/admin/admins` - List all admins (Super Admin only) ## Environment Variables Set the following environment variables for production use: ```env # Security SECRET_KEY=your-secret-key-here # Stripe Payment Gateway STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key STRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key # Paystack Payment Gateway PAYSTACK_SECRET_KEY=sk_test_your_paystack_secret_key PAYSTACK_PUBLIC_KEY=pk_test_your_paystack_public_key ``` ## Installation and Setup 1. **Install dependencies**: ```bash pip install -r requirements.txt ``` 2. **Set up environment variables** (see Environment Variables section above) 3. **Run database migrations**: ```bash alembic upgrade head ``` 4. **Start the application**: ```bash uvicorn main:app --reload ``` 5. **Access the API**: - API Documentation: http://localhost:8000/docs - Alternative Docs: http://localhost:8000/redoc - OpenAPI Schema: http://localhost:8000/openapi.json - Health Check: http://localhost:8000/health ## Database The application uses SQLite with the database file stored at `/app/storage/db/db.sqlite`. The database includes the following main tables: - `users` - User accounts with role-based access - `gyms` - Gym information and details - `membership_plans` - Available membership plans per gym - `gym_memberships` - User-gym relationships - `subscriptions` - User subscriptions to membership plans - `transactions` - Payment transaction records ## Payment Integration The system supports two payment gateways: ### Stripe - Handles payments in USD - Uses Payment Intents for secure processing - Requires STRIPE_SECRET_KEY and STRIPE_PUBLISHABLE_KEY ### Paystack - Handles payments in NGN (Nigerian Naira) - Uses transaction initialization and verification - Requires PAYSTACK_SECRET_KEY and PAYSTACK_PUBLIC_KEY ## Security Features - JWT-based authentication - Password hashing with bcrypt - Role-based access control (User, Admin, Super Admin) - CORS configuration for cross-origin requests - Input validation with Pydantic schemas ## Development Run the linter to ensure code quality: ```bash ruff check . ruff format . ``` ## License This project was generated by BackendIM, an AI-powered backend generation platform.