Commit Graph

1 Commits

Author SHA1 Message Date
Developer 7ae98c7f5b feat(referral-service): Implement complete referral service with DDD architecture
Implement the referral service microservice with comprehensive features:

## Domain Layer
- ReferralRelationship aggregate: manages user referral relationships
- TeamStatistics aggregate: tracks team statistics and leaderboard scores
- Value Objects: UserId, ReferralCode, ReferralChain, LeaderboardScore, ProvinceCityDistribution
- Domain Services: ReferralChainService, LeaderboardCalculationService
- Domain Events: ReferralRelationshipCreated, TeamStatisticsUpdated

## Application Layer
- ReferralService: create relationships, get user info, validate codes
- TeamStatisticsService: update statistics, get leaderboard, province/city distribution
- Commands: CreateReferralRelationship, UpdateTeamStatistics
- Queries: GetUserReferralInfo, GetDirectReferrals, GetLeaderboard, GetProvinceCityDistribution
- Event Handlers: UserRegisteredHandler, PlantingCreatedHandler

## Infrastructure Layer
- Prisma repositories with PostgreSQL
- Redis caching for leaderboard
- Kafka messaging for domain events
- JWT authentication guard

## API Layer
- REST endpoints for referral management
- Leaderboard endpoints with pagination
- Team statistics endpoints
- Health check endpoints

## Testing (127 unit + 35 integration + 16 E2E tests)
- Domain layer unit tests (100% coverage)
- Integration tests with mocks
- E2E tests with supertest
- Docker test environment with PostgreSQL, Redis, Redpanda

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-01 00:18:20 -08:00