Go to file
Developer 0be3fe619e feat(presence-service): 完整实现 DDD+Hexagonal 架构的用户活跃度与在线状态服务
Domain 层 (领域层):
- 值对象: InstallId, EventName, EventProperties, DeviceInfo, TimeWindow
- 实体: EventLog, OnlineSnapshot
- 聚合根: DailyActiveStats
- 领域事件: SessionStartedEvent, HeartbeatReceivedEvent, DauCalculatedEvent
- 仓储接口: IEventLogRepository, IDailyActiveStatsRepository, IOnlineSnapshotRepository
- 领域服务: DauCalculationService, OnlineDetectionService

Infrastructure 层 (基础设施层):
- Prisma: EventLog, DailyActiveStats, OnlineSnapshot 数据模型
- Redis: 在线状态存储 (ZSET) + HyperLogLog DAU 实时统计
- Kafka: 事件发布服务 (可选)
- Mappers: 领域对象 <-> Prisma 模型转换
- 仓储实现: EventLogRepositoryImpl, DailyActiveStatsRepositoryImpl, OnlineSnapshotRepositoryImpl

Application 层 (应用层):
- Commands: RecordEvents, RecordHeartbeat, CalculateDau
- Queries: GetOnlineCount, GetDauStats
- Schedulers: 每分钟记录在线快照, 每小时清理过期数据, 每天凌晨计算前一天DAU

API 层 (表现层):
- Controllers: AnalyticsController, PresenceController, HealthController
- DTOs: BatchEventsDto, HeartbeatDto, QueryDauDto, OnlineCountResponseDto, DauStatsResponseDto
- Guards: JwtAuthGuard
- Decorators: @Public, @CurrentUser

核心功能:
-  用户行为事件批量上报与存储
-  日活 DAU 统计 (按自然日去重, 支持省/市维度)
-  实时在线人数统计 (3分钟窗口)
-  心跳机制 (前台60秒间隔)
-  HyperLogLog 实时 DAU 计数
-  定时任务 (快照记录, 过期清理, DAU 计算)
-  Swagger API 文档
-  Docker 多阶段构建
-  健康检查

技术栈:
- NestJS + TypeScript
- Prisma ORM + PostgreSQL
- Redis (ioredis)
- Kafka (kafkajs, 可选)
- CQRS 模式 (@nestjs/cqrs)
- 定时任务 (@nestjs/schedule)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-02 12:11:38 -08:00
.claude . 2025-11-30 06:44:57 -08:00
backend feat(presence-service): 完整实现 DDD+Hexagonal 架构的用户活跃度与在线状态服务 2025-12-02 12:11:38 -08:00
docs first commit 2025-11-23 21:21:44 -08:00
frontend fix: 修复 docker-compose.yml 中所有服务的健康检查 2025-12-02 09:36:38 -08:00
kubernetes . 2025-11-25 10:29:24 +08:00
scripts . 2025-11-25 10:29:24 +08:00
tests . 2025-11-25 10:29:24 +08:00
.gitignore first commit 2025-11-23 21:21:44 -08:00
README.md first commit 2025-11-23 21:21:44 -08:00
docker-compose.yml first commit 2025-11-23 21:21:44 -08:00

README.md