# ghost.blog (V2) ## Project Overview This is a SaaS application built with Next.js that allows users to generate blog content using Google's Gemini AI. It features a complete authentication system, team-based workspaces, Stripe integration for subscriptions and one-time purchases (coins), and a dashboard for managing content and integrations. The application is designed to be a "ghost blog" platform, where users can connect their WordPress sites and have AI-generated content automatically posted to their blogs. It also supports manual content generation and a rich text editor for editing the generated content. ## Key Features * **AI Content Generation**: Leverages the Gemini API to generate blog posts from prompts, keywords, and reference sites. The application has a 10-stage AI generation pipeline (Topic Selection -> Research -> Title Generation -> Outline -> Writing -> Quality Check -> Image Generation -> SEO Optimization -> Publishing -> Complete). * **Scheduled Generation**: Users can schedule future dates and times for content generation jobs, allowing the system to automatically trigger AI pipeline execution exactly when needed via `app/api/generation-jobs/schedule`. * **WordPress Integration**: Seamlessly connects to WordPress sites to publish content via the WordPress CMS. * **Scheduled Publishing**: After content is generated, users can configure automatic scheduling or directly publish the content. Using an `autoPublishDelayDays` config, the system can automatically publish drafted WordPress posts on future dates via cron jobs (`app/api/cron/publish-scheduled`). * **Subscription and Coin-based Billing**: Uses Stripe to manage subscriptions and a coin-based system for one-time purchases of content generation credits. * **Team Management**: Supports multi-user teams with different roles (owner, member). * **Content Management**: A dashboard for viewing, editing, and deleting generated content. * **RSS Content Aggregation**: A daily cron job collects content from RSS feeds to be used as inspiration for AI generation. * **Activity Logging**: Tracks user actions for auditing and analytics. ## Technologies Used * **Framework**: Next.js (App Router) * **Database**: PostgreSQL * **ORM**: Drizzle ORM * **Authentication**: Custom JWTs stored in HTTP-only cookies * **Payments**: Stripe * **AI Model**: Google Gemini 3 Pro (for text generation), Gemini 3 Pro Image (for image generation) * **UI Library**: Tailwind CSS, shadcn/ui, Lucide React * **Deployment**: Vercel * **Caching/Real-time APIs**: Redis (Pub/Sub for AI generation stages), WebSockets. ## Development Conventions ### Code Style The project uses TypeScript across the stack. Prettier is used for code formatting. ### Database Drizzle ORM is used for all database access. The schema is centrally defined in `lib/db/schema.ts`. Migrations are generated (`pnpm db:generate`) and applied (`pnpm db:migrate`) using `drizzle-kit`. You can view the DB with `pnpm db:studio`. ### Authentication and Authorization Authentication is handled using JWTs stored in HTTP-only cookies. Server-side actions are protected using the `validatedAction` and `validatedActionWithUser` middleware, which can be found in `lib/auth/middleware.ts`. ### AI Integration The `lib/ai/gemini.ts` file contains a comprehensive client for interacting with the Google Gemini API. The `lib/ai/pipeline/` folder contains a multi-staged AI pipeline logic with real-time websocket pushes to the frontend. ### Cron Jobs Vercel Cron is used for scheduling background jobs. The cron endpoints are located in the `app/api/cron/` directory and secured using a `CRON_SECRET` environment variable.