# Finzone — CMS Tài chính/Crypto/Forex/Chứng khoán

## Mục tiêu
CMS hiện đại cho trang tin tài chính, có công cụ SEO, AI viết bài, và Public API.

## Stack
- **Framework**: Next.js 15 (App Router) + TypeScript + Tailwind + shadcn/ui
- **DB**: PostgreSQL 16 (Docker)
- **ORM**: Prisma
- **Content**: MDX (next-mdx-remote) — embed chart, tweet, image, callout
- **Auth (admin)**: JWT cookie session, password bcrypt
- **AI**: OpenAI-compatible (configurable base URL + key qua admin)
- **Public API**: REST `/api/v1/*` với `X-API-Key` header

## Domain model (Prisma)
- `User` — admin login
- `Setting` — global key/value (pw hash, seo defaults, ai key, site url)
- `Category` — slug, name, description, parentId (cây)
- `Tag` — slug, name
- `Post` — slug, title, excerpt, content (MDX), status (draft/published), publishedAt, authorId, categoryId, tags[], coverImage, viewCount
- `SeoMeta` — postId, title, description, canonical, ogImage, schemaJson
- `AiDraft` — prompt, model, output, postId(opt), createdAt
- `ApiKey` — name, hash, scopes[], lastUsed, createdAt
- `Media` — uploaded files (path, mime, size)
- `Webhook` — git/external integrations

## Modules / pages

### Public (SEO-first)
- `/` — landing: top tin, sectors (crypto/forex/chứng khoán), latest, featured
- `/[category]` — list bài theo category, có pagination
- `/post/[slug]` — bài viết (SSG + ISR), JSON-LD Article, OG image
- `/tag/[slug]`, `/search?q=` — search-as-you-type
- `/sitemap.xml`, `/robots.txt`, `/feed.xml` (RSS)
- Per-page: dynamic `<head>` từ SeoMeta hoặc fallback Setting defaults

### Admin (auth required)
- `/admin` — dashboard: tổng bài, view, draft, AI usage
- `/admin/posts` — list, lọc theo status/category, bulk action
- `/admin/posts/new` & `/admin/posts/[id]` — editor MDX (Monaco), preview, AI assistant panel, SEO panel, schedule publish
- `/admin/categories`, `/admin/tags` — CRUD
- `/admin/media` — upload, gallery
- `/admin/seo` — site-wide SEO defaults, OG image generator, sitemap status, broken link checker
- `/admin/seo-tools` — readability score, keyword density analyzer, meta length checker, structured data preview
- `/admin/ai` — chat playground, prompt templates (article outline, SEO meta, social caption)
- `/admin/api-keys` — generate/revoke
- `/admin/settings` — site URL, default OG, AI provider config, password change

### API v1 (public, key-based)
- `GET /api/v1/posts?category=&tag=&page=` — list
- `GET /api/v1/posts/:slug` — detail (full content)
- `GET /api/v1/categories`, `GET /api/v1/tags`
- `POST /api/v1/ai/draft` — protected, body `{prompt, mode}` → text
- `GET /api/v1/sitemap.json` — bonus
- `POST /api/v1/posts` (scope=write) — create draft programmatically

## SEO toolkit
1. Auto-generate sitemap + robots
2. JSON-LD: Article, BreadcrumbList, Organization, WebSite (+ SearchAction)
3. OG image generator (Satori @vercel/og)
4. Readability score: Flesch-Kincaid implementation, hiển thị inline editor
5. Keyword density: top-10 từ khóa trong bài
6. Meta-length validator: title ≤ 60, description ≤ 160
7. Internal link suggester (search slugs từ bài hiện có)
8. Canonical override
9. RSS feed
10. ISR (revalidate 60s) — vừa nhanh vừa fresh

## AI writer
- Settings: `AI_BASE_URL`, `AI_API_KEY`, `AI_MODEL` (default `gpt-4o-mini`)
- Modes:
  - `outline` — brief → cấu trúc heading
  - `expand` — outline → bài đầy đủ
  - `polish` — refine văn phong tiếng Việt
  - `seo` — generate title + meta + tags + slug
  - `summarize` — TL;DR
- Stream qua SSE để editor hiển thị từng token
- Lưu mỗi lần gọi vào `AiDraft` để rollback

## Deploy plan
- Source: `/data/video-pipeline/LXC4103/project/finzone` (NFS, scan-able by PM)
- Build trên LXC 4103 (đã có docker registry 127.0.0.1:5000)
- Push image `127.0.0.1:5000/finzone:<tag>` → pull về LXC 4015
- LXC 4015 chạy 2 container:
  - `finzone-app` (Next.js standalone, port 3000)
  - `finzone-postgres` (Postgres 16, volume `/var/lib/finzone-pg`)
- Compose file ở `/opt/finzone/docker-compose.prod.yml`
- Truy cập: `http://192.168.40.25:3000`

## Mở rộng (sau v1)
- Comment system (Giscus / built-in)
- Newsletter (email subscribe)
- Multi-author + role
- i18n (EN + VI)
- Analytics dashboard (Plausible self-host)
- Crypto price widget (CoinGecko free API)
