refactor: split monolith into 3 microservices (frontend, backend, discord-gateway)
- Extract services into services/{frontend,backend,discord-gateway}
- Create packages/shared/ for shared logger, errors, utils, types
- Setup Modular MVC pattern in backend (controller→service→repository)
- Setup event-driven architecture in discord-gateway with Redis pub/sub
- Move Docker files to infra/docker/ with per-service Dockerfiles
- Update docker-compose.yml to use Traefik-only routing (no port exposes)
- Update GitHub Actions deploy workflow for multi-service matrix build
- Fix all import paths and resolve type errors across all services
- All 3 services pass tsc --noEmit clean
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
bda8304bb9
commit
c48a0c5e3b
@@ -0,0 +1,61 @@
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { ForbiddenError, ValidationError } from "../../shared/errors/index.js";
|
||||
import { createChildLogger } from "../../shared/logger/index.js";
|
||||
import { analyticsRepository } from "./analytics.repository.js";
|
||||
import type { AnalyticsQuery } from "./analytics.schema.js";
|
||||
|
||||
const logger = createChildLogger("analytics.service");
|
||||
|
||||
export class AnalyticsService {
|
||||
private assertMonitorGuild(guildId: string) {
|
||||
if (!config.MONITOR_GUILD_ID) {
|
||||
throw new ValidationError("MONITOR_GUILD_ID is not configured");
|
||||
}
|
||||
|
||||
if (guildId !== config.MONITOR_GUILD_ID) {
|
||||
throw new ForbiddenError("Analytics are restricted to the monitor guild");
|
||||
}
|
||||
}
|
||||
|
||||
async getOverview(query: AnalyticsQuery) {
|
||||
this.assertMonitorGuild(query.guildId);
|
||||
logger.debug({ query }, "Getting analytics overview");
|
||||
return analyticsRepository.getOverview(
|
||||
query.guildId,
|
||||
query.channelId,
|
||||
query.hours,
|
||||
);
|
||||
}
|
||||
|
||||
async getDailyTrend(guildId: string, hours = 24) {
|
||||
this.assertMonitorGuild(guildId);
|
||||
logger.debug({ guildId, hours }, "Getting daily trend");
|
||||
return analyticsRepository.getDailyTrend(guildId, hours);
|
||||
}
|
||||
|
||||
async getHourlyStats(guildId: string, hours = 24) {
|
||||
this.assertMonitorGuild(guildId);
|
||||
logger.debug({ guildId, hours }, "Getting hourly stats");
|
||||
return analyticsRepository.getHourlyStats(guildId, hours);
|
||||
}
|
||||
|
||||
async getTopViolators(guildId: string, limit = 10) {
|
||||
this.assertMonitorGuild(guildId);
|
||||
logger.debug({ guildId, limit }, "Getting top violators");
|
||||
return analyticsRepository.getTopViolators(guildId, limit);
|
||||
}
|
||||
|
||||
async getUserLeaderboard(guildId: string, limit = 10) {
|
||||
this.assertMonitorGuild(guildId);
|
||||
logger.debug({ guildId, limit }, "Getting user leaderboard");
|
||||
return analyticsRepository.getUserLeaderboard(guildId, limit);
|
||||
}
|
||||
|
||||
async getModerationStats(guildId: string) {
|
||||
this.assertMonitorGuild(guildId);
|
||||
logger.debug({ guildId }, "Getting moderation stats");
|
||||
return analyticsRepository.getModerationStats(guildId);
|
||||
}
|
||||
}
|
||||
|
||||
export const analyticsService = new AnalyticsService();
|
||||
Reference in New Issue
Block a user