first commit

This commit is contained in:
James Pattinson
2025-11-10 13:57:02 +00:00
commit cffb5e8b8e

302
README.md Normal file
View File

@@ -0,0 +1,302 @@
# Swansea Airport Stakeholders' Alliance Membership Management System
A comprehensive membership management system built with FastAPI, MySQL, and Docker.
## Features
- **User Management**: Registration, authentication, and profile management
- **Membership Tiers**: Configurable membership levels with different benefits and fees
- **Payment Processing**: Support for Square payments, cash, and check payments
- **Admin Dashboard**: Complete administrative control over members and payments
- **Event Management**: Create and manage events with RSVP tracking (coming soon)
- **Volunteer Management**: Role assignments, scheduling, and certificates (coming soon)
- **Email Notifications**: Automated notifications via SMTP2GO (coming soon)
## Tech Stack
- **Backend**: FastAPI (Python 3.11)
- **Database**: MySQL 8.0
- **Authentication**: JWT tokens with OAuth2
- **Containerization**: Docker & Docker Compose
- **ORM**: SQLAlchemy
## Project Structure
```
membership/
├── backend/
│ ├── app/
│ │ ├── api/
│ │ │ ├── v1/
│ │ │ │ ├── auth.py # Authentication endpoints
│ │ │ │ ├── users.py # User management
│ │ │ │ ├── tiers.py # Membership tiers
│ │ │ │ ├── memberships.py # Membership management
│ │ │ │ └── payments.py # Payment processing
│ │ │ └── dependencies.py # Auth dependencies
│ │ ├── core/
│ │ │ ├── config.py # Configuration
│ │ │ ├── database.py # Database setup
│ │ │ └── security.py # Security utilities
│ │ ├── models/
│ │ │ └── models.py # Database models
│ │ ├── schemas/
│ │ │ └── schemas.py # Pydantic schemas
│ │ └── main.py # Application entry point
│ ├── Dockerfile
│ └── requirements.txt
├── database/
│ └── init.sql # Database initialization
├── docker-compose.yml
├── .env.example
└── README.md
```
## Getting Started
### Prerequisites
- Docker
- Docker Compose
### Installation
1. **Navigate to the project directory**
2. **The `.env` file is already configured** with default settings. You can customize:
- Square API credentials (for payment processing)
- SMTP2GO API key (for email notifications)
- Database password (if desired)
3. **Start the services**:
```bash
docker-compose up -d
```
4. **Wait for services to be ready** (about 30 seconds for MySQL initialization):
```bash
docker-compose logs -f
```
Press Ctrl+C when you see "Application startup complete"
5. **Access the API**:
- API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
- Alternative Docs: http://localhost:8000/redoc
## Default Credentials
**Admin Account**:
- Email: `admin@swanseaairport.org`
- Password: `admin123`
⚠️ **IMPORTANT**: Change the admin password immediately after first login!
## API Endpoints
### Authentication
- `POST /api/v1/auth/register` - Register new user
- `POST /api/v1/auth/login` - Login (OAuth2 form)
- `POST /api/v1/auth/login-json` - Login (JSON)
### Users
- `GET /api/v1/users/me` - Get current user profile
- `PUT /api/v1/users/me` - Update current user profile
- `GET /api/v1/users/` - List all users (admin)
- `GET /api/v1/users/{id}` - Get user by ID (admin)
- `DELETE /api/v1/users/{id}` - Delete user (admin)
### Membership Tiers
- `GET /api/v1/tiers/` - List all tiers
- `GET /api/v1/tiers/{id}` - Get tier by ID
- `POST /api/v1/tiers/` - Create tier (admin)
- `PUT /api/v1/tiers/{id}` - Update tier (admin)
- `DELETE /api/v1/tiers/{id}` - Delete tier (admin)
### Memberships
- `GET /api/v1/memberships/my-memberships` - Get current user's memberships
- `POST /api/v1/memberships/` - Create membership
- `GET /api/v1/memberships/{id}` - Get membership by ID
- `PUT /api/v1/memberships/{id}` - Update membership (admin)
- `GET /api/v1/memberships/` - List all memberships (admin)
- `DELETE /api/v1/memberships/{id}` - Delete membership (admin)
### Payments
- `GET /api/v1/payments/my-payments` - Get current user's payments
- `POST /api/v1/payments/` - Create payment
- `GET /api/v1/payments/{id}` - Get payment by ID
- `PUT /api/v1/payments/{id}` - Update payment (admin)
- `GET /api/v1/payments/` - List all payments (admin)
- `POST /api/v1/payments/manual-payment` - Record manual payment (admin)
## Docker Compose Commands
### Basic Operations
```bash
# Start all services
docker-compose up -d
# View logs (all services)
docker-compose logs -f
# View logs (specific service)
docker-compose logs -f backend
docker-compose logs -f mysql
# Stop services
docker-compose down
# Stop and remove volumes (clean slate)
docker-compose down -v
# Restart services
docker-compose restart
# Rebuild after code changes
docker-compose up -d --build
# Check service status
docker-compose ps
```
### Database Operations
```bash
# Access MySQL CLI
docker exec -it membership_mysql mysql -u membership_user -pSecureMembershipPass2024! membership_db
# Create backup
docker exec membership_mysql mysqldump -u membership_user -pSecureMembershipPass2024! membership_db > backup_$(date +%Y%m%d_%H%M%S).sql
# Restore database
docker exec -i membership_mysql mysql -u membership_user -pSecureMembershipPass2024! membership_db < backup.sql
```
## API Testing
You can use the interactive API documentation at http://localhost:8000/docs to test endpoints:
1. Register a new user
2. Login to get access token
3. Click "Authorize" button and enter: `Bearer <your_token>`
4. Test protected endpoints
Or use curl:
```bash
# Register
curl -X POST "http://localhost:8000/api/v1/auth/register" \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "password123",
"first_name": "John",
"last_name": "Doe"
}'
# Login
curl -X POST "http://localhost:8000/api/v1/auth/login-json" \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "password123"
}'
# Get profile (replace TOKEN with actual token)
curl -X GET "http://localhost:8000/api/v1/users/me" \
-H "Authorization: Bearer TOKEN"
```
## Default Membership Tiers
The system comes with three pre-configured tiers:
1. **Personal** - £5/year
- Access to member portal
- Meeting notifications
- Event participation
2. **Aircraft Owners** - £25/year
- All Personal benefits
- Priority event registration
- Aircraft owner resources
3. **Corporate** - £100/year
- All benefits
- Corporate recognition
- Promotional opportunities
- File access
## Security
- Passwords are hashed using bcrypt
- JWT tokens for authentication
- Role-based access control (Member, Admin, Super Admin)
- CORS protection
- Environment-based configuration
## Troubleshooting
### Services not starting
```bash
# Check status of all services
docker-compose ps
# View all logs
docker-compose logs
# View specific service logs
docker-compose logs mysql
docker-compose logs backend
# Restart all services
docker-compose restart
# Full restart with rebuild
docker-compose down
docker-compose up -d --build
```
### Database connection issues
```bash
# Check if MySQL is healthy
docker-compose ps
# View MySQL logs for errors
docker-compose logs mysql
# Wait for MySQL to be fully ready (may take 30 seconds on first start)
docker-compose logs -f mysql
```
### Clean slate restart
```bash
# Stop everything and remove volumes
docker-compose down -v
# Start fresh
docker-compose up -d
# Wait for initialization
docker-compose logs -f
```
## Next Steps
- [ ] Implement Square payment integration
- [ ] Add email notification system
- [ ] Create event management endpoints
- [ ] Add volunteer management features
- [ ] Build frontend interface
- [ ] Add file upload/management
- [ ] Implement automated renewal reminders
- [ ] Add reporting and analytics
## License
Copyright © 2024 Swansea Airport Stakeholders' Alliance
## Support
For issues or questions, please contact the development team.