Skip to content

BOOK-STORE-SCRAPPER/frontend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š Book Store Scraper - Frontend

Next.js frontend application for the Book Store Web Scraper. A modern, responsive UI for scraping and viewing book data from books.toscrape.com.


πŸš€ Quick Start (Local Development)

Prerequisites

  • Node.js 18+ (check with node --version)
  • npm or yarn (comes with Node.js)

Step 1: Clone the Repository

git clone https://github.com/BOOK-STORE-SCRAPER/frontend.git
cd book-store-scraper-frontend

Note: Replace YOUR_ORG with your GitHub organization name.

Step 2: Install Dependencies

npm install

Step 3: Setup Environment Variables

# 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:8000

Step 4: Start Development Server

npm run dev

The frontend will start at: http://localhost:3000

Step 5: Verify Installation

  1. Open http://localhost:3000 in your browser
  2. Make sure the backend is running at http://localhost:8000
  3. You should see the Book Store Scraper interface
  4. Visit http://localhost:3000/dev-status to check system status and backend connection

πŸ”— Backend Connection

This frontend requires the book-store-scraper-backend to be running.

Quick Backend Setup

  1. Clone the backend repository
  2. Follow backend README to start it
  3. Backend should run on http://localhost:8000
  4. Frontend will automatically connect to it

Backend Not Running?

If the backend is not running, you'll see connection errors in the browser console. Make sure:

  1. Backend is running on http://localhost:8000
  2. NEXT_PUBLIC_API_URL in .env.local matches your backend URL
  3. Backend CORS allows http://localhost:3000

βš™οΈ Configuration

Environment Variables

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.local is git-ignored (your local config)
  • .env.example is committed (template for others)
  • Always use .env.local for local development

πŸ“ Project Structure

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

πŸ› οΈ Available Scripts

# Development server (with hot reload)
npm run dev

# Build for production
npm run build

# Start production server
npm start

# Lint code
npm run lint

🎨 Features

  • βœ… 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

πŸ”Œ API Integration

All API calls are handled through src/lib/api.ts which:

  • Uses NEXT_PUBLIC_API_URL from 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/' });

πŸ–ΌοΈ Image Configuration

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!


πŸ› Troubleshooting

Backend Connection Issues

Problem: Frontend can't connect to backend

Solutions:

  1. Verify backend is running: http://localhost:8000/health
  2. Check .env.local has correct NEXT_PUBLIC_API_URL
  3. Verify backend CORS allows http://localhost:3000
  4. Check browser console for specific errors

Build Errors

Problem: npm run build fails

Solutions:

  1. Ensure all dependencies are installed: npm install
  2. Check for TypeScript errors: npm run lint
  3. Verify environment variables are set correctly

Port Already in Use

Error: Port 3000 is already in use

Solution:

# Use a different port
npm run dev -- -p 3001

Module Not Found

Error: Cannot find module

Solution:

# Delete node_modules and reinstall
rm -rf node_modules package-lock.json
npm install

πŸš€ Production Build

Build for Production

npm run build
npm start

Environment Variables for Production

When deploying, set NEXT_PUBLIC_API_URL to your production backend URL:

NEXT_PUBLIC_API_URL=https://your-backend-url.com

πŸ› οΈ Tech Stack

  • 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)

πŸ“Š Development Status Page

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:


πŸ“š Additional Resources


🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

MIT License


πŸ“ž Support

For issues or questions:


Happy Scraping! πŸš€

About

Next.js frontend for book store web scraper

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages