Build Guide

Complete System Design for This Blog Platform

This page documents the exact architecture and implementation flow used on this website. You can follow it to build the same automated MDX blog engine in your own project.

1. Trend Ingestion

Pull trending topics from market/news feeds and normalize topic candidates.

2. Topic Selection

Remove recently used topics and choose the highest novelty + relevance topic.

3. Gemini MDX Generation

Generate structured MDX content with consistent sections and SEO-friendly formatting.

4. Content Persistence

Store slug, topic, excerpt, MDX body, timestamps, and source topics in PostgreSQL.

5. SEO Distribution

Expose posts through HTML pages, metadata, sitemap, RSS, robots, and llms.txt.

6. Scheduled Publishing

Run generation endpoint 3x daily via cron for steady content freshness.

flow://runtime/publishsequence

1. cron -> /api/automation/generate-post

2. fetchTrendingTopics() -> [topics]

3. selectTopic(topics, recentTopics)

4. generateBlogDraftWithGemini(topic) -> title/excerpt/contentMdx

5. ensureUniqueSlug(title)

6. insertBlogPost(...) -> PostgreSQL

7. /blogs and /blogs/[slug] instantly reflect new post

Database Contract

The core storage model is intentionally simple to keep publishing fast and query-friendly.

CREATE TABLE blog_posts (
  id BIGSERIAL PRIMARY KEY,
  slug TEXT UNIQUE NOT NULL,
  title TEXT NOT NULL,
  excerpt TEXT NOT NULL,
  content_markdown TEXT NOT NULL,
  topic TEXT NOT NULL,
  source_topics JSONB NOT NULL DEFAULT '[]'::jsonb,
  published_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

Replication Steps

  1. 1Create a Next.js app with App Router and server-side routes.
  2. 2Create `blog_posts` table in PostgreSQL with slug + published_at indexes.
  3. 3Add a trend fetcher service (RSS or API provider).
  4. 4Generate MDX article JSON with Gemini and validate required fields.
  5. 5Insert article into DB with unique slug generation.
  6. 6Render archive (`/blogs`) and detail (`/blogs/[slug]`) pages from DB.
  7. 7Add metadata, JSON-LD, sitemap, RSS, and llms.txt endpoints.
  8. 8Secure cron endpoint with `CRON_SECRET` and schedule 3 runs daily.

Ops Checklist

Environment

Set `GEMINI_API_KEY`, `DATABASE_URL`, `CRON_SECRET`, and `GEMINI_MODEL`.

Scheduling

Configure Vercel cron jobs for three daily publish windows.

SEO

Keep sitemap, feed.xml, llms.txt, and article schema continuously updated.

Quality

Run periodic prompt tuning for better topic relevance and structure quality.

Want to extend this architecture with moderation, search, or multilingual publishing?

Contact the Team
System Design | CodePrompt Blog