05. Django Project - Dự Án Microservices
Mục Tiêu Module
Áp dụng tất cả kiến thức đã học để xây dựng hệ thống microservices hoàn chỉnh với Django, Docker và PostgreSQL.
Danh Sách Bài Học
Phase 1: Project Setup
1. Project Architecture Design
- Microservices architecture overview
- Service boundaries
- Communication patterns (REST, Message Queue)
- Database per service pattern
- API Gateway pattern
- Technology stack decisions
2. Development Environment Setup
- Git repository structure
- Virtual environment (mxtechenv)
- IDE configuration
- Docker Desktop installation
- PostgreSQL client tools
- Postman/Insomnia setup
3. Common Source Package
- Shared utilities structure
- Base models và serializers
- Custom middleware
- Authentication decorators
- Response formatters
- Error handlers
- Constants và configs
Phase 2: User/Auth Service
4. User Service - Project Setup
- Django project initialization
- App structure
- Database configuration
- Environment variables
- Initial migrations
5. User Models
- Custom User model
- User profile model
- Role model
- Permission model
- Model relationships
- Model methods
6. Authentication System
- JWT implementation với simplejwt
- Login endpoint
- Logout endpoint
- Token refresh
- Token blacklist
- Password validation
7. User Registration
- Registration endpoint
- Email verification
- Username/email validation
- Password strength requirements
- Terms acceptance
- Welcome email trigger
8. User Profile Management
- Profile retrieve
- Profile update
- Avatar upload
- Password change
- Account deactivation
- Profile visibility settings
9. Password Recovery
- Forgot password endpoint
- Reset token generation
- Reset password endpoint
- Email templates
- Token expiration
- Security measures
10. Role-Based Access Control (RBAC)
- Role definition
- Permission system
- Role assignment
- Permission checking
- Custom permissions
- Admin roles
11. User Service Testing
- Model tests
- API endpoint tests
- Authentication tests
- Permission tests
- Integration tests
- Test coverage report
Phase 3: Mailer Service
12. Mailer Service - Project Setup
- Django project initialization
- Celery configuration
- Redis setup
- Email backend configuration
- Template directory structure
13. Email Models
- Email template model
- Email history model
- Email queue model
- Template variables
- Email status tracking
14. Email Templates
- Welcome email template
- Verification email template
- Password reset template
- Notification templates
- Template rendering
- HTML vs plain text
15. Celery Tasks
- Send email task
- Bulk email task
- Scheduled email task
- Retry logic
- Error handling
- Task monitoring
16. Mailer API Endpoints
- Send email endpoint
- Template management endpoints
- Email history endpoints
- Queue status endpoint
- Retry failed emails
- API authentication
17. Email Service Integration
- User service → Mailer service communication
- REST API calls
- Async task triggering
- Error handling
- Fallback mechanisms
- Circuit breaker pattern
18. Mailer Service Testing
- Task tests
- Email sending tests
- Template rendering tests
- API tests
- Integration tests
- Mock email backend
Phase 4: Docker & Deployment
19. Docker Basics Review
- Dockerfile best practices
- Multi-stage builds
- Layer caching
- .dockerignore
- Image optimization
20. Service Dockerfiles
- User service Dockerfile
- Mailer service Dockerfile
- Base image selection
- Dependencies installation
- Health checks
- Entrypoint scripts
21. Docker Compose Configuration
- docker-compose.yml structure
- Service definitions
- Network configuration
- Volume management
- Environment variables
- Dependency ordering
22. PostgreSQL Containers
- PostgreSQL service definition
- Multiple databases
- Data persistence
- Initialization scripts
- Backup strategies
- Connection pooling
23. Redis Container
- Redis service definition
- Persistence configuration
- Memory limits
- Security settings
- Connection from services
24. Service Networking
- Docker networks
- Service discovery
- Internal communication
- Port mapping
- Load balancing basics
- Network security
25. Environment Configuration
- .env file structure
- Secrets management
- Different environments (dev, staging, prod)
- Environment validation
- Configuration best practices
26. Database Migrations
- Running migrations trong Docker
- Migration strategies
- Zero-downtime migrations
- Rollback procedures
- Data migrations
27. Static Files & Media
- Static files configuration
- Media files configuration
- Volume mounting
- WhiteNoise integration
- CDN considerations
- File upload limits
Phase 5: Testing & Quality
28. Integration Testing
- Service-to-service tests
- End-to-end tests
- Docker Compose for testing
- Test data setup
- Test isolation
- CI/CD testing
29. API Documentation
- OpenAPI/Swagger setup
- drf-spectacular integration
- Endpoint documentation
- Request/response examples
- Authentication documentation
- Postman collections
30. Code Quality
- Linting với flake8/pylint
- Code formatting với black
- Pre-commit hooks
- Type checking với mypy
- Code review checklist
Phase 6: Monitoring & Maintenance
31. Logging Setup
- Centralized logging
- Log aggregation
- Log levels
- Structured logging
- Log rotation
- Debug logging
32. Error Tracking
- Sentry integration
- Error notifications
- Error grouping
- Performance monitoring
- Release tracking
33. Health Checks
- Service health endpoints
- Database health
- External service checks
- Readiness vs liveness
- Docker health checks
34. Performance Monitoring
- Response time tracking
- Database query monitoring
- Cache hit rates
- Celery task monitoring
- Resource usage
Phase 7: Advanced Features
35. API Rate Limiting
- Rate limiting implementation
- Per-user limits
- IP-based limits
- Throttling strategies
- Rate limit headers
36. API Versioning
- Versioning strategies
- URL versioning
- Header versioning
- Backward compatibility
- Deprecation policy
37. Caching Strategy
- Redis caching
- Cache invalidation
- Cache warming
- Cache patterns
- Performance gains
38. Background Jobs
- Periodic tasks với Celery Beat
- Scheduled emails
- Data cleanup jobs
- Report generation
- Job monitoring
39. Database Optimization
- Query optimization
- Indexing strategy
- Connection pooling
- Read replicas (concept)
- Database backup
40. Security Hardening
- HTTPS enforcement
- CORS configuration
- Security headers
- SQL injection prevention
- XSS prevention
- CSRF protection
- Security audit
Phase 8: Deployment
41. Production Settings
- DEBUG = False
- ALLOWED_HOSTS
- Security settings
- Database configuration
- Static/media files
- Email configuration
42. Docker Compose Production
- Production docker-compose
- Resource limits
- Restart policies
- Healthchecks
- Logging drivers
43. Container Orchestration Intro
- Docker Swarm basics
- Kubernetes concepts
- Service scaling
- Load balancing
- High availability
44. CI/CD Pipeline
- GitHub Actions / GitLab CI
- Automated testing
- Docker image building
- Automated deployment
- Rollback strategies
45. Deployment Checklist
- Pre-deployment checks
- Database migrations
- Static files collection
- Environment verification
- Smoke tests
- Monitoring setup
Phase 9: Project Documentation
46. System Documentation
- Architecture diagrams
- Service dependencies
- Database schemas
- API contracts
- Infrastructure setup
47. Developer Guide
- Setup instructions
- Development workflow
- Coding standards
- Testing guidelines
- Contribution guide
48. Operations Guide
- Deployment procedures
- Backup/restore procedures
- Monitoring guide
- Troubleshooting guide
- Incident response
49. User Guide (for team members)
- API usage examples
- Authentication flow
- Common use cases
- Error handling
- Best practices
50. Project Retrospective
- Lessons learned
- What went well
- What to improve
- Technology evaluation
- Next steps
Prerequisites
- ✅ Hoàn thành Module 01-04
- ✅ Docker installed
- ✅ PostgreSQL knowledge
- ✅ Git basics
- Postman/Insomnia
- Terminal/shell proficiency
Thời Gian Học
- Ước tính: 6-8 tuần
- Thời lượng mỗi bài: 2-4 giờ
- Full-time commitment: 40+ giờ/tuần
Deliverables
Code Deliverables
- ✅ Working User/Auth Service
- ✅ Working Mailer Service
- ✅ Common package
- ✅ Docker configuration
- ✅ Database schemas
- ✅ Test suites
- ✅ API documentation
Documentation Deliverables
- ✅ README.md
- ✅ Architecture diagrams
- ✅ API documentation
- ✅ Setup guide
- ✅ Deployment guide
Presentation
- ✅ Demo video
- ✅ Technical presentation
- ✅ Code walkthrough
Tài Nguyên Tham Khảo
- Microservices Patterns (Book)
- Building Microservices (Book)
- Docker Documentation
- Django Deployment Checklist
Evaluation Criteria
Technical (70%)
- Code quality (20%)
- Architecture design (15%)
- Testing coverage (15%)
- Security implementation (10%)
- Performance (10%)
Documentation (20%)
- Code documentation (10%)
- System documentation (10%)
Presentation (10%)
- Demo (5%)
- Technical explanation (5%)
Module Tiếp Theo
06-postgresql - Deep dive vào PostgreSQL cho production databases.
Note: Đây là project thực tế, commit code thường xuyên và push lên Git repository!