A sophisticated AI-powered tool that generates professional news articles through a multi-stage process including research, drafting, editing, and finalization.
-
Multi-stage Article Generation:
- Research: AI-powered web browsing for real-time information gathering
- Drafting: Initial article creation based on research
- Editing: Content refinement and structure improvement
- Finalizing: SEO optimization and final polish
-
Advanced Web Browsing & Research:
- Real-time web search across multiple search engines
- Content extraction from web pages with full text analysis
- Fact verification using multiple sources
- Expert source identification and credibility scoring
- AI-powered insight extraction and analysis
- Comprehensive research synthesis
- Configurable time range filtering (day/week/month/year/all)
- Adjustable source limits (1-15 sources)
- Source verification and reliability assessment
-
Multiple AI Models: Support for various AI models including:
- OpenAI GPT-4o Mini & GPT-4.1 Mini
- Anthropic Claude Sonnet 4 & Claude 3.7 Sonnet
- Google Gemini 2.5 Flash & Gemini 2.5 Pro
- X.AI Grok 4 Fast
-
Customizable Output:
- News styles (investigative, feature, breaking news, opinion, interview, profile)
- Tones (formal, casual, humorous, authoritative, conversational, academic)
- Lengths (short, medium, long)
-
SEO Optimization:
- Keyword integration
- Meta information generation
- Source citation
-
Real-time Progress: Live updates during article generation
-
Source Management: Automatic source gathering and citation
-
MongoDB Integration: Article storage and retrieval
-
Clone the repository:
git clone <repository-url> cd ai-news-article-generator
-
Install dependencies:
bun install
-
Set up environment variables:
cp .env.example .env
Edit
.envand add your configuration:OPENROUTER_API_KEY=your_openrouter_api_key_here MONGODB_URI=mongodb://localhost:27017/article-generator PORT=3000 NODE_ENV=development
-
Start MongoDB (if running locally):
mongod
bun run devThis starts the server with hot reloading on http://localhost:3000.
bun run build
bun run startOpen http://localhost:3000 in your browser to access the web interface where
you can:
- Enter your article topic and summary
- Select style, tone, and length preferences
- Choose your preferred AI model
- Add SEO keywords (optional)
- Generate the article with real-time progress updates
Generates a complete article with real-time progress updates via Server-Sent Events (SSE).
POST /api/articles/generate
Content-Type: application/json
{
"topic": "Climate Change Impact on Agriculture",
"summary": "Exploring how climate change affects farming practices worldwide",
"style": "feature", // Optional: investigative, feature, breaking-news, opinion, interview, profile
"tone": "formal", // Optional: formal, casual, humorous, authoritative, conversational, academic
"length": "medium", // Optional: short, medium, long
"model": "openai/gpt-4-turbo-preview", // Optional: any available model
"keywords": ["climate change", "agriculture", "farming"] // Optional: array of SEO keywords
}Response: Server-Sent Events stream with progress updates and final article data.
Performs comprehensive web-based research without generating an article.
POST /api/articles/research
Content-Type: application/json
{
"topic": "Renewable Energy Trends 2024",
"summary": "Current developments in renewable energy sector", // Optional
"model": "openai/gpt-4-turbo-preview", // Optional
"maxSources": 8, // Optional: 1-15, default 8
"includeFullContent": true, // Optional: default true
"timeRange": "month" // Optional: day, week, month, year, all
}Response: JSON object with research results, sources, and AI-generated insights.
Lists all available AI models and the default model.
GET /api/articles/modelsResponse:
{
"models": ["openai/gpt-4-turbo-preview", "anthropic/claude-3-opus", "..."],
"default": "openai/gpt-4-turbo-preview"
}Retrieves a specific article by its MongoDB ObjectId.
GET /api/articles/:idParameters:
id: MongoDB ObjectId (24-character hexadecimal string)
Retrieves a paginated list of articles.
GET /api/articles?limit=10&offset=0Query Parameters:
limit: Number of articles to return (default: 10, max: 50)offset: Number of articles to skip (default: 0)
Response:
{
"articles": [...],
"pagination": {
"limit": 10,
"offset": 0,
"hasMore": true
}
}Returns service health status and metrics.
GET /api/articles/healthResponse:
{
"status": "healthy",
"timestamp": "2024-01-01T00:00:00.000Z",
"service": "Article Generator API",
"availableModels": 8
}src/
├── config/
│ └── database.ts # MongoDB connection
├── middleware/
│ └── errorHandler.ts # Error handling middleware
├── models/
│ └── Article.ts # Article data model
├── routes/
│ └── articles.ts # API routes
├── services/
│ ├── ArticleGeneratorService.ts # Main article generation logic
│ ├── EnhancedResearchService.ts # Advanced web research with AI insights
│ ├── OpenRouterService.ts # AI model integration
│ └── WebBrowsingService.ts # Web content extraction and browsing
├── types/
│ ├── article.ts # Article-related type definitions
│ └── api.ts # API-related type definitions
├── utils/
│ └── helpers.ts # Utility functions
└── index.ts # Application entry point
| Variable | Description | Default |
|---|---|---|
OPENROUTER_API_KEY |
Your OpenRouter API key | Required |
MONGODB_URI |
MongoDB connection string | mongodb://localhost:27017/article-generator |
PORT |
Server port | 3000 |
NODE_ENV |
Environment mode | development |
DEBUG |
Enable debug logging (1 or 0) | 0 |
OPENROUTER_BASE_URL |
OpenRouter API base URL | https://openrouter.ai/api/v1 |
DEFAULT_MODEL |
Default AI model | openai/gpt-4o-mini |
AVAILABLE_MODELS |
Comma-separated list of models | See current model list below |
RATE_LIMIT_WINDOW_MS |
Rate limit window (milliseconds) | 900000 (15 minutes) |
RATE_LIMIT_MAX_REQUESTS |
Max requests per window | 100 |
The following models are currently supported (as of default configuration):
openai/gpt-4o-mini(default)google/gemini-2.5-flashanthropic/claude-sonnet-4anthropic/claude-3.7-sonnetgoogle/gemini-2.5-prox-ai/grok-4-fastopenai/gpt-4.1-mini
You can customize available models by setting the AVAILABLE_MODELS environment
variable with a comma-separated list.
- Feature: In-depth, magazine-style articles
- Breaking News: Fast, factual reporting
- Investigative: Deep-dive analysis with multiple sources
- Opinion: Editorial and commentary pieces
- Interview: Q&A format articles
- Profile: Biographical or company profiles
- Formal: Professional, business-like tone
- Conversational: Friendly, accessible language
- Authoritative: Expert, confident voice
- Casual: Relaxed, informal style
- Academic: Scholarly, research-oriented
- Humorous: Light-hearted, entertaining
- Short: 300-600 words
- Medium: 600-1200 words
- Long: 1200-2500 words
- Long-form: 2500+ words
The application integrates with OpenRouter API to access multiple AI models. You'll need to:
- Sign up at OpenRouter
- Get your API key
- Add credits to your account
- Configure the API key in your
.envfile
bun run type-check- TypeScript: Strict typing enabled
- ESM: Modern ES modules
- Path Mapping: Convenient imports with
@/prefix - Error Handling: Comprehensive error management
- Validation: Request validation with Zod
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
FROM oven/bun:latest
WORKDIR /app
COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile
COPY . .
RUN bun run build
EXPOSE 3000
CMD ["bun", "start"]- Set up MongoDB on your server
- Configure environment variables
- Build the application:
bun run build - Start the application:
bun start
The application includes:
- Request logging
- Error tracking
- Performance monitoring
- Health check endpoints
- Rate limiting
- CORS configuration
- Security headers (Helmet)
- MongoDB Connection Failed: Check your MongoDB URI and ensure MongoDB is running
- OpenRouter API Errors: Verify your API key and account credits
- Rate Limiting: Reduce request frequency or increase limits
- Memory Issues: For long articles, consider increasing Node.js memory limit
Check console output for detailed error messages and debugging information.
MIT License - see LICENSE file for details.
For issues and questions:
- Check the troubleshooting section
- Review the API documentation
- Create an issue on GitHub
- Contact support team
Built with ❤️ using Bun, TypeScript, Express, and MongoDB.