# izecrypt/socialautomation architecture

> Architecture diagram of the GitHub repository izecrypt/socialautomation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/izecrypt/socialautomation
- Repository: https://github.com/izecrypt/socialautomation

## Overview

#### Purpose and Entry Points
Crypto Pulse is a Next.js application that turns crypto/AI RSS news into reviewed, scheduled social posts for X, Telegram, Instagram, TikTok, and YouTube Shorts. Its operator interface starts at `src/app/dashboard/page.tsx`; API routes serve cron, Make.com automation, direct publishing, and AI generation under `src/app/api/`.

#### Persistence and Domain Backbone
Postgres is the system of record, accessed through Prisma. The schema models RSS sources/items, generated posts, queue/publication state, settings, and logs; seed data establishes initial sources and defaults.
- `prisma/schema.prisma`
- `prisma/seed.ts`
- `src/lib/db.ts`

#### RSS Intake, Qualification, and Inbox
News enters either through authenticated Make.com webhook delivery or the internal cron fetch endpoint. Ingestion normalizes and persists items, rejects duplicates, detects configured keywords, scores relevance, and applies niche rules before eligible stories enter the content workflow.
- `src/app/api/webhooks/rss-item/route.ts`
- `src/app/api/cron/fetch-rss/route.ts`
- `src/lib/rss/ingest.ts`
- `src/lib/rss/fetcher.ts`
- `src/lib/deduplication/index.ts`
- `src/lib/scoring/relevance.ts`

#### AI Content and Media Pipeline
A selected RSS item is expanded into platform-specific copy, scripts, and image prompts. The provider layer uses OpenAI when configured and mock content otherwise. Optional media generation produces images, TTS narration, scenes, and ffmpeg-composed video assets for video platforms.
- `src/app/api/ai/generate-from-rss/[rssItemId]/route.ts`
- `src/lib/ai/generator.ts`
- `src/lib/ai/provider.ts`
- `src/lib/ai/video.ts`
- `src/app/api/ai/generate-video/[postId]/route.ts`

#### Review, Queueing, and Scheduling
Generated content receives a risk classification and moves through manual or headless approval into a publishable queue. Queue selection enforces per-platform cadence and configured limits before returning the next eligible post. Dashboard server actions and pages provide the operating surface for inbox, generated content, queue, settings, and logs.
- `src/app/api/ai/risk-check/[generatedPostId]/route.ts`
- `src/app/api/queue/approve/[postId]/route.ts`
- `src/app/api/queue/next-post/route.ts`
- `src/lib/queue/selector.ts`
- `src/lib/scheduling/enforcement.ts`
- `src/app/dashboard/content-queue/page.tsx`

#### Publication and Automation Boundary
Make.com is the principal external orchestration boundary: it retrieves approved posts, publishes through Buffer/Publer or other configured workflows, then records success/failure or platform callbacks. Telegram and Discord also have direct publish routes backed by platform clients. Shared webhook and rate-limit utilities protect machine-facing endpoints.
- `src/app/api/queue/mark-posted/route.ts`
- `src/app/api/webhooks/platform-response/route.ts`
- `src/app/api/telegram/publish/[postId]/route.ts`
- `src/app/api/discord/publish/[postId]/route.ts`
- `src/lib/security/webhook.ts`

#### Runtime and Deployment
The runtime is Node.js 20+ with Next.js, Prisma/PostgreSQL, and optional OpenAI plus local ffmpeg. Local infrastructure is defined by Docker Compose; production materials indicate PM2/Nginx and a cron caller for RSS fetching. Generated video files are served/stored under the public media tree.
- `docker-compose.yml`
- `ecosystem.config.cjs`
- `public/media/videos`
- `docs/deployment.md`

