How dhruv-jangid/nextblog works
Project Type & Purpose
• MetaPress is a mono-repo full-stack blogging platform built with Next.js 16 (App Router), React 19, Bun, and Turborepo.
• It provides server-rendered pages, rich content creation (TipTap), advanced auth & moderation, admin dashboard, Redis caching, and AI integration (MCP).
High-Level File Structure & Architectural Patterns
• apps/web/
• src/app/ – Next.js App Router (page.tsx, layout.tsx, API routes under src/app/api/)
• src/components/ – Reusable UI & provider components
• src/core/ – Business logic services (auth, blog, comment, image, mail, mcp, cache, user)
• src/db/ – Drizzle ORM schema, relations, Snowflake ID generator
• src/lib/ – Utility functions (auth-client, image upload/NSFW check, profanity, slugify, Redis client)
• src/shared/ – Shared schemas & types for API contracts
• Turborepo orchestrates build/test tasks; Bun is the package manager/runtime.
• Next.js API routes act as serverless “controllers,” invoking core services and repositories.
Key Components
A. Frontend (Browser / Next.js)
• Next.js pages & Server Components (App Router)
• UI components & providers (Tailwind, shadcn/ui, TipTap editor)
• TensorFlow.js & NSFWJS models in public/models for client-side NSFW detection
• Calls backend via built-in API routes (HTTP fetch)
B. API Layer (Next.js Serverless Functions)
• Endpoints under src/app/api/:
• /api/auth/[...all] → Better Auth integration (sign-in/up, session)
• /api/cron/sync-likes → Scheduled/cron jobs for like count sync
• /api/[transport] → MCP HTTP/SSE/WS endpoints
• Each route invokes core services & uses Zod for request validation
C. Business Logic & Services (Core Layer)
• AuthService: user auth flows (email/password, OAuth, JWT sessions)
• BlogService, CommentService, ImageService, MailService, CacheService, MCPService, UserService
• Each service calls its repository & handles domain rules (rate-limit, profanity)
D. Data Layer
• Repositories (e.g., blog.repository.ts) using Drizzle ORM
• PostgreSQL (Neon or local) as primary DB
• Redis (optional/Upstash) for caching & session data
E. External Services
• Cloudinary for image upload/optimization & NSFW API
• Obscenity library for profanity filtering
• Model Context Protocol (MCP) via @modelcontextprotocol/sdk & @vercel/mcp-adapter
• Email via Nodemailer
• OAuth providers (Google, GitHub)
• Docker Compose wraps PostgreSQL & Redis for local dev
F. Infrastructure & Dev Tools
• Turborepo (monorepo orchestration)
• Bun: package manager, runtime, build (bun dev, bun build)
• Vercel for deployment, Docker Compose for local containers
• CI/Hooks: Husky, ESLint, TypeScript checks
Relationships & Data Flows
• Browser → Next.js page (SSR/SSG) → React Server/Client Components
• Browser (fetch) → Next.js API Routes → Core Services → Repositories → PostgreSQL
• Core Services ↔ Redis (cache reads/writes via CacheService)
• Core Services → External APIs (Cloudinary, Obscenity, MCP)
• Cron Endpoint → SyncLikes Service → DB
• Admin UI → Admin API endpoints → Core User/Blog services
• AI UI/Background → MCP endpoints (HTTP, SSE, WS)
Architectural Patterns & Principles
• Layered: Controllers (API routes) → Services → Repositories → DB
• Separation of concerns: UI vs. business logic vs. data access
• Serverless functions for APIs, functions as first-class citizens
• Monorepo with isolated workspaces (Turborepo)
• Infrastructure as code (Docker Compose, bunfig.toml, turbo.json)
• Cache-Aside pattern with Redis
• Model-View-Service pattern in core modules
Final Checklist
• [ ] Clear component labels
• [ ] Group modules by folder or layer
• [ ] Call out tech stack at each layer (Next.js 16, React 19, Drizzle, Bun, Turborepo)
• [ ] Note environment: local (Docker) vs. production (Vercel)