Replace Vercel-specific infra (Cron, Blob) with self-hosted equivalents for deployment to Coolify: in-container cron scheduler (scripts/cron-runner.mjs) and disk-based upload storage served via /api/uploads/[...path]. Add Dockerfile, .dockerignore, and /api/health for container health checks. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
4.9 KiB
CLAUDE.md — ระบบจัดการเพจ (Page Manager)
ระบบหลังบ้านสำหรับทีมดูแล หลายเพจ Facebook (+ Instagram ที่ผูกกับเพจ) ในที่เดียว: เชื่อมเพจ, เขียน/อนุมัติ/ตั้งเวลาโพสต์, ตอบ inbox + คอมเมนต์, auto-reply, insights
Setup / env / คำสั่ง: README.md
Verify ก่อนจบงาน
npm run typecheck · npm run lint · npm run build — ทั้งสามต้องผ่าน. ไม่มี test suite; flow ที่แตะ Graph ทดสอบกับ DB local (npx prisma dev) + เพจทดสอบจริง
เอกสาร (อ่านก่อนแก้ส่วนนั้น)
- docs/ARCHITECTURE.md — โมดูล, data model, auth/roles, Graph API, webhook, cron, กับดัก Meta. อ่านก่อนแตะ
src/lib/facebook/,prisma/,api/webhooks/,api/cron/ - DESIGN.md — สี, font, layout, component. อ่านก่อนสร้าง/แก้ UI ทุกหน้า
Reference projects (อ่านอย่างเดียว ห้ามแก้)
| ต้องการ | ดูที่ |
|---|---|
| ตัวอย่างเชื่อม FB ที่ใช้งานจริง (Graph client, token exchange, publish/schedule, inbox, webhook HMAC, insights, cron) | D:\Project 4tech\loma-agent\dashboard\src\lib\facebook\, src\app\api\webhooks\messenger\route.ts, src\app\api\cron\ |
| โทนสี / visual language | D:\Project 4tech\Lomalotto\Loma-Lotto\DESIGN.md + frontend\app.css |
dashboard ผูก เพจเดียว ผ่าน env META_PAGE_ID — ระบบนี้ หลายเพจ: ทุกฟังก์ชัน Graph รับ pageId เป็น argument และดึง token จาก DB (รายละเอียดใน ARCHITECTURE.md). ยก pattern มาได้ แต่ห้ามลอก global META_PAGE_ID
Stack (ตาม dashboard)
Next.js 16 App Router + React 19 + TypeScript · Prisma 7 + PostgreSQL · Tailwind v4 · jose session cookie · self-hosted on Coolify (Docker; see docs/gitea-coolify-deploy-guide.md) — cron runs in-container (scripts/cron-runner.mjs), uploads on disk under UPLOAD_DIR (persistent volume)
Next.js 16 ต่างจากที่ model รู้จัก — ก่อนเขียน route/layout/proxy ให้อ่าน guide ใน node_modules/next/dist/docs/. auth gate อยู่ที่ src/proxy.ts (ไม่ใช่ middleware.ts)
กฎหลัก
- Token อยู่ฝั่ง server เท่านั้น — page token เก็บใน DB แบบเข้ารหัส (AES-256-GCM, key
TOKEN_ENCRYPTION_KEY), ห้ามส่งถึง browser, ห้าม log - Error จาก Graph: log เต็มฝั่ง server, คืนข้อความไทยที่ปลอดภัยให้ client (pattern
safeFacebookErrorMessageของ dashboard) - ทุก query/route ที่แตะข้อมูลเพจ ต้องเช็กว่า user มีสิทธิ์ใน เพจนั้น (
PageMember) ไม่ใช่แค่ login แล้ว - การกระทำที่เปลี่ยนสถานะ (อนุมัติ, เผยแพร่, ยกเลิก, เชื่อม/ถอดเพจ, เปลี่ยนสิทธิ์) append ลง
AuditLog— ห้ามแก้/ลบแถว - Webhook route: verify
X-Hub-Signature-256จาก raw body ก่อน parse, ตอบ 200 เสมอหลังผ่าน signature - เปลี่ยน schema → สร้าง Prisma migration (
npx prisma migrate dev --name <ชื่อ>) ห้ามแก้ DB ตรง - UI ภาษาไทย, code/comment/commit ภาษาอังกฤษ
- เอกสารภาษาไทยปนศัพท์เทคนิคอังกฤษ เหมือน workspace อื่นของ 4tech
This is NOT the Next.js you know
This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in node_modules/next/dist/docs/ (resolved from this file's directory; in monorepos the next package may not be visible from the repo root) before writing any code. Heed deprecation notices.
This block is written and re-added by next dev — verify at node_modules/next/dist/server/lib/generate-agent-files.js. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean.