Next.js frontend application for the Book Store Web Scraper. A modern, responsive UI for scraping and viewing book data from books.toscrape.com.
- Node.js 18+ (check with
node --version) - npm or yarn (comes with Node.js)
git clone https://github.com/BOOK-STORE-SCRAPER/frontend.git
cd book-store-scraper-frontendNote: Replace
YOUR_ORGwith your GitHub organization name.
npm install# Copy the example environment file
cp .env.example .env.local
# Edit .env.local if your backend is running on a different URL
# Default: http://localhost:8000 (works if backend is running locally)Default .env.local configuration:
NEXT_PUBLIC_API_URL=http://localhost:8000npm run devThe frontend will start at: http://localhost:3000
- Open http://localhost:3000 in your browser
- Make sure the backend is running at http://localhost:8000
- You should see the Book Store Scraper interface
- Visit http://localhost:3000/dev-status to check system status and backend connection
This frontend requires the book-store-scraper-backend to be running.
- Clone the backend repository
- Follow backend README to start it
- Backend should run on
http://localhost:8000 - Frontend will automatically connect to it
If the backend is not running, you'll see connection errors in the browser console. Make sure:
- Backend is running on
http://localhost:8000 NEXT_PUBLIC_API_URLin.env.localmatches your backend URL- Backend CORS allows
http://localhost:3000
Create a .env.local file in the root directory (copy from .env.example):
# Backend API URL
NEXT_PUBLIC_API_URL=http://localhost:8000| Variable | Description | Default |
|---|---|---|
NEXT_PUBLIC_API_URL |
Backend API base URL | http://localhost:8000 |
Important:
.env.localis git-ignored (your local config).env.exampleis committed (template for others)- Always use
.env.localfor local development
frontend/
βββ src/
β βββ app/ # Next.js app router pages
β β βββ page.tsx # Home page
β β βββ admin/ # Admin dashboard
β β β βββ page.tsx
β β βββ dev-status/ # Development status page
β β β βββ page.tsx # System info, backend health, dev tools
β β βββ layout.tsx # Root layout
β β βββ globals.css # Global styles
β βββ components/ # React components
β β βββ CategorySidebar.tsx
β β βββ BookList.tsx
β β βββ BookDetails.tsx
β β βββ StatsBox.tsx
β β βββ AdminPanel.tsx
β βββ lib/
β β βββ api.ts # API utility (uses env vars)
β βββ types/
β βββ api.ts # TypeScript types
βββ public/ # Static assets
βββ .env.example # Environment variables template
βββ package.json # Dependencies
βββ next.config.ts # Next.js configuration
βββ README.md # This file
# Development server (with hot reload)
npm run dev
# Build for production
npm run build
# Start production server
npm start
# Lint code
npm run lint- β Category Scraping: Scrape all book categories from the website
- β Book Listing: View books by category in organized tables
- β Real-time Stats: Live statistics dashboard
- β Book Details: View detailed information about each book
- β Image Display: View book cover images
- β Responsive Design: Works on desktop and mobile
- β Admin Panel: Admin dashboard for managing data
- β Dev Status Page: Development status and system information page
All API calls are handled through src/lib/api.ts which:
- Uses
NEXT_PUBLIC_API_URLfrom environment variables - Provides type-safe methods (
get,post,delete) - Handles errors consistently
- Automatically constructs full URLs
Example Usage:
import { api } from '@/lib/api';
// Get categories
const categories = await api.get<Category[]>('/categories');
// Scrape categories
await api.post('/categories', { base_url: 'https://books.toscrape.com/' });Images are configured in next.config.ts to allow:
- Local development (
localhost:8000) - Backend media files (
/media/**) - External book images from
books.toscrape.com
No additional configuration needed for local development!
Problem: Frontend can't connect to backend
Solutions:
- Verify backend is running: http://localhost:8000/health
- Check
.env.localhas correctNEXT_PUBLIC_API_URL - Verify backend CORS allows
http://localhost:3000 - Check browser console for specific errors
Problem: npm run build fails
Solutions:
- Ensure all dependencies are installed:
npm install - Check for TypeScript errors:
npm run lint - Verify environment variables are set correctly
Error: Port 3000 is already in use
Solution:
# Use a different port
npm run dev -- -p 3001Error: Cannot find module
Solution:
# Delete node_modules and reinstall
rm -rf node_modules package-lock.json
npm installnpm run build
npm startWhen deploying, set NEXT_PUBLIC_API_URL to your production backend URL:
NEXT_PUBLIC_API_URL=https://your-backend-url.com- Framework: Next.js 16.0.10
- UI Library: React 19.2.1
- Language: TypeScript 5
- Styling: Tailwind CSS 4
- HTTP Client: Fetch API (via
lib/api.ts)
The application includes a dedicated development status page at /dev-status that provides:
- Backend Connection Status: Real-time monitoring of backend API connectivity
- System Information: Frontend URL, API URL, Node.js version, and environment details
- Health Checks: Backend health endpoint status and response details
- Quick Links: Easy navigation to Home, Admin Panel, and Backend API
- Environment Configuration: View current environment variables and configuration
- Development Tips: Helpful tips for development workflow
Access the Dev Status Page:
- Navigate to: http://localhost:3000/dev-status
- Or click the "Dev Status" link from the admin panel (if added)
- Next.js Docs: https://nextjs.org/docs
- React Docs: https://react.dev
- TypeScript Docs: https://www.typescriptlang.org/docs
- Tailwind CSS Docs: https://tailwindcss.com/docs
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License
For issues or questions:
- Open an issue on GitHub
- Check the backend repository for API documentation
Happy Scraping! π