How sonnysangha/reddit-ai-clone-nextjs-15-ai-agents-sanity-clerk works
Project type and purpose
• This is a full-stack, AI-powered Reddit clone built on Next.js 15, Sanity CMS, Clerk Auth, and OpenAI.
• It offers community creation, posting, commenting, voting, real-time updates, and AI content moderation.
File structure
• app/: Next.js 15 App Router routes & layouts (admin vs. user-facing).
• action/: Server Actions for CRUD (posts, comments, votes, reports).
• components/: UI React components (posts, comments, header, sidebar, UI primitives).
• sanity/: Sanity Studio config, schemas, and typed client logic.
• lib/: Shared utilities & base URL definitions.
• hooks/: Client-only React hooks.
• middleware.ts: Auth/session middleware.
• public/ & images/: Static assets.
• tools/: CLI and prompt builders for admin tools.
• config files: next.config.ts, tsconfig.json, postcss.config.mjs, eslint.config.mjs.
Additional insights from README
• Highlights Next.js Server Components & Actions, Turbopack, Tailwind CSS, Radix UI.
• Authentication delegated to Clerk.
• Content storage & real-time updates via Sanity.
• AI moderation uses OpenAI API during content creation workflows.
Main components and their interactions
a. Frontend (Next.js App Router)
• Routes under /app handle page rendering.
• Server Components fetch data via Sanity client & Clerk.
• Client Components for interactivity (buttons, forms, hooks).
• UI styled with Tailwind + Radix UI primitives.
b. Server Actions (action/ folder)
• Entry points for create/update/delete events.
• Validate user (via Clerk session), then call Sanity client libraries.
• Trigger AI moderation by calling OpenAI before persisting.
c. Sanity CMS
• Headless CMS holds posts, comments, subreddits, users, votes.
• Studio under /sanity for admin tooling.
• Real-time updates via Sanity “live” client.
d. Clerk Auth Service
• Manages user signup, signin, sessions.
• Protects server actions via middleware.
e. OpenAI API
• Content moderation endpoint.
• Called from server actions before content persistence.
f. Client-side state & real-time
• Hooks (use-mobile, live subscriptions).
• Optimistic UI updates on votes/comments.
Architectural patterns and design principles
• App Router / Server Components: clear separation of server vs. client rendering.
• Server Actions: centralize data mutations, enforce auth & moderation.
• Headless CMS: decoupled content storage, real-time event streams.
• Component-driven UI: reusable, isolated UI pieces in /components.
Detail
• Sanity schemas vs. Studio vs. client APIs.
• Middleware for auth checks.
• Don’t omit the content moderation step.