✦ AI Blog Generator
Transform any topic into a beautifully structured blog article in seconds — powered by OpenAI GPT, React, and Express.
📸 Preview
A clean, editorial-style UI with:
- Topic input + tone selector (Professional / Casual / Technical)
- Skeleton loading animation while the AI writes
- Rendered markdown output with word count
- One-click copy button
🗂 Project Structure
ai-blog-generator/
├── backend/
│ ├── routes/
│ │ └── blog.js # POST /api/generate-blog route
│ ├── services/
│ │ └── openai.js # OpenAI API call + prompt
│ ├── server.js # Express app entry point
│ ├── .env.example # Environment variable template
│ └── package.json
│
├── frontend/
│ ├── src/
│ │ ├── components/
│ │ │ ├── BlogForm.jsx # Topic input + tone selector
│ │ │ └── BlogResult.jsx # Rendered blog + copy button
│ │ ├── App.jsx # Root component + API call
│ │ ├── main.jsx # React entry point
│ │ └── index.css # Tailwind + custom styles
│ ├── index.html
│ ├── vite.config.js
│ ├── tailwind.config.js
│ ├── .env.example
│ └── package.json
│
└── README.md
⚙️ Prerequisites
- Node.js v18 or higher
- npm v9 or higher
- An OpenAI API key → platform.openai.com
🚀 Local Setup
1. Clone the repository
git clone https://github.com/YOUR_USERNAME/ai-blog-generator.git
cd ai-blog-generator2. Backend Setup
cd backend
npm installCreate your .env file:
cp .env.example .envEdit .env:
OPENAI_API_KEY=sk-your-openai-api-key-here
PORT=5000Start the backend:
# Development (with auto-reload)
npm run dev
# Production
npm startBackend runs at: http://localhost:5000
3. Frontend Setup
Open a new terminal:
cd frontend
npm installCreate your .env file:
cp .env.example .envEdit .env:
VITE_API_URL=http://localhost:5000/apiStart the frontend:
npm run devFrontend runs at: http://localhost:3000
🔌 API Reference
POST /api/generate-blog
Generates a blog article using the OpenAI GPT API.
Request Body:
{
"topic": "Artificial Intelligence in Healthcare",
"tone": "Professional"
}| Field | Type | Required | Values |
|---|---|---|---|
topic |
string | ✅ | Any blog topic |
tone |
string | ✅ | Professional, Casual, Technical |
Response:
{
"blog": "## Introduction\n\nArtificial intelligence is transforming..."
}Error Response:
{
"error": "Topic and tone are required."
}☁️ Deployment
Backend → Render
- Push the project to GitHub
- Go to render.com → New Web Service
- Connect your GitHub repository
- Configure:
- Root Directory:
backend - Build Command:
npm install - Start Command:
npm start - Environment Variables:
OPENAI_API_KEY= your keyPORT=5000
- Root Directory:
- Click Deploy
- Copy your Render URL (e.g.,
https://ai-blog-backend.onrender.com)
Frontend → Vercel
- Go to vercel.com → New Project
- Import your GitHub repository
- Configure:
- Root Directory:
frontend - Framework Preset: Vite
- Build Command:
npm run build - Output Directory:
dist - Environment Variables:
VITE_API_URL= your Render backend URL +/api
(e.g.,https://ai-blog-backend.onrender.com/api)
- Root Directory:
- Click Deploy
🛠 Tech Stack
| Layer | Technology |
|---|---|
| Frontend | React 18, Vite, Tailwind CSS |
| HTTP | Axios |
| Markdown | react-markdown |
| Backend | Node.js, Express.js |
| AI | OpenAI GPT-3.5 Turbo |
| Config | dotenv |
📦 npm Scripts
Backend
| Command | Description |
|---|---|
npm start |
Start production server |
npm run dev |
Start dev server with nodemon |
Frontend
| Command | Description |
|---|---|
npm run dev |
Start Vite dev server |
npm run build |
Build for production |
npm run preview |
Preview production build |
🔒 Environment Variables
Backend (backend/.env)
OPENAI_API_KEY=sk-... # Your OpenAI secret key
PORT=5000 # Server port (optional, default 5000)Frontend (frontend/.env)
VITE_API_URL=http://localhost:5000/api # Backend API URL
⚠️ Never commit.envfiles to version control. They are listed in.gitignore.
📄 License
MIT — feel free to use, modify, and build on this project.