docs / current-system-reference

System reference hiện tại

Trang này là bản đồ ngắn gọn của code đang chạy tại ngày 12/06/2026. Khi tài liệu lịch sử mâu thuẫn với trang này, hãy kiểm tra route, DTO và service trong source; source code là nguồn sự thật cuối cùng.

126route declarations
41Prisma models
10workers
12queue names

Request lifecycle

Express middleware
Global rate limit
Module router
Controller + service
Response/error envelope
Giai đoạnCodeHành vi
App middlewaresrc/app.tsHelmet, CORS, compression, Morgan, JSON/urlencoded parser, logger và response helper.
HLS exception/api/v1/webhooks/hlsRaw JSON body được mount trước express.json() để verify chữ ký.
API boundaryapp.use('/api/v1', apiLimiter, router)Mọi route bên dưới đều đi qua global limiter.
Authorizationsrc/middlewares/auth.tsVerify Bearer JWT, Redis blacklist, user tồn tại và trạng thái không bị BANNED.
Validationsrc/middlewares/validate.tsZod parse body/params/query; query đã parse nằm ở req.query_parsed.
Success enveloperes.success / res.paginate{ success: true, message?, data?, pagination? }.
Error envelopeerrorHandler{ success: false, message?, errors?, errorCode? }; map Prisma P2002/P2025/P2003.

HTTP module map

PrefixModuleAuth boundaryGhi chú
/docsSwagger UIPublicOpenAPI document được ghép từ module swagger files.
/adminAdminLogin public; phần còn lại JWT + ADMIN roleUser moderation, report, stats, hashtag và daily quest.
/authAuthMixedProfile, me, logout và resend verify cần JWT.
/postsPostPublic reads trước router.use(authorization)Write/interactions protected; judge-status hiện trả placeholder.
/circleCircleToàn bộ protectedCircle domain lớn nhất, gồm management và gamification.
/circle-aiCircle AIProtectedGenerate markdown response cho circle workflow.
/usersPublic userProfile/mention public; karma/badge protectedPublic profile route phải nằm trước auth boundary.
/userFollowReads public, writes protectedFollow toggle và legacy friend-request route.
/meCurrent userToàn bộ protectedFollower và friend-request lifecycle.
/message-groupsChatMỗi route protectedPersistence + Pusher + message notification worker.
/notificationNotificationToàn bộ protectedGrouped notification và unread counters.
/searchSearchToàn bộ protectedSearch index tên search, hydrate record từ Prisma.
/uploadUploadMedia protected; avatar hiện publicAvatar thiếu authorization là hành vi code hiện tại, cần cân nhắc security.
/webhooksWebhooksProvider verificationHLS signature và Leonardo callback key.
/aiAIToàn bộ protectedHTTP route tạo image; scoring/report chạy nội bộ qua worker.
/topic, /quests, /museum, /pusher, /healthSupporting HTTP modulesTùy moduleXem API page tương ứng.

Module hỗ trợ không mount route riêng

ModuleTrách nhiệmĐược dùng bởi
access-controlRole, permission, user-role và middleware kiểm tra quyền.Auth, admin, circle.
anti-spamLưu/đọc giới hạn hành vi user theo ngày.Post/circle policy.
jwtSign/verify access-refresh token pair.Auth middleware và auth service.
limit-actionKhóa hành động AI khi user vượt quota.AI service.
mixed-bread + pineconeEmbedding và vector similarity.Post semantic search/index worker.
reportTạo report và enqueue AI evaluation.Post + admin.
user-action-logAudit hành động, quest progress và AI quota.Post, circle, quest, AI.
user-restrictionRestriction theo user/type/expiry.Circle và moderation policies.
jobProducer cho email, index, vector, like, notification, evaluation, HP và ban.Nhiều domain service.

Queue và worker

QueueWorker hiện cóMục đích
email_queueemail.workerVerify, forgot-password và invitation email.
bloom_queuebloom.workerRedis Bloom username/email.
pinecone_queuepine.workerMixedbread embedding và Pinecone upsert.
like_queue + likes_eventslike.workerĐồng bộ like state và phát notification count.
notificationnotification.workerFlush grouped reply/mention/like notification.
message_queuemessage.workerFlush realtime chat notification.
evaluation_queueevaluate.workerAI score circle post và evaluate report.
delta_hp_queuedelta-hp.workerĐiều chỉnh circle HP theo repeat job.
auto_remove_ban_queueauto-remove-ban.workerTự gỡ user ban hết hạn.
friend_request_queueKhông có worker riêngĐược producer khai báo; cần xác nhận consumer trước khi phụ thuộc.

Công nghệ thực tế

NhómStack hiện tại
Runtime/APINode.js, TypeScript 5.8, Express 5.1, Zod 3.25.
DatabasePrisma 7.8, @prisma/adapter-mariadb, MySQL/MariaDB.
Async/cacheRedis 5 client, ioredis, Redis Bloom, BullMQ 5.76.
Search/vectorPrisma, Mixedbread AI, Pinecone.
AIOpenRouter SDK/provider, Groq, Google GenAI dependency, Leonardo provider.
Media/realtimeCloudflare R2 qua AWS S3 SDK, Sharp, HLS, Pusher.
OperationsDocker multi-stage, Nginx, API + worker container.
Các điểm chưa hoàn thiện cần ghi rõ khi tích hợp: AuthService.updateProfile() hiện trả cờ giả lập; validateResetPasswordToken() luôn trả valid; PostService.getJudgeStatus() trả pending placeholder; avatar upload chưa có authorization; Swagger vẫn có tag Internal dù router không mount internal module.