# 00 — Architecture Overview

**Scope:** Business-grounded content platform on the existing Next.js application: website intelligence, brand, RAG, generation, QA, approval, scheduling, and publishing.

---

## 1. Vision

```
PROJECT (configuration)
   ↓
WEBSITE + BRAND
   ↓
WEBSITE INTELLIGENCE
   ↓
BUSINESS CONTEXT          ← factual source of truth
   ↓
STORYTELLING FRAMEWORK    ← narrative structure only
   ↓
CONTENT STRATEGY
   ↓
CONTENT SEQUENCE
   ↓
┌────────┬────────┐
AI+RAG  MANUAL   CSV
└────────┴────────┘
   ↓
UNIFIED CONTENT LIBRARY
   ↓
QA / REVIEW / APPROVAL
   ↓
SCHEDULING (project timezone, 1–5/day, ±30 min)
   ↓
PUBLISHING  publishPostToPlatforms()
```

PostSync Pro is **not** a simple AI post generator. The user's real business information is the source of truth. Storytelling is a narrative framework. Platform RAG explains how to create content for each platform.

---

## 2. Current application

| Layer | Implementation |
|-------|----------------|
| Framework | Next.js 15 App Router, React 19, Zustand, Tailwind 4 |
| Storage | MariaDB preferred + JSON under `data/` |
| Project config | Name, website URL, industry label, timezone, target markets, active/paused |
| Website intelligence | `src/lib/context/website-intelligence.ts` — scrape, never invent missing facts |
| Business context | `src/lib/context/business-context.ts` — user > website > inference |
| Storytelling | `src/lib/context/storytelling-framework.ts` — configurable 10-beat structure |
| Platform RAG | `src/lib/rag/` → `data/knowledge/{platform}/` when `RAG_ENABLED=true` |
| Text AI | `AI_PROVIDER` = `anthropic` or `openai` |
| Publish | Shared `publish-post.ts` for LinkedIn, Facebook Page, Instagram Business, YouTube |
| Schedule | Smart Schedule 1–5/day + `cron-poller` / `/api/cron/scheduled-publish` |

**Key code anchors**

- Context: `src/lib/context/`
- Generation: `src/lib/generation/run-generation.ts`
- Social: `src/lib/social/publish-post.ts`
- Scheduling: `src/lib/scheduling/run-scheduled-publish.ts`
- Storage: `src/lib/storage/`, `src/lib/db/repositories/`

---

## 3. Source of truth

```
Explicit user input
        >
Verified website information
        >
AI inference
```

Missing phone / email / service are stored as `missing` / `unknown`. AI must not fabricate company facts or customer results. Unverified outcomes use educational or hypothetical language.

---

## 4. Related docs

- [architecture/04-CONTENT-PIPELINE.md](./04-CONTENT-PIPELINE.md)
- [rag/01-DATA-SOURCES.md](../rag/01-DATA-SOURCES.md)
- [rag/02-RAG-ARCHITECTURE.md](../rag/02-RAG-ARCHITECTURE.md)
- [social/01-PUBLISHING-OVERVIEW.md](../social/01-PUBLISHING-OVERVIEW.md)
