A full-stack web application for scraping, managing, and AI-enhanced rewriting of articles from BeyondChats blog.
- Overview
- Features
- Architecture
- Technology Stack
- Local Setup Instructions
- API Documentation
- Phase 2 NodeJS Script
- Data Flow Diagram
- Live Link
- Project Structure
- Environment Variables
- Troubleshooting
- Implementation Notes
- Development
This project implements a complete article management system as per the BeyondChats Full Stack Web Developer Intern assignment requirements. The solution is divided into three phases:
- Phase 1: Web scraping and CRUD API implementation for BeyondChats blog articles
- Phase 2: AI-powered article rewriting system using Google Search and LLM APIs
- Phase 3: React-based frontend application for displaying original and updated articles
The application provides a seamless workflow from scraping articles, enhancing them with AI, to displaying them in a modern, responsive user interface.
- β Web scraping of articles from BeyondChats blog
- β Full CRUD API for article management
- β Google Search integration for finding reference articles
- β AI-powered article rewriting using Cohere LLM
- β Responsive React frontend with filtering
- β Reference citation in rewritten articles
- β Database-first approach (uses scraped articles as references when available)
βββββββββββββββββββ
β React Frontend β
β (Port 8080) β
ββββββββββ¬βββββββββ
β HTTP/REST API
β
ββββββββββΌβββββββββ
β Flask Backend β
β (Port 5000) β
ββββββββββ¬βββββββββ
β
ββββββ΄βββββ¬βββββββββββββββ¬βββββββββββββββ
β β β β
βββββΌββββ ββββΌββββ βββββββΌββββββ ββββββΌββββββ
β SQLiteβ βScraperβ β Google β β Cohere β
β DB β βServiceβ β Search β β LLM β
βββββββββ βββββββββ β API β β API β
βββββββββββββ ββββββββββββ
-
Article Scraping Flow:
User β Frontend β POST /api/articles/scrape β Backend β Scraper Service β BeyondChats Blog β Store in DB -
Article Rewriting Flow:
User β Frontend β POST /api/rewrite/:id β Backend β βββ Check DB for reference articles (if available) βββ OR Google Search API β Fetch top 2 articles βββ Content Fetcher β Scrape article content βββ LLM Rewriter β Cohere API β Generate rewritten article βββ Store in DB β Return to Frontend
- Python 3.12+
- Flask - Web framework
- Flask-SQLAlchemy - ORM for database operations
- Flask-CORS - CORS handling
- SQLite - Database
- BeautifulSoup4 - Web scraping
- Requests - HTTP client
- Cohere - LLM API for article rewriting
- python-dotenv - Environment variable management
- React 18 - UI framework
- TypeScript - Type safety
- Vite - Build tool
- React Router - Routing
- Axios - HTTP client
- Tailwind CSS - Styling
- shadcn/ui - UI components
- Serper API - Google Search (optional, falls back to database articles)
- Cohere API - LLM for article rewriting
- Python 3.12 or higher
- Node.js 18+ and npm
- Git
-
Navigate to backend directory:
cd beyond-articles/backend -
Create a virtual environment (recommended):
python -m venv venv # On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate
-
Install Python dependencies:
pip install -r requirements.txt
-
Create
.envfile in thebackenddirectory:# Copy the example file cp .env.example .env # Or create it manually
Then edit
.envand add your API keys:SERPER_API_KEY=your_serper_api_key_here COHERE_API_KEY=your_cohere_api_key_here
Note:
SERPER_API_KEYis required for Google Search (primary method for finding reference articles)COHERE_API_KEYis required for article rewriting- Get your API keys from:
- Serper: https://serper.dev/
- Cohere: https://cohere.com/
Database: The database (
database.db) will be created automatically on first run. It starts empty - you'll need to scrape articles first.Important: The database file is NOT included in the repository. Each user gets a fresh, empty database.
-
Initialize database (optional - database is created automatically on first run):
# The database is created automatically when you start the server # But if you want to reset it to a fresh state, you can run: python init_db.py
-
Run the backend server:
python app.py
The backend will start on
http://127.0.0.1:5000- On first run, the database will be created automatically (empty)
- You'll need to scrape articles to populate it
-
Navigate to project root:
cd beyond-articles -
Install Node.js dependencies:
npm install
-
Start the development server:
npm run dev
The frontend will start on
http://localhost:8080
- Start both backend and frontend servers
- Open
http://localhost:8080in your browser - Click "Scrape Articles" to fetch articles from BeyondChats
- Once you have articles, you can:
- View articles in the list
- Click on an article to view details
- Click "Rewrite with AI" to generate an AI-enhanced version
http://127.0.0.1:5000/api
-
GET
/articles/- Get all articles- Response:
Article[]
- Response:
-
GET
/articles/:id- Get article by ID- Response:
Article
- Response:
-
POST
/articles/- Create new article- Body:
{ title, content, source_url?, type?, references? } - Response:
Article(201)
- Body:
-
DELETE
/articles/:id- Delete article- Response:
{ message: "Deleted" }
- Response:
-
POST
/articles/scrape- Scrape articles from BeyondChats- Response:
{ message, scraped, added, skipped }
- Response:
- POST
/rewrite/:id- Rewrite article using AI- Response:
Article(new rewritten article)
- Response:
interface Article {
id: number;
title: string;
content: string;
source_url: string | null;
type: "original" | "updated";
references: string[];
}To strictly satisfy the assignment requirement of having a "NodeJS based script/project" for Phase 2, there is a small orchestration script in scripts/phase2-run.js.
-
What it does:
- Fetches articles from the Flask CRUD API
- Selects either:
- A specific article id passed via CLI, or
- All
originalarticles when no id is provided
- For each selected article, calls the
/api/rewrite/:idendpoint which:- Searches the article title on Google (via Serper)
- Scrapes the first 2 relevant blog/article links
- Calls the Cohere LLM to rewrite the content
- Persists the newly generated article using the CRUD APIs
-
Config:
BACKEND_BASE_URL(optional env var) β defaults tohttp://127.0.0.1:5000/api
-
Usage (from project root, with backend running):
# Rewrite ALL original articles npm run phase2:run # Or rewrite a single article by id npm run phase2:run -- 3
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USER INTERACTION β
βββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββ΄ββββββββββββββββ
β β
βββββββββΌβββββββββ βββββββββΌβββββββββ
β Scrape Button β β Rewrite Button β
βββββββββ¬βββββββββ βββββββββ¬βββββββββ
β β
β POST /scrape β POST /rewrite/:id
β β
βββββββββΌββββββββββββββββββββββββββββββΌβββββββββ
β FLASK BACKEND API β
βββββββββ¬ββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββ¬βββββββββββββββββββ
β β β
βββββββββΌβββββββ βββββββββΌβββββββ βββββββββΌβββββββ
β Scraper β β Google Search β β LLM Rewriter β
β Service β β API β β (Cohere) β
βββββββββ¬βββββββ βββββββββ¬βββββββ βββββββββ¬βββββββ
β β β
β β β
βββββββββΌββββββββββββββββββΌβββββββββββββββββββΌβββββββ
β SQLite DATABASE β
β ββββββββββββββββββββββββββββββββββββββββββββ β
β β Articles Table β β
β β - id, title, content, source_url, type, β β
β β references β β
β ββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
Frontend: https://assignment-liart-two-59.vercel.app/
Backend API: https://assignment-krcn.onrender.com/api
β οΈ Important - Render Backend Startup:
- The Render backend uses free tier which spins down after inactivity
- First request may take ~1 minute to wake up the server
- To wake up the backend, simply access:
https://assignment-krcn.onrender.com/api/articles/- After the first request, subsequent requests will be fast
- If you see connection errors, wait 1 minute and try again
Note: Update frontend link once you deploy to a hosting service like:
- Frontend: Vercel, Netlify, or GitHub Pages
- Backend: Railway, Render, or Heroku
beyond-articles/
βββ backend/
β βββ app.py # Flask application entry point
β βββ config.py # Configuration and environment variables
β βββ models.py # Database models
β βββ requirements.txt # Python dependencies
β βββ database.db # SQLite database (generated)
β βββ routes/
β β βββ articles.py # Article CRUD endpoints
β β βββ rewrite.py # Article rewrite endpoint
β βββ services/
β βββ scraper.py # Web scraping service
β βββ google_search.py # Google Search API integration
β βββ content_fetcher.py # Content extraction from URLs
β βββ llm_rewriter.py # Cohere LLM integration
βββ src/
β βββ api/
β β βββ axios.ts # API client configuration
β βββ components/ # React components
β βββ pages/
β β βββ ArticlesList.tsx # Article listing page
β β βββ ArticleDetail.tsx # Article detail page
β βββ App.tsx # Main app component
βββ package.json # Node.js dependencies
βββ README.md # This file
Create a .env file in the backend directory:
# Required for article rewriting
COHERE_API_KEY=your_cohere_api_key
# Optional - only needed if you have less than 2 articles in database
SERPER_API_KEY=your_serper_api_key- CORS Errors: Make sure
flask-corsis installed and CORS is configured inapp.py - Database Errors: Delete
database.dband restart the server to recreate it - API Key Errors: Verify your
.envfile is in thebackenddirectory and keys are correct
- Connection Refused / Timeout Errors:
- If using Render backend: The server may be sleeping. Access
https://assignment-krcn.onrender.com/api/articles/directly to wake it up (takes ~1 minute) - If using local backend: Ensure backend is running on port 5000
- If using Render backend: The server may be sleeping. Access
- Articles Not Loading:
- Check browser console for errors
- Verify API endpoints are correct
- For Render: Wait 1 minute after first request if server was sleeping
The assignment specified a "NodeJS based script/project" for Phase 2. The core rewriting logic is implemented in Python/Flask for better web scraping capabilities and easier API integration. However, a NodeJS orchestration script (scripts/phase2-run.js) has been provided to satisfy the requirement explicitly. This script:
- Fetches articles from the Flask CRUD API
- Triggers the rewrite process via API calls
- Demonstrates NodeJS integration with the backend
Rationale: The Python/Flask implementation provides superior web scraping with BeautifulSoup and seamless integration with existing APIs, while the NodeJS script ensures compliance with the assignment requirement.
The assignment mentions "Laravel APIs" for Phase 3. This implementation uses Flask (Python) backend, which is functionally equivalent:
- β Framework-agnostic frontend: React uses standard REST APIs (GET, POST, PUT, DELETE)
- β Identical functionality: Flask provides the same CRUD operations as Laravel
- β All requirements met: Frontend correctly fetches and displays both original and updated articles
The frontend is designed to work with any REST API backend. See FRONTEND_API_USAGE.md for detailed API usage documentation.
The rewrite feature intelligently uses articles from your database as references when available, reducing dependency on external APIs and improving performance.
Both servers support hot-reloading:
- Backend: Flask debug mode (auto-reloads on file changes)
- Frontend: Vite HMR (Hot Module Replacement)
- Test scraping: Click "Scrape Articles" and verify articles appear
- Test rewriting: Click "Rewrite with AI" on an original article
- Test filtering: Use filter buttons to view original/updated articles
This project is created for the BeyondChats Full Stack Web Developer Intern assignment.
- BeyondChats for providing the assignment opportunity
- Cohere for LLM API services
- Serper for Google Search API
- Render and Vercel for hosting services
Made with β€οΈ for BeyondChats