
- Fixed configparser.InterpolationSyntaxError by simplifying alembic.ini format strings - Updated env.py to handle configuration parsing errors gracefully - Added proper exception handling for logging configuration - Ensured database directory creation before migrations - Added fallback engine creation if config parsing fails - Simplified formatter configuration to avoid interpolation issues The migration system now handles deployment environments more robustly.
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 registrationPOST /api/v1/auth/login
- User login
Users
GET /api/v1/users/me
- Get current user profilePUT /api/v1/users/me
- Update user profileGET /api/v1/users/me/memberships
- Get user gym membershipsGET /api/v1/users/me/subscriptions
- Get user subscriptions
Gyms
GET /api/v1/gyms/
- List all gymsGET /api/v1/gyms/{gym_id}
- Get gym detailsPOST /api/v1/gyms/{gym_id}/join
- Join a gymGET /api/v1/gyms/{gym_id}/membership-plans
- Get gym membership plansPOST /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 plansGET /api/v1/memberships/plans/{plan_id}
- Get plan detailsPOST /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 subscriptionsGET /api/v1/subscriptions/{subscription_id}
- Get subscription detailsPOST /api/v1/subscriptions/
- Create subscriptionPOST /api/v1/subscriptions/{subscription_id}/cancel
- Cancel subscriptionPUT /api/v1/subscriptions/{subscription_id}
- Update subscription (Admin only)
Payments
POST /api/v1/payments/initialize
- Initialize paymentPOST /api/v1/payments/verify/{transaction_id}
- Verify paymentGET /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:
# 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
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables (see Environment Variables section above)
-
Run database migrations:
alembic upgrade head
-
Start the application:
uvicorn main:app --reload
-
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 accessgyms
- Gym information and detailsmembership_plans
- Available membership plans per gymgym_memberships
- User-gym relationshipssubscriptions
- User subscriptions to membership planstransactions
- 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:
ruff check .
ruff format .
License
This project was generated by BackendIM, an AI-powered backend generation platform.
Description
Languages
Python
99.2%
Mako
0.8%