1 · System Architecture
Frontend → Supabase → Edge Functions → AI providers (Claude / Whisper / Flux)
flowchart LR
subgraph Client["📱 Client (Vue 3)"]
UI[Dashboard / Calendar / Editor / Video Studio]
Pinia[(Pinia stores
auth · brand · content)] UI <--> Pinia end subgraph Supa["🗄️ Supabase"] Auth[Auth + RLS] DB[(PostgreSQL
14 tables)] Storage[Storage Buckets
media · videos · rendered] Fns[Edge Functions
Deno] end subgraph AI["🤖 AI Providers"] Claude[Claude Sonnet 4.6
caption · plan · recommend] Whisper[OpenAI Whisper
Thai transcription] Flux[Replicate Flux
image gen — optional] FFmpeg[ffmpeg worker
burn subtitle] end subgraph Distro["📤 Distribution (Phase 3)"] Meta[Meta Graph API
FB + IG] Line[LINE Messaging API] TT[TikTok API] end Pinia -- supabase-js --> Auth Pinia -- CRUD via RLS --> DB Pinia -- upload --> Storage Pinia -- functions.invoke --> Fns Fns --> Claude Fns --> Whisper Fns --> Flux Fns --> FFmpeg Fns -. future .-> Meta Fns -. future .-> Line Fns -. future .-> TT style Client fill:#e0f2fe,stroke:#0ea5e9 style Supa fill:#dcfce7,stroke:#22c55e style AI fill:#fef3c7,stroke:#f59e0b style Distro fill:#fce7f3,stroke:#ec4899
auth · brand · content)] UI <--> Pinia end subgraph Supa["🗄️ Supabase"] Auth[Auth + RLS] DB[(PostgreSQL
14 tables)] Storage[Storage Buckets
media · videos · rendered] Fns[Edge Functions
Deno] end subgraph AI["🤖 AI Providers"] Claude[Claude Sonnet 4.6
caption · plan · recommend] Whisper[OpenAI Whisper
Thai transcription] Flux[Replicate Flux
image gen — optional] FFmpeg[ffmpeg worker
burn subtitle] end subgraph Distro["📤 Distribution (Phase 3)"] Meta[Meta Graph API
FB + IG] Line[LINE Messaging API] TT[TikTok API] end Pinia -- supabase-js --> Auth Pinia -- CRUD via RLS --> DB Pinia -- upload --> Storage Pinia -- functions.invoke --> Fns Fns --> Claude Fns --> Whisper Fns --> Flux Fns --> FFmpeg Fns -. future .-> Meta Fns -. future .-> Line Fns -. future .-> TT style Client fill:#e0f2fe,stroke:#0ea5e9 style Supa fill:#dcfce7,stroke:#22c55e style AI fill:#fef3c7,stroke:#f59e0b style Distro fill:#fce7f3,stroke:#ec4899
2 · User Flow — จาก signup → posted
เส้นทางหลัก เริ่มจาก marketing สร้างแผน → owner approve → admin โพสต์
flowchart TD
A([👤 Sign up / Login]) --> B[สร้าง Brand
tone · target · products · do_not_use] B --> C{มีแผนเดือนนี้?} C -- ไม่มี --> D[/สร้างแผน 30 วัน/
กรอก goal + channel] D --> E[🤖 Claude generate
30 days × N channels] E --> F[Preview → Save plan] F --> G[Content Calendar
month / week / kanban] C -- มีแล้ว --> G G --> H[เปิด Content card] H --> I[ปรับ caption ต่อ channel
shorter · sales · friendly · +#] H --> J[Generate image prompt
เลือก style → AI prompt] H --> K[Upload media / video] K --> L{มีวิดีโอ?} L -- yes --> M[Video Subtitle Studio
Whisper transcribe → edit → burn] I --> N[Status: draft → review] J --> N M --> N N --> O[/Approval queue/] O --> P{Owner approve?} P -- ✅ --> Q[Status: ready] P -- ❌ --> H Q --> R[Admin โพสต์
หรือ auto-post API] R --> S[Status: posted
+ external_url] S --> T[เก็บ performance อัตโนมัติ] T --> U[Analytics + AI recommend
เดือนถัดไป] U --> D style D fill:#fef3c7 style E fill:#fef3c7 style M fill:#fce7f3 style U fill:#dcfce7
tone · target · products · do_not_use] B --> C{มีแผนเดือนนี้?} C -- ไม่มี --> D[/สร้างแผน 30 วัน/
กรอก goal + channel] D --> E[🤖 Claude generate
30 days × N channels] E --> F[Preview → Save plan] F --> G[Content Calendar
month / week / kanban] C -- มีแล้ว --> G G --> H[เปิด Content card] H --> I[ปรับ caption ต่อ channel
shorter · sales · friendly · +#] H --> J[Generate image prompt
เลือก style → AI prompt] H --> K[Upload media / video] K --> L{มีวิดีโอ?} L -- yes --> M[Video Subtitle Studio
Whisper transcribe → edit → burn] I --> N[Status: draft → review] J --> N M --> N N --> O[/Approval queue/] O --> P{Owner approve?} P -- ✅ --> Q[Status: ready] P -- ❌ --> H Q --> R[Admin โพสต์
หรือ auto-post API] R --> S[Status: posted
+ external_url] S --> T[เก็บ performance อัตโนมัติ] T --> U[Analytics + AI recommend
เดือนถัดไป] U --> D style D fill:#fef3c7 style E fill:#fef3c7 style M fill:#fce7f3 style U fill:#dcfce7
3 · 11 Modules
คลิกแต่ละการ์ดเพื่อดู input / output / สถานะ
1Brand Profile ▸
Input: name, tone, target, products, brand_color, logo, do_not_use
Output: AI context ที่ใช้ทุก request
Table: brands, brand_members
✓ ready
2AI 30-Day Generator ▸
Input: goal, product_focus, campaign, channels
Output: 30 contents + caption ทุก channel (FB/IG/LINE/TikTok/YT/Blog)
AI: Claude Sonnet 4.6 · max 8192 tokens · JSON output
✓ ready
3Content Calendar ▸
Views: Month / Week / Kanban
Action: drag-drop เปลี่ยนวัน / drag เปลี่ยน status (kanban)
Lib: FullCalendar + vuedraggable
✓ ready
4Channel Selection ▸
Channels: FB · IG Post · IG Story · LINE OA · TikTok · YT Shorts · Blog
Per channel: caption แยก · is_ready · posted_at · external_url
Table: content_channels (unique on content_id+channel)
✓ ready
5AI Caption Generator ▸
Modifiers: shorter · premium · sales · friendly · +# · LINE OA · TikTok hook
Context: brand tone + do_not_use + channel-specific guide
Endpoint: /functions/generate-caption
✓ ready
6AI Image Prompt ▸
Styles: modern clean · premium gold · factory realistic · cute · neon · infographic
Output: EN prompt + --ar 1:1 --v 6 พร้อมใช้กับ MJ / Flux / SDXL
Storage: เก็บ prompt ใน contents.image_prompt
⚠ prompt only · ต่อ Flux/Replicate ใน Phase 2
7Media Asset Library ▸
Types: image · video · poster · logo · template · audio
Storage: Supabase Storage (media public, videos private)
Link: content_media (n:m) — ผูก media กับ content + channel
✓ ready
8Video Subtitle Studio ▸
Flow: upload → Whisper (TH) → split segments → edit → burn
Aspect: 9:16 · 1:1 · 16:9
Style: font size · color · bg (เก็บใน videos.subtitle_style)
Export: .srt + .mp4 (burn)
⚠ render ต้องต่อ ffmpeg worker
9Approval Flow ▸
Path: Marketing → Designer → Owner approve → Admin post
Status: pending · approved · rejected · changes_requested
Comment: content_comments (thread per content)
✓ ready
10LINE OA Broadcast ▸
v1: text broadcast <250 ตัวอักษร + CTA button
v2 (Phase 3): flex message builder + rich menu
CTA: โทร · ทักแชท · เช็กราคา · สมัครสมาชิก
⚠ caption ready · auto-send Phase 3
11Analytics ▸
Metrics: reach · impressions · engagement · click · share · save · views
AI: ปุ่ม "แนะนำคอนเทนต์เดือนหน้า" → Claude วิเคราะห์ top 30
Source: post_performance (ดึงจาก Meta/LINE/TT — Phase 4)
⚠ UI ready · ต่อ insight API Phase 4
4 · Data Model (14 tables)
RLS เปิดทุกตาราง · helper has_brand_access() กรองตาม brand membership
erDiagram
PROFILES ||--o{ BRANDS : owns
PROFILES ||--o{ BRAND_MEMBERS : ""
BRANDS ||--o{ BRAND_MEMBERS : has
BRANDS ||--o{ CAMPAIGNS : ""
BRANDS ||--o{ CONTENT_PLANS : ""
BRANDS ||--o{ CONTENTS : ""
BRANDS ||--o{ MEDIA_ASSETS : ""
BRANDS ||--o{ VIDEOS : ""
CAMPAIGNS ||--o{ CONTENT_PLANS : ""
CONTENT_PLANS ||--o{ CONTENTS : ""
CONTENTS ||--o{ CONTENT_CHANNELS : ""
CONTENTS ||--o{ CONTENT_MEDIA : ""
CONTENTS ||--o{ APPROVALS : ""
CONTENTS ||--o{ CONTENT_COMMENTS : ""
CONTENTS ||--o{ VIDEOS : ""
MEDIA_ASSETS ||--o{ CONTENT_MEDIA : ""
VIDEOS ||--o{ SUBTITLES : ""
CONTENT_CHANNELS ||--o{ POST_PERFORMANCE : ""
PROFILES { uuid id PK; text email; text full_name; user_role role }
BRANDS { uuid id PK; text name; text tone_of_voice; jsonb products; text do_not_use }
CONTENT_PLANS { uuid id PK; date month; text goal; channel_type[] channels }
CONTENTS { uuid id PK; date scheduled_date; text topic; content_status status; text image_prompt }
CONTENT_CHANNELS { uuid id PK; channel_type channel; text caption; bool is_ready }
MEDIA_ASSETS { uuid id PK; media_type type; text url; text[] tags }
VIDEOS { uuid id PK; text aspect_ratio; text transcription_status; jsonb subtitle_style }
SUBTITLES { uuid id PK; int start_ms; int end_ms; text text }
APPROVALS { uuid id PK; approval_status status; text comment }
POST_PERFORMANCE { uuid id PK; int reach; int engagement; int clicks }
5 · AI Pipeline
ทุก call ผ่าน Edge Function — API key ไม่ leak ฝั่ง client
sequenceDiagram
participant U as User
participant V as Vue App
participant S as Supabase
participant EF as Edge Function
participant C as Claude API
participant W as Whisper API
Note over U,C: Flow 1: สร้างแผน 30 วัน
U->>V: กรอก goal + channels
V->>EF: invoke('generate-content-plan', payload)
EF->>C: POST /v1/messages (system+user, max 8192)
C-->>EF: JSON array 30 days
EF-->>V: { days: [...] }
V->>S: insert content_plans + contents + content_channels
V-->>U: ไป Calendar
Note over U,W: Flow 2: Video subtitle
U->>V: upload .mp4
V->>S: storage.upload + insert media_assets + videos
U->>V: กด "ถอดเสียง AI"
V->>EF: invoke('transcribe-video', {video_id})
EF->>S: fetch video URL
EF->>W: POST /v1/audio/transcriptions (whisper-1, lang=th)
W-->>EF: { segments: [...] }
EF->>S: insert subtitles (start_ms, end_ms, text)
EF-->>V: ok
V-->>U: แสดง subtitle editor
Note over U,C: Flow 3: AI recommendation
U->>V: กด "แนะนำเดือนหน้า"
V->>EF: invoke('recommend-next-month', {brand_id})
EF->>S: query top 30 by engagement
EF->>C: วิเคราะห์ JSON performance
C-->>EF: บทวิเคราะห์ + แนะนำ
EF-->>V: { text }
6 · Roles & Permissions
5 บทบาท · enforce ด้วย Postgres RLS + frontend guard
| Role | Brand | Plan | Caption | Media | Video | Approve | Post | Settings |
|---|---|---|---|---|---|---|---|---|
| 👑 Owner | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ final | ✅ | ✅ |
| 📣 Marketing | 👁 | ✅ | ✅ | ✅ | 📝 idea | 📤 request | — | — |
| 🎨 Designer | 👁 | 👁 | 👁 | ✅ | — | — | — | — |
| 🎬 Video Editor | 👁 | 👁 | — | ✅ video | ✅ | — | — | — |
| ⚙️ Admin | 👁 | — | — | 👁 | 👁 | — | ✅ | ✅ |
✅ = แก้ได้ · 👁 = อ่านอย่างเดียว · 📝 = สร้าง draft · 📤 = ส่งให้คนอื่น · — = ไม่เกี่ยว
7 · Screen Map
10 หน้าหลัก · responsive · sidebar desktop / top bar mobile
8 · Roadmap — 8 สัปดาห์
Phase 0-2 = MVP ปัจจุบัน · Phase 3-5 = scale + distribution
Cost estimate (5-10 brand · 300 โพสต์/เดือน)
| Supabase Pro | $25 |
| Claude Sonnet API | $30-60 |
| OpenAI Whisper | $10-20 |
| Replicate Flux | $20-40 |
| Storage (50GB) | $5 |
| Vercel / CF Pages | $0 |
| รวม | $90-150 / เดือน (≈ 3,000-5,000 บาท) |