Skip to content

Gotnochill/java_fsd_2328113

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bookstore Application - Full Stack Java Project

Quick Start

Run the startup script:

./start.sh

This will start the backend (port 8080), frontend (port 3000/3001), and open the application in your browser.

Test Credentials

  • Email: demo@bookstore.com
  • Password: Demo@123

Project Overview

A complete full-stack web application for online bookstore management built with Spring Boot (backend), React (frontend), and H2 embedded database. Users can register, login, browse books, search, and manage shopping cart.

Tech Stack

Backend

  • Spring Boot 3.0 - REST API development
  • Spring Data JPA - ORM for database operations
  • H2 Database - Embedded relational database (file-based)
  • Spring Security + JWT - Authentication and authorization
  • Maven - Build and dependency management
  • Lombok - Reduce boilerplate code

Frontend

  • React 18 - UI framework
  • React Router 6 - Client-side routing
  • Axios - HTTP client
  • Vite - Build tool
  • CSS - Styling (vanilla CSS)

Database

  • H2 Database - Embedded file-based relational database at /tmp/bookstore_db
  • Hibernate ORM - Object-Relational Mapping

Project Structure

bookstore-backend/
├── src/
│   ├── main/
│   │   ├── java/com/bookstore/
│   │   │   ├── entity/          (Database entities)
│   │   │   ├── repository/      (JPA repositories)
│   │   │   ├── service/         (Business logic)
│   │   │   ├── controller/      (REST endpoints)
│   │   │   ├── dto/             (Data transfer objects)
│   │   │   ├── security/        (JWT utilities)
│   │   │   └── BookstoreApplication.java
│   │   └── resources/
│   │       └── application.properties
│   └── test/
└── pom.xml

bookstore-frontend/
├── src/
│   ├── components/    (Reusable components)
│   ├── pages/        (Page components)
│   ├── services/     (API service layer)
│   ├── styles/       (CSS files)
│   ├── App.jsx
│   └── main.jsx
├── index.html
├── vite.config.js
└── package.json

Database Schema

Users Table

- id (PK)
- email (unique)
- password (hashed)
- name
- role

Books Table

- id (PK)
- title
- author
- category
- price
- stock
- description

Orders Table

- id (PK)
- user_id (FK)
- total_amount
- status
- created_at

Order Items Table

- id (PK)
- order_id (FK)
- book_id (FK)
- quantity
- price

Setup Instructions

Prerequisites

  • Java 17+
  • Node.js 14+
  • Maven 3.6+
  • (No database installation needed - uses H2 embedded database)

Quick Setup (Recommended)

Simply run the startup script:

./start.sh

Everything will be configured and running automatically!

Manual Setup

If you prefer manual setup, follow these steps:

Backend Setup

  1. Navigate to backend folder:
cd bookstore-backend
  1. Build the application:
mvn clean package -DskipTests
  1. Run:
java -jar target/bookstore-api-1.0.0.jar

Backend runs on: http://localhost:8080

Note: No database configuration needed - H2 is embedded and auto-configured

Frontend Setup

  1. Navigate to frontend folder:
cd bookstore-frontend
  1. Install dependencies:
npm install
  1. Run development server:
npm run dev

Frontend runs on: http://localhost:3000

API Endpoints

Authentication

  • POST /api/auth/register - Register new user
  • POST /api/auth/login - Login user

Books

  • GET /api/books - Get all books
  • GET /api/books/{id} - Get book by ID
  • GET /api/books/search/title?title=... - Search by title
  • GET /api/books/search/author?author=... - Search by author
  • GET /api/books/category/{category} - Get books by category
  • POST /api/books - Add new book (Admin)
  • PUT /api/books/{id} - Update book (Admin)
  • DELETE /api/books/{id} - Delete book (Admin)

Orders

  • GET /api/orders/user/{userId} - Get user's orders
  • GET /api/orders/{id} - Get order details
  • PUT /api/orders/{id}/status?status=... - Update order status

Features Implemented

  • User Authentication & Authorization (JWT)
  • Book Management (CRUD operations)
  • Search & Filter functionality
  • Shopping Cart (local storage)
  • Order Management
  • Responsive UI
  • Input Validation (Backend & Frontend)
  • Error Handling
  • Layered Architecture (Controller → Service → Repository)
  • Role-based Access Control

How to Use

  1. Register - Create new account with email and password
  2. Login - Use credentials to login
  3. Browse Books - View all available books
  4. Search - Search books by title or author
  5. Add to Cart - Click "View Details" and add desired quantity
  6. Manage Cart - Modify quantities or remove items

Testing

Test Credentials (Pre-configured)

Email: demo@bookstore.com
Password: Demo@123

Manual Testing

  • Test registration with new email
  • Test login with valid/invalid credentials
  • Add/remove items from cart
  • Search with different keywords
  • Verify responsive design on different screen sizes

Deployment

Backend (Production)

mvn clean package
java -jar target/bookstore-api-1.0.0.jar

Frontend (Production Build)

npm run build
npm run preview

Notes

  • JWT tokens expire after 24 hours
  • Passwords are hashed using BCrypt
  • Cart is stored in browser's localStorage
  • All APIs require authentication (except /auth endpoints)
  • CORS is enabled for localhost:3000 and localhost:3001
  • Database is H2 embedded file-based at /tmp/bookstore_db
  • Data persists between application restarts
  • 8 sample books are pre-loaded on first run

Troubleshooting

Port Already in Use

  • Frontend will automatically try port 3001 if 3000 is in use
  • Backend uses port 8080. To change, modify application.properties:
    server.port=8081

Issues Starting Services

  • Ensure both pom.xml (backend) and package.json (frontend) are in place
  • Check that Maven and Node.js are installed: mvn -v and node -v
  • Try removing the database file: rm -f /tmp/bookstore_db*

CORS Issues

Application Not Starting

  • Check logs:
    tail -f /tmp/bookstore-backend.log
    tail -f /tmp/bookstore-frontend.log
  • Ensure you're in the correct directory when running ./start.sh
  • Check file permissions: ls -la start.sh (should have x permission)

Author

Student Name: Ritvik Mukherjee Roll Number: 2328113 Batch: 2024 Date: April 2026

License

Educational Project - Learning Purpose Only

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors