A comprehensive booking platform for BOC Life policy holders to redeem retirement packages using their accumulated points.
graph TB
subgraph "Client Layer"
A[Flutter Web App]
B[Flutter iOS App]
C[Flutter Android App]
D[Admin Dashboard]
end
subgraph "Application Layer"
E[FastAPI Backend<br/>Python 3.12+]
F[Directus CMS<br/>Node.js]
end
subgraph "Data Layer"
G[(PostgreSQL 15<br/>Main Database)]
H[(Redis Cache)]
end
subgraph "AWS Cloud Services"
I[S3 Bucket<br/>File Storage]
J[SNS<br/>SMS/OTP]
K[SES<br/>Email Service]
L[CloudFront<br/>CDN]
M[EC2/ECS<br/>Hosting]
end
A --> E
B --> E
C --> E
D --> F
E --> F
E --> G
E --> H
F --> G
E --> I
E --> J
E --> K
A --> L
B --> L
C --> L
E --> M
F --> M
style E fill:#e3f2fd
style F fill:#fff3e0
style G fill:#f3e5f5
style H fill:#fce4ec
sequenceDiagram
participant User as User/Client
participant API as FastAPI Backend
participant Cache as Redis Cache
participant DB as PostgreSQL
participant CMS as Directus CMS
participant AWS as AWS Services
User->>API: Request Package List
API->>Cache: Check Cache
alt Cache Hit
Cache-->>API: Return Cached Data
else Cache Miss
API->>CMS: Fetch Packages
CMS->>DB: Query Data
DB-->>CMS: Package Data
CMS-->>API: Package List
API->>Cache: Store in Cache
end
API-->>User: Return Packages
User->>API: Create Booking
API->>DB: Validate Points
DB-->>API: Points Available
API->>DB: Create Booking & Deduct Points
API->>AWS: Send Confirmation Email (SES)
API->>CMS: Log Booking Event
API-->>User: Booking Confirmation
sequenceDiagram
participant User as User
participant App as Flutter App
participant API as FastAPI
participant SNS as AWS SNS
participant DB as Database
User->>App: Enter Invitation Code
App->>API: POST /auth/verify-invitation
API->>DB: Validate Invitation Code
DB-->>API: Code Valid
API-->>App: Code Verified
User->>App: Enter Phone Number
App->>API: POST /auth/request-otp
API->>SNS: Send OTP SMS
SNS-->>User: OTP SMS
API-->>App: OTP Sent
User->>App: Enter OTP
App->>API: POST /auth/verify-otp
API->>DB: Verify OTP
DB-->>API: OTP Valid
API->>DB: Create/Update User
API-->>App: JWT Access Token
App-->>User: Authenticated
flowchart TD
A[User Browses Packages] --> B{Filter by Location?}
B -->|Yes| C[Select City/Region]
B -->|No| D[View All Packages]
C --> E[Display Filtered Packages]
D --> E
E --> F[Select Package]
F --> G[Check Availability]
G --> H{Available?}
H -->|No| I[Show Alternative Dates]
H -->|Yes| J[Check Points Balance]
J --> K{Sufficient Points?}
K -->|No| L[Show Insufficient Points]
K -->|Yes| M[Enter Guest Details]
M --> N[Review Booking]
N --> O{Confirm?}
O -->|No| P[Cancel/Edit]
O -->|Yes| Q[Process Booking]
Q --> R[Deduct Points]
R --> S[Create Booking Record]
S --> T[Send Email Confirmation]
T --> U[Update Availability]
U --> V[Booking Complete]
I --> F
L --> E
P --> M
style Q fill:#4caf50,color:#fff
style V fill:#2196f3,color:#fff
style L fill:#f44336,color:#fff
erDiagram
USERS ||--o{ BOOKINGS : creates
USERS ||--o{ POINTS_TRANSACTIONS : has
CAMPAIGNS ||--o{ INVITATION_CODES : generates
INVITATION_CODES ||--o| USERS : used_by
PACKAGES ||--o{ BOOKINGS : booked_in
HOTELS ||--o{ PACKAGES : contains
CITIES ||--o{ HOTELS : located_in
USERS {
string id PK
string phone_number UK
string email
string full_name
string language
int total_points
datetime created_at
datetime last_login
}
CAMPAIGNS {
string id PK
string name
string description
int points_allocation
datetime start_date
datetime end_date
boolean is_active
}
INVITATION_CODES {
string code PK
string campaign_id FK
string user_id FK
boolean is_used
datetime used_at
datetime expires_at
}
PACKAGES {
string id PK
string hotel_id FK
string name_en
string name_zh_hk
string name_zh_cn
int points_required
int max_guests
boolean is_active
}
HOTELS {
string id PK
string city_id FK
string name
string address
float rating
string image_url
}
BOOKINGS {
string id PK
string booking_code UK
string user_id FK
string package_id FK
date check_in_date
date check_out_date
int points_used
string status
datetime created_at
}
POINTS_TRANSACTIONS {
string id PK
string user_id FK
int points_change
string transaction_type
string reference_id
datetime created_at
}
| Platform | Technology | Status |
|---|---|---|
| ๐ฑ Mobile Web | Flutter Web | โ Supported |
| ๐ iOS | Flutter Native | โ Supported |
| ๐ค Android | Flutter Native | โ Supported |
| ๐ผ Admin Panel | Directus CMS | โ Supported |
Ensure you have the following installed:
This is the fastest way to get the entire platform running locally.
# 1. Clone the repository
git clone <repository-url>
cd fast_boc_life_retirement_package_booking_platform
# 2. Copy environment configuration
cp .env.example .env
# Edit .env with your configuration
# 3. Start all services
docker-compose up -d
# 4. Wait for services to start (check logs)
docker-compose logs -f
# 5. Access the services
# - Backend API: http://localhost:8000
# - API Docs: http://localhost:8000/docs
# - Directus CMS: http://localhost:8055
# - PostgreSQL: localhost:5432
# - Redis: localhost:6379
# 1. Navigate to backend directory
cd backend
# 2. Create virtual environment (optional but recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Configure environment
cp .env.example .env
# Edit .env with your database and AWS credentials
# 5. Run database migrations (if using Alembic)
alembic upgrade head
# 6. Start the development server
uvicorn main:app --reload --host 0.0.0.0 --port 8000
# Server will be available at http://localhost:8000
# Using UV package manager for faster dependency resolution
uv pip install -r requirements.txt
uv run uvicorn main:app --reload
# 1. Navigate to CMS directory
cd _directus
# 2. Install dependencies
npm install
# Or using Bun (faster)
bun install
# 3. Configure environment
cp .env.example .env
# Edit .env with database credentials
# 4. Bootstrap Directus
npx directus bootstrap
# 5. Start Directus
npx directus start
# Or with Bun
bun run directus start
# Directus will be available at http://localhost:8055
# 1. Navigate to Flutter app directory
cd flutter_app
# 2. Install dependencies
flutter pub get
# 3. Configure environment
cp lib/core/config/config.example.dart lib/core/config/config.dart
# Edit config.dart with your API endpoints
# 4. Run on different platforms
# Web
flutter run -d chrome
# iOS (requires macOS and Xcode)
flutter run -d ios
# Android
flutter run -d android
# Build for production
flutter build web --release
flutter build ios --release
flutter build apk --release
# Using Docker for PostgreSQL
docker run -d \
--name boclife-postgres \
-e POSTGRES_USER=boclife \
-e POSTGRES_PASSWORD=boclife123 \
-e POSTGRES_DB=boc_retirement \
-p 5432:5432 \
postgres:15-alpine
# Using Docker for Redis
docker run -d \
--name boclife-redis \
-p 6379:6379 \
redis:7-alpine
# Application
APP_NAME=BOC Life Retirement Package API
API_V1_STR=/api/v1
DEBUG=True
# Database
DATABASE_URL=postgresql://boclife:boclife123@localhost:5432/boc_retirement
# JWT Authentication
JWT_SECRET_KEY=your-super-secret-jwt-key-change-this-in-production
JWT_ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
# Redis
REDIS_URL=redis://localhost:6379
# AWS Configuration
AWS_ACCESS_KEY_ID=your-aws-access-key
AWS_SECRET_ACCESS_KEY=your-aws-secret-key
AWS_REGION=ap-east-1
AWS_S3_BUCKET=boclife-retirement-uploads
# AWS SNS (for OTP)
AWS_SNS_SENDER_ID=BOCLife
# AWS SES (for Email)
[email protected]
# Directus
DIRECTUS_URL=http://localhost:8055
DIRECTUS_TOKEN=your-directus-static-token
# CORS
CORS_ORIGINS=["http://localhost:3000","http://localhost:8080"]
# Server
PORT=8055
PUBLIC_URL=http://localhost:8055
# Database
DB_CLIENT=pg
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=directus
DB_USER=boclife
DB_PASSWORD=boclife123
# Security
KEY=your-directus-key-min-32-characters
SECRET=your-directus-secret-min-32-characters
# Admin Account
[email protected]
ADMIN_PASSWORD=change-this-secure-password
# Storage
STORAGE_LOCATIONS=local
STORAGE_LOCAL_DRIVER=local
STORAGE_LOCAL_ROOT=./uploads
# Email (Optional)
[email protected]
EMAIL_TRANSPORT=smtp
EMAIL_SMTP_HOST=smtp.gmail.com
EMAIL_SMTP_PORT=587
[email protected]
EMAIL_SMTP_PASSWORD=your-app-password
# Extensions
EXTENSIONS_PATH=./extensions
fast_boc_life_retirement_package_booking_platform/
โ
โโโ backend/ # FastAPI Backend Application
โ โโโ api/ # API Routes
โ โ โโโ v1/ # API Version 1
โ โ โ โโโ auth/ # Authentication endpoints
โ โ โ โโโ users/ # User management
โ โ โ โโโ packages/ # Package endpoints
โ โ โ โโโ hotels/ # Hotel endpoints
โ โ โ โโโ bookings/ # Booking endpoints
โ โ โโโ admin/ # Admin endpoints
โ โ โโโ dependencies.py # Shared dependencies
โ โโโ config/ # Configuration
โ โ โโโ settings.py # App settings
โ โโโ schemas/ # Pydantic schemas
โ โโโ services/ # Business logic services
โ โโโ main.py # Application entry point
โ โโโ requirements.txt # Python dependencies
โ โโโ Dockerfile # Docker configuration
โ
โโโ _directus/ # Directus CMS Integration
โ โโโ index.ts # Directus SDK client
โ โโโ directus-setup.js # Setup scripts
โ โโโ package.json # Node dependencies
โ โโโ README.md # Directus documentation
โ
โโโ cms/ # CMS Data & Schema
โ โโโ directus_schema.json # Complete schema export
โ โโโ directus_collections.json # Collections configuration
โ โโโ directus_complete_schema.json # Full schema backup
โ โโโ uploads/ # User uploads (gitignored)
โ
โโโ deployment/ # Deployment Configuration
โ โโโ init-db.sh # Database initialization script
โ
โโโ scripts/ # Utility Scripts
โ โโโ ... # Various helper scripts
โ
โโโ docker-compose.yml # Docker Compose configuration
โโโ Dockerfile # Main application Dockerfile
โโโ package.json # Root Node.js configuration
โโโ pyproject.toml # Python project configuration (UV)
โโโ tsconfig.json # TypeScript configuration
โโโ .env.example # Environment variables template
โโโ README.md # This file
Once the backend is running, interactive API documentation is available at:
View request/response schemas
ReDoc: http://localhost:8000/redoc
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/auth/verify-invitation |
Verify invitation code |
| POST | /api/v1/auth/request-otp |
Request OTP SMS |
| POST | /api/v1/auth/verify-otp |
Verify OTP and get JWT token |
| POST | /api/v1/auth/register |
Register new user |
| POST | /api/v1/auth/login |
User login |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/packages |
List all available packages |
| GET | /api/v1/packages/{id} |
Get package details |
| GET | /api/v1/packages/search |
Advanced package search |
| GET | /api/v1/hotels |
List all hotels |
| GET | /api/v1/hotels/cities |
Get available cities |
| GET | /api/v1/hotels/news |
Get latest news updates |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/bookings |
Create new booking |
| GET | /api/v1/bookings |
Get user's bookings |
| GET | /api/v1/bookings/{code} |
Get booking details |
| PUT | /api/v1/bookings/{code} |
Update booking |
| POST | /api/v1/bookings/{code}/cancel |
Cancel booking |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/users/me |
Get current user profile |
| PUT | /api/v1/users/me |
Update user profile |
| GET | /api/v1/users/dashboard |
Get user dashboard data |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/admin/campaigns |
Create campaign |
| GET | /api/v1/admin/campaigns |
List all campaigns |
| POST | /api/v1/admin/campaigns/{id}/generate-invitations |
Generate invitation codes |
| GET | /api/v1/admin/statistics |
Get admin statistics |
# Build all images
docker-compose build
# Start services in production mode
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
# View logs
docker-compose logs -f backend
# Stop services
docker-compose down
# 1. Build Docker image
docker build -t boclife-api:latest ./backend
# 2. Tag for ECR
docker tag boclife-api:latest <aws-account-id>.dkr.ecr.ap-east-1.amazonaws.com/boclife-api:latest
# 3. Login to ECR
aws ecr get-login-password --region ap-east-1 | \
docker login --username AWS --password-stdin <aws-account-id>.dkr.ecr.ap-east-1.amazonaws.com
# 4. Push to ECR
docker push <aws-account-id>.dkr.ecr.ap-east-1.amazonaws.com/boclife-api:latest
# 5. Update ECS service
aws ecs update-service --cluster boclife-cluster --service boclife-api --force-new-deployment
# 1. Build Flutter web app
cd flutter_app
flutter build web --release
# 2. Sync to S3
aws s3 sync build/web/ s3://boclife-web-app/ --delete
# 3. Invalidate CloudFront cache
aws cloudfront create-invalidation \
--distribution-id <DISTRIBUTION_ID> \
--paths "/*"
# Run all tests
cd backend
pytest
# Run with coverage
pytest --cov=app --cov-report=html
# Run specific test file
pytest tests/test_auth.py
# Run with verbose output
pytest -v
cd flutter_app
# Unit tests
flutter test
# Integration tests
flutter test integration_test/
# Widget tests
flutter test test/widgets/
# Generate coverage
flutter test --coverage
genhtml coverage/lcov.info -o coverage/html
The platform supports three languages:
| Language | Code | Coverage |
|---|---|---|
| English | en |
โ Full |
| Traditional Chinese | zh-HK |
โ Full |
| Simplified Chinese | zh-CN |
โ Full |
Translations are stored in Directus CMS and accessed via API.
# Generate translations
flutter gen-l10n
# Translation files location
lib/l10n/
โโโ app_en.arb
โโโ app_zh_HK.arb
โโโ app_zh_CN.arb
All content fields support multi-language input directly in the admin interface.
# Backend health check
curl http://localhost:8000/health
# Directus health check
curl http://localhost:8055/server/health
# Docker logs
docker-compose logs -f backend
docker-compose logs -f directus
# Application logs (if running locally)
tail -f logs/app.log
/metrics endpointPython: Follow PEP 8, use black formatter
bash
black backend/
flake8 backend/
TypeScript/JavaScript: Use Prettier
bash
npm run format
npm run lint
Flutter/Dart: Follow official Dart style guide
bash
dart format .
flutter analyze
# Branch naming
feature/your-feature-name
bugfix/issue-description
hotfix/critical-fix
# Commit messages (Conventional Commits)
feat: add points balance endpoint
fix: resolve OTP verification timeout
docs: update API documentation
refactor: optimize booking service
main or developSymptom: Server fails to start
# Check logs
docker-compose logs backend
# Common fixes:
# 1. Check database connection
docker-compose ps postgres
# 2. Verify environment variables
cat .env
# 3. Check port availability
lsof -i :8000
Symptom: OTP SMS not received
# Verify AWS SNS configuration
aws sns list-phone-numbers-opted-out
# Check AWS credentials
aws sts get-caller-identity
# Review IAM permissions for SNS
# Test PostgreSQL connection
docker-compose exec postgres psql -U boclife -d boc_retirement -c "SELECT 1;"
# Reset database
docker-compose down -v
docker-compose up -d postgres
# Clean Flutter build
flutter clean
flutter pub get
flutter pub upgrade
# Clear Flutter cache
rm -rf ~/.pub-cache
flutter pub cache repair
| Service | Location |
|---|---|
| Backend | logs/app.log |
| Directus | cms/logs/directus.log |
| PostgreSQL | docker logs boclife-postgres |
| Redis | docker logs boclife-redis |
/docsThis project is proprietary software developed for BOC Life Insurance.
ยฉ 2024 BOC Life Insurance. All rights reserved.
This is a private project. For authorized contributors:
If you discover a security vulnerability, please email [email protected] immediately.
Do not create public issues for security vulnerabilities.
Built with โค๏ธ for BOC Life Insurance policy holders
Last Updated: November 2024