Post · Module Overview

Post — Bài viết, tương tác và report

Trang này giải thích post là gì, ai cần đọc nó, và những file nào quyết định hành vi chính.

Mục đích

Module này xử lý vòng đời bài viết: tạo post, reply, quote, repost, like, hide, report, update, delete, feed và semantic search.

Về mặt kỹ thuật, module này bám pattern route -> controller -> service -> repository. Những việc chậm hoặc phụ thuộc service ngoài được đẩy sang Redis/BullMQ khi code có producer tương ứng.

Phạm vi

Trong phạm vi ✓Ngoài phạm vi ✗
Các endpoint dưới /api/v1/postsUI frontend và copy hiển thị trong app
Validation, business rules, side effects từ codeÝ định product không thể thấy trong source
DB/cache/queue/service ngoài module gọi trực tiếpSLA chính thức nếu không có trong config/code

Công nghệ & thư viện sử dụng

Thành phầnCông nghệPhiên bảnLý do chọnGhi chú
HTTPExpress5.1.0Router/middleware rõ ràngpackage.json
ValidationZod3.25.76Validate request trước controllerRoute nào có validate() mới enforce
DBPrisma + MySQL/MariaDBPrisma 7Repository truy cập databaseschema.prisma
AsyncBullMQ + RedisBullMQ 5Tách tác vụ nềnKhông phải module nào cũng enqueue

Cấu trúc file

Sơ đồ này cho thấy module được chia theo vai trò: route nhận URL, controller đọc request, service quyết định nghiệp vụ, repository chạm database.

routesentrypointcontrollerrequest/responseservicebusiness rulesrepositoryPrisma/MySQLdtoZod validationcallscallsqueriesvalidate
Đây là cấu trúc lặp lại trong hầu hết module, không dùng thư viện vẽ ngoài.
1
src/modules/post/post.routes.ts

File này là một phần của luồng post. Đọc nó để trace request từ entrypoint tới nghiệp vụ.

snippet định vị
// đọc file này để trace module post
import ... from "src/modules/post/post.routes.ts"
2
src/modules/post/controller/post.controller.ts

File này là một phần của luồng post. Đọc nó để trace request từ entrypoint tới nghiệp vụ.

snippet định vị
// đọc file này để trace module post
import ... from "src/modules/post/controller/post.controller.ts"
3
src/modules/post/service/post.service.ts

File này là một phần của luồng post. Đọc nó để trace request từ entrypoint tới nghiệp vụ.

snippet định vị
// đọc file này để trace module post
import ... from "src/modules/post/service/post.service.ts"
4
src/modules/post/dto/post.dto.ts

File này là một phần của luồng post. Đọc nó để trace request từ entrypoint tới nghiệp vụ.

snippet định vị
// đọc file này để trace module post
import ... from "src/modules/post/dto/post.dto.ts"
5
src/modules/post/repository/post.repository.ts

File này là một phần của luồng post. Đọc nó để trace request từ entrypoint tới nghiệp vụ.

snippet định vị
// đọc file này để trace module post
import ... from "src/modules/post/repository/post.repository.ts"
6
src/modules/post/repository/like.repository.ts

File này là một phần của luồng post. Đọc nó để trace request từ entrypoint tới nghiệp vụ.

snippet định vị
// đọc file này để trace module post
import ... from "src/modules/post/repository/like.repository.ts"

Dependency map

Module này dùng các dependency ở bên trái và có thể được module bên phải gọi hoặc phụ thuộc gián tiếp.

postmoduleDepends onauth, user, redisUsed bycircle, search, jobs/evaluate.workerStorage/ExternalDB Redis APIsOutputsresponse/eventsusescalledreads/writesemits
Mũi tên đi vào là dependency module dùng; mũi tên đi ra là nơi kết quả được tiêu thụ.

Tóm tắt luồng chính

Người dùng tạo post, server validate content/mentions/visibility, ghi posts, attach topic/mention trong transaction, enqueue Pinecone, ghi action log rồi tăng version cache feed.