System Architecture
High-Level Architecture
Component Interactions
User Authentication Flow
Booking Creation Flow
Data Flow: Service Listing with i18n
Database Schema Overview
Entity Relationship Diagram
Key Table Relationships
User & Authentication- User: Core user account
- Session: Active user sessions (1:N)
- Account: OAuth accounts (1:N)
- Verification: Email verification tokens
- Booking: Main booking record
- BookingPet: Junction table (Booking N:N Pet)
- BookingService: Junction table (Booking N:N Service) with pricing
- Staff: Assigned staff member (optional)
- Service.name: JSONB
{"en": "Grooming", "vi": "Chăm sóc lông"} - Service.description: JSONB with translations
- Staff position, specialization: JSONB fields
- Setting value: JSONB for multi-language configs
API Design Patterns
Standard Response Format
HTTP Status Codes
| Code | Usage |
|---|---|
| 200 OK | Successful GET/PUT/PATCH |
| 201 Created | Successful POST |
| 204 No Content | DELETE success |
| 400 Bad Request | Invalid input |
| 401 Unauthorized | Missing/invalid auth |
| 403 Forbidden | Insufficient permissions |
| 404 Not Found | Resource doesn’t exist |
| 409 Conflict | Duplicate resource |
| 500 Internal Server Error | Server error |
Resource Pagination
Authentication & Authorization
Better Auth Integration
- Session-based authentication
- JWT tokens for API access
- Refresh token rotation
- CSRF protection on state-changing operations
- Rate limiting on auth endpoints
Role-Based Access Control (RBAC)
Deployment Architecture
Development Environment
Production Environment
Security Architecture
Network Security
- HTTPS/TLS 1.3+ for all communications
- CORS configured for specific origins
- Rate limiting per IP/endpoint
- DDoS protection via CDN
Data Security
- Passwords hashed with bcrypt
- Sessions encrypted
- Sensitive data excluded from logs
- SQL injection prevention via ORM
- XSS prevention via React escaping
Authentication Security
- Secure cookie flags (HttpOnly, Secure)
- CSRF tokens on state-changing operations
- Session timeout with warnings
- Account lockout after failed attempts
- Email verification for sign-up
Scalability Considerations
Current Architecture
- Monolithic backend suitable for < 1000 bookings/day
- Single database instance with replication
- Static asset CDN for frontend
Future Scaling
- Horizontal Scaling: Multiple backend instances behind load balancer
- Database: Query optimization, read replicas, eventual sharding
- Caching: Redis for sessions and frequent queries
- Message Queue: Async booking notifications and processing
- Microservices: Separate booking, payment, notification services