Main entry points: [`prisma/schema.prisma`](https://github.com/izecrypt/socialautomation/blob/main/prisma/schema.prisma) (Postgres / Prisma), [`src/app/api/ai/generate-from-rss/[rssItemId]/route.ts`](https://github.com/izecrypt/socialautomation/blob/main/src/app/api/ai/generate-from-rss/%5BrssItemId%5D/route.ts) (AI Post Generation), [`src/lib/ai/video.ts`](https://github.com/izecrypt/socialautomation/blob/main/src/lib/ai/video.ts) (Video Generation), [`src/lib/rss/ingest.ts`](https://github.com/izecrypt/socialautomation/blob/main/src/lib/rss/ingest.ts) (Ingestion & Qualification)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_operator["Operator Surface"]
  node_dashboard["Dashboard<br/>Next.js UI<br/>[page.tsx]"]
  node_queue_ui["Content Queue<br/>Dashboard page<br/>[page.tsx]"]
end

subgraph group_pipeline["Content Pipeline"]
  node_rss_webhook["RSS Webhook<br/>API route<br/>[route.ts]"]
  node_rss_cron["RSS Fetch Cron<br/>API route<br/>[route.ts]"]
  node_rss_fetcher["RSS Fetcher<br/>RSS client<br/>[fetcher.ts]"]
  node_ingestion["Ingestion &amp; Qualification<br/>Domain service<br/>[ingest.ts]"]
  node_relevance["Relevance Scoring<br/>Scoring service<br/>[relevance.ts]"]
  node_ai_generation["AI Post Generation<br/>API route<br/>[route.ts]"]
  node_ai_provider{{"AI Provider<br/>Provider layer<br/>[provider.ts]"}}
  node_video_generation["Video Generation<br/>Media pipeline<br/>[video.ts]"]
  node_risk_check["Risk Check<br/>API route<br/>[route.ts]"]
  node_approval["Approval<br/>Queue API<br/>[route.ts]"]
  node_queue_selector["Queue Selection<br/>Queue service<br/>[selector.ts]"]
end

subgraph group_automation["Publishing Automation"]
  node_make{{"Make.com<br/>External orchestrator"}}
  node_publish_status["Publication Status<br/>API routes<br/>[route.ts]"]
  node_direct_publish["Direct Publishers<br/>Platform APIs<br/>[route.ts]"]
end

subgraph group_runtime["Runtime"]
  node_database[("Postgres / Prisma<br/>System of record<br/>[schema.prisma]")]
  node_media_storage["Video Media<br/>Public assets"]
  node_deployment["Deployment Runtime<br/>Node / Next.js<br/>[deployment.md]"]
end

node_make -->|"RSS delivery"| node_rss_webhook
node_rss_webhook -->|"ingest item"| node_ingestion
node_rss_cron -->|"fetch feeds"| node_rss_fetcher
node_rss_fetcher -->|"feed items"| node_ingestion
node_ingestion -->|"qualify"| node_relevance
node_relevance -->|"eligible items"| node_database
node_dashboard -->|"operate content"| node_database
node_dashboard -->|"generate"| node_ai_generation
node_ai_generation -->|"copy and scripts"| node_ai_provider
node_ai_generation -->|"generated posts"| node_database
node_ai_generation -->|"video requests"| node_video_generation
node_video_generation -->|"rendered assets"| node_media_storage
node_video_generation -->|"asset metadata"| node_database
node_ai_generation -->|"generated content"| node_risk_check
node_risk_check -->|"review result"| node_approval
node_queue_ui -->|"manual approval"| node_approval
node_approval -->|"queue state"| node_database
node_make -->|"request next post"| node_queue_selector
node_queue_selector -->|"cadence and limits"| node_database
node_make -->|"publish result"| node_publish_status
node_direct_publish -->|"delivery status"| node_publish_status
node_publish_status -->|"publication logs"| node_database
node_deployment -.->|"scheduled invocation"| node_rss_cron

click node_dashboard "https://github.com/izecrypt/socialautomation/blob/main/src/app/dashboard/page.tsx"
click node_queue_ui "https://github.com/izecrypt/socialautomation/blob/main/src/app/dashboard/content-queue/page.tsx"
click node_rss_webhook "https://github.com/izecrypt/socialautomation/blob/main/src/app/api/webhooks/rss-item/route.ts"
click node_rss_cron "https://github.com/izecrypt/socialautomation/blob/main/src/app/api/cron/fetch-rss/route.ts"
click node_rss_fetcher "https://github.com/izecrypt/socialautomation/blob/main/src/lib/rss/fetcher.ts"
click node_ingestion "https://github.com/izecrypt/socialautomation/blob/main/src/lib/rss/ingest.ts"
click node_relevance "https://github.com/izecrypt/socialautomation/blob/main/src/lib/scoring/relevance.ts"
click node_database "https://github.com/izecrypt/socialautomation/blob/main/prisma/schema.prisma"
click node_ai_generation "https://github.com/izecrypt/socialautomation/blob/main/src/app/api/ai/generate-from-rss/%5BrssItemId%5D/route.ts"
click node_ai_provider "https://github.com/izecrypt/socialautomation/blob/main/src/lib/ai/provider.ts"
click node_video_generation "https://github.com/izecrypt/socialautomation/blob/main/src/lib/ai/video.ts"
click node_media_storage "https://github.com/izecrypt/socialautomation/tree/main/public/media/videos"
click node_risk_check "https://github.com/izecrypt/socialautomation/blob/main/src/app/api/ai/risk-check/%5BgeneratedPostId%5D/route.ts"
click node_approval "https://github.com/izecrypt/socialautomation/blob/main/src/app/api/queue/approve/%5BpostId%5D/route.ts"
click node_queue_selector "https://github.com/izecrypt/socialautomation/blob/main/src/lib/queue/selector.ts"
click node_publish_status "https://github.com/izecrypt/socialautomation/blob/main/src/app/api/queue/mark-posted/route.ts"
click node_direct_publish "https://github.com/izecrypt/socialautomation/blob/main/src/app/api/telegram/publish/%5BpostId%5D/route.ts"
click node_deployment "https://github.com/izecrypt/socialautomation/blob/main/docs/deployment.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_dashboard,node_queue_ui toneBlue
class node_rss_webhook,node_rss_cron,node_rss_fetcher,node_ingestion,node_relevance,node_ai_generation,node_ai_provider,node_video_generation,node_risk_check,node_approval,node_queue_selector toneAmber
class node_make,node_publish_status,node_direct_publish toneMint
class node_database,node_media_storage,node_deployment toneRose
```

## Components

### Operator Surface

- [Dashboard](https://github.com/izecrypt/socialautomation/blob/main/src/app/dashboard/page.tsx): Next.js UI · Operator workspace for inbox, content, queue, settings, and logs. · `src/app/dashboard/page.tsx`
- [Content Queue](https://github.com/izecrypt/socialautomation/blob/main/src/app/dashboard/content-queue/page.tsx): Dashboard page · `src/app/dashboard/content-queue/page.tsx`

### Content Pipeline

- [RSS Webhook](https://github.com/izecrypt/socialautomation/blob/main/src/app/api/webhooks/rss-item/route.ts): API route · `src/app/api/webhooks/rss-item/route.ts`
- [RSS Fetch Cron](https://github.com/izecrypt/socialautomation/blob/main/src/app/api/cron/fetch-rss/route.ts): API route · `src/app/api/cron/fetch-rss/route.ts`
- [RSS Fetcher](https://github.com/izecrypt/socialautomation/blob/main/src/lib/rss/fetcher.ts): RSS client · `src/lib/rss/fetcher.ts`
- [Ingestion & Qualification](https://github.com/izecrypt/socialautomation/blob/main/src/lib/rss/ingest.ts): Domain service · Normalizes, deduplicates, scores, and qualifies incoming stories. · `src/lib/rss/ingest.ts`
- [Relevance Scoring](https://github.com/izecrypt/socialautomation/blob/main/src/lib/scoring/relevance.ts): Scoring service · Applies configured keywords and niche rules. · `src/lib/scoring/relevance.ts`
- [AI Post Generation](https://github.com/izecrypt/socialautomation/blob/main/src/app/api/ai/generate-from-rss/%5BrssItemId%5D/route.ts): API route · Expands selected RSS items into platform-specific copy and scripts. · `src/app/api/ai/generate-from-rss/[rssItemId]/route.ts`
- [AI Provider](https://github.com/izecrypt/socialautomation/blob/main/src/lib/ai/provider.ts): Provider layer · Uses OpenAI when configured, otherwise mock content. · `src/lib/ai/provider.ts`
- [Video Generation](https://github.com/izecrypt/socialautomation/blob/main/src/lib/ai/video.ts): Media pipeline · Creates images, narration, scenes, and ffmpeg-composed video. · `src/lib/ai/video.ts`
- [Risk Check](https://github.com/izecrypt/socialautomation/blob/main/src/app/api/ai/risk-check/%5BgeneratedPostId%5D/route.ts): API route · Classifies generated content risk before approval. · `src/app/api/ai/risk-check/[generatedPostId]/route.ts`
- [Approval](https://github.com/izecrypt/socialautomation/blob/main/src/app/api/queue/approve/%5BpostId%5D/route.ts): Queue API · Moves reviewed or headlessly approved posts into the queue. · `src/app/api/queue/approve/[postId]/route.ts`
- [Queue Selection](https://github.com/izecrypt/socialautomation/blob/main/src/lib/queue/selector.ts): Queue service · Selects the next eligible post under cadence and limit rules. · `src/lib/queue/selector.ts`

### Publishing Automation

- **Make.com**: External orchestrator · Delivers RSS and retrieves or publishes approved posts.
- [Publication Status](https://github.com/izecrypt/socialautomation/blob/main/src/app/api/queue/mark-posted/route.ts): API routes · Records publisher results and platform callbacks. · `src/app/api/queue/mark-posted/route.ts`
- [Direct Publishers](https://github.com/izecrypt/socialautomation/blob/main/src/app/api/telegram/publish/%5BpostId%5D/route.ts): Platform APIs · Publishes directly to Telegram or Discord. · `src/app/api/telegram/publish/[postId]/route.ts`

### Runtime

- [Postgres / Prisma](https://github.com/izecrypt/socialautomation/blob/main/prisma/schema.prisma): System of record · Stores sources, RSS items, posts, queue state, settings, and logs. · `prisma/schema.prisma`
- [Video Media](https://github.com/izecrypt/socialautomation/tree/main/public/media/videos): Public assets · `public/media/videos`
- [Deployment Runtime](https://github.com/izecrypt/socialautomation/blob/main/docs/deployment.md): Node / Next.js · Docker locally; PM2, Nginx, and cron in production. · `docs/deployment.md`

## Connections

- Make.com → RSS Webhook: RSS delivery
- RSS Webhook → Ingestion & Qualification: ingest item
- RSS Fetch Cron → RSS Fetcher: fetch feeds
- RSS Fetcher → Ingestion & Qualification: feed items
- Ingestion & Qualification → Relevance Scoring: qualify
- Relevance Scoring → Postgres / Prisma: eligible items
- Dashboard → Postgres / Prisma: operate content
- Dashboard → AI Post Generation: generate
- AI Post Generation → AI Provider: copy and scripts
- AI Post Generation → Postgres / Prisma: generated posts
- AI Post Generation → Video Generation: video requests
- Video Generation → Video Media: rendered assets
- Video Generation → Postgres / Prisma: asset metadata
- AI Post Generation → Risk Check: generated content
- Risk Check → Approval: review result
- Content Queue → Approval: manual approval
- Approval → Postgres / Prisma: queue state
- Make.com → Queue Selection: request next post
- Queue Selection → Postgres / Prisma: cadence and limits
- Make.com → Publication Status: publish result
- Direct Publishers → Publication Status: delivery status
- Publication Status → Postgres / Prisma: publication logs
- Deployment Runtime → RSS Fetch Cron: scheduled invocation
