A modern full-stack digital book marketplace application that allows users to browse, purchase, and download PDF books. Features include UPI payment integration, email notifications, dark/light mode, and a comprehensive admin dashboard.
- Project Overview
- Technology Stack
- Project Structure
- Features
- Prerequisites
- Setup Instructions
- Running the Application
- API Endpoints
- Database Schema
- Configuration
- Authentication
- Payment Integration
- UI/UX Features
NoPaper is a digital book marketplace built with modern technologies. The application provides:
- Public Book Browsing: Anyone can view available books without login
- User Portal: Browse books, make purchases via UPI, and download purchased PDFs
- Admin Portal: Upload new books, manage inventory, view statistics and orders
- Authentication: Simple email/password authentication with role-based access
- Payment System: UPI payment integration with email notifications
- Modern UI: Dark/light mode toggle, responsive design, luxury theme
- Python 3.14+
- FastAPI - Modern, fast web framework for building APIs
- SQLAlchemy (< 2.0) - ORM for database operations
- PyMySQL - MySQL database connector
- Pydantic - Data validation
- Uvicorn - ASGI server
- Python-multipart - File upload handling
- smtplib - Email notifications
- React 19.2.1 - UI library
- React Router DOM 7.10.0 - Client-side routing
- Axios 1.13.2 - HTTP client for API calls
- React Context API - State management (Auth, Theme)
- React Scripts 5.0.1 - Build tooling
- MySQL - Relational database management system
NoPaper/
βββ backend/ # Python FastAPI backend
β βββ __init__.py # Python package marker
β βββ db.py # Database configuration and session management
β βββ main.py # FastAPI application and API endpoints
β βββ models.py # SQLAlchemy database models
β βββ requirements.txt # Python dependencies
β βββ uploads/ # Uploaded PDF files storage
β βββ pdfs/ # PDF book files directory
β
βββ frontend/ # React frontend application
β βββ public/ # Static public files
β β βββ index.html # HTML template
β β βββ ...
β βββ src/ # React source code
β β βββ App.js # Main app component with routing
β β βββ App.css # App styles
β β βββ index.js # React entry point
β β βββ index.css # Global styles
β β βββ config.js # API configuration
β β βββ AuthContext.js # Authentication context provider
β β βββ ThemeContext.js # Theme context provider
β β βββ pages/ # Page components
β β β βββ LoginPage.js # Login/Registration page
β β β βββ LoginPage.css
β β β βββ UserDashboard.js # User portal
β β β βββ UserDashboard.css
β β β βββ AdminDashboard.js # Admin portal
β β β βββ AdminDashboard.css
β β β βββ AboutUs.js # About Us page
β β β βββ AboutUs.css
β β βββ components/ # Reusable components
β β βββ Footer.js # Footer component
β β βββ Footer.css
β β βββ PaymentModal.js # Payment modal component
β β βββ PaymentModal.css
β βββ package.json # Node.js dependencies and scripts
β βββ package-lock.json # Dependency lock file
β
βββ venv/ # Python virtual environment
βββ start-backend.ps1 # PowerShell script to start backend
βββ start-frontend.ps1 # PowerShell script to start frontend
βββ start-all.ps1 # PowerShell script to start both servers
βββ start-backend.bat # Batch script to start backend
βββ start-frontend.bat # Batch script to start frontend
βββ start-all.bat # Batch script to start both servers
βββ README.md # This file
- Public Book Browsing: View all available books without login
- User Registration & Authentication: Simple email/password authentication
- Book Purchase: Purchase books via UPI payment integration
- Payment Flow:
- UPI deep link generation
- Payment verification
- Automatic email notifications on successful payment
- Download Purchased Books: Download PDF files for purchased books
- Dark/Light Mode: Toggle between themes
- About Us Page: Learn about the company and contact information
- Admin Authentication: Role-based access control
- Book Management:
- Upload new books with PDF files
- Set book details (title, author, price, description)
- View all books with purchase statistics
- Order Management:
- View all purchases
- Track order status (pending, paid, failed)
- View order details (user, books, amount, date)
- Dashboard Statistics:
- Total books count
- Total users count
- Total orders count
- Total revenue
- Recent purchases table
- Dark/Light Mode: Toggle between themes
- Responsive Design: Works on desktop, tablet, and mobile devices
- Dark/Light Mode: Universal theme toggle on all pages
- Modern Luxury Theme: Clean, elegant design
- Loading States: Visual feedback during data fetching
- Error Handling: User-friendly error messages
- Payment Modal: Intuitive payment flow with UPI integration
- Footer: Copyright notice on all pages
- Simple Authentication: Email/password based authentication
- Role-Based Access Control: User and admin roles
- Protected API Endpoints: Authentication required for purchases and downloads
- Secure File Downloads: Only purchased books can be downloaded
Before you begin, ensure you have the following installed:
- Python 3.14+ - Download Python
- Node.js 14+ and npm - Download Node.js
- MySQL Server - Download MySQL
- Git (optional) - For version control
- Install and start MySQL server
- Create a new database:
CREATE DATABASE online_bookshop;
- Note your MySQL credentials:
- Username (default:
root) - Password
- Host (default:
localhost) - Port (default:
3306)
- Username (default:
-
Navigate to the backend directory:
cd backend -
Create a virtual environment (if not already created):
# Windows python -m venv ../venv # macOS/Linux python3 -m venv ../venv
-
Activate the virtual environment:
# Windows PowerShell ..\venv\Scripts\Activate.ps1 # Windows Command Prompt ..\venv\Scripts\activate.bat # macOS/Linux source ../venv/bin/activate
-
Install Python dependencies:
pip install -r requirements.txt
-
Configure database connection in
backend/db.py:MYSQL_USER = os.getenv("MYSQL_USER", "root") MYSQL_PASSWORD = os.getenv("MYSQL_PASSWORD", "your_password") MYSQL_HOST = os.getenv("MYSQL_HOST", "localhost") MYSQL_PORT = os.getenv("MYSQL_PORT", "3306") MYSQL_DB = os.getenv("MYSQL_DB", "online_bookshop")
-
Configure email settings in
backend/main.py(for payment notifications):SMTP_SERVER = os.getenv("SMTP_SERVER", "smtp.gmail.com") SMTP_PORT = int(os.getenv("SMTP_PORT", "587")) EMAIL_USER = os.getenv("EMAIL_USER", "your_email@gmail.com") EMAIL_PASSWORD = os.getenv("EMAIL_PASSWORD", "your_app_password") ADMIN_EMAIL = "your_email@gmail.com" UPI_ID = "your_upi_id@okaxis"
-
Navigate to the frontend directory:
cd frontend -
Install Node.js dependencies:
npm install
-
Configure API URL in
frontend/src/config.js(optional):export const API_URL = process.env.REACT_APP_API_URL || "http://localhost:8000";
Windows PowerShell:
# Start both servers
.\start-all.ps1
# Or start individually
.\start-backend.ps1
.\start-frontend.ps1Windows Command Prompt:
# Start both servers
start-all.bat
# Or start individually
start-backend.bat
start-frontend.batStart the Backend Server:
-
Open a terminal and navigate to the backend directory:
cd backend -
Activate the virtual environment:
# Windows PowerShell ..\venv\Scripts\Activate.ps1 # Windows Command Prompt ..\venv\Scripts\activate.bat # macOS/Linux source ../venv/bin/activate
-
Start the FastAPI server:
uvicorn main:app --reload --host 0.0.0.0 --port 8000
The backend API will be available at:
http://localhost:8000- API documentation:
http://localhost:8000/docs(Swagger UI) - Alternative docs:
http://localhost:8000/redoc
- API documentation:
Start the Frontend Development Server:
-
Open a new terminal and navigate to the frontend directory:
cd frontend -
Start the React development server:
npm start
The frontend application will automatically open in your browser at:
http://localhost:3000
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
-
POST /register- Register a new user- Body:
{ "email": "user@example.com", "password": "password123" } - Returns: User role
- Body:
-
POST /login- Login user- Body:
{ "email": "user@example.com", "password": "password123" } - Returns: User role
- Body:
-
GET /books- List all available books (public, no auth required)- Returns: Array of book objects
-
GET /books/{book_id}/download- Download purchased book PDF- Headers:
email: user@example.com,password: password123 - Returns: PDF file
- Headers:
-
POST /buy- Purchase a book- Headers:
email: user@example.com,password: password123 - Body:
{ "book_id": 1 } - Returns: Order details with UPI payment URL
- Headers:
-
POST /payment/verify- Verify payment completion- Headers:
email: user@example.com,password: password123 - Query:
order_id=1&status=success - Returns: Updated order status
- Triggers: Email notification to admin
- Headers:
-
GET /admin/books- Get all books with statistics (admin only)- Headers:
email: admin@example.com,password: admin_password
- Headers:
-
POST /admin/books- Upload a new book (admin only)- Headers:
email: admin@example.com,password: admin_password - Body: Form data with
title,author,price,description,pdf(file)
- Headers:
-
GET /admin/orders- Get all orders (admin only)- Headers:
email: admin@example.com,password: admin_password
- Headers:
-
GET /admin/stats- Get dashboard statistics (admin only)- Headers:
email: admin@example.com,password: admin_password - Returns: Total books, users, orders, revenue
- Headers:
id(Integer, Primary Key)email(String, Unique, Indexed)password_hash(String) - Plain text password (as per requirements)role(String) - 'user' or 'admin'created_at(DateTime)
id(Integer, Primary Key)title(String)author(String)price(Numeric)description(Text, Optional)pdf_path(String) - Path to PDF filecreated_at(DateTime)
id(Integer, Primary Key)user_id(Integer, Foreign Key β users.id)total(Numeric)status(String) - 'pending', 'paid', or 'failed'created_at(DateTime)
id(Integer, Primary Key)order_id(Integer, Foreign Key β orders.id)book_id(Integer, Foreign Key β books.id)quantity(Integer)price_each(Numeric)
Database Configuration (backend/db.py):
- Default MySQL user:
root - Default MySQL password:
lijo - Default MySQL host:
localhost - Default MySQL port:
3306 - Default database:
online_bookshop
Email Configuration (backend/main.py):
- SMTP Server:
smtp.gmail.com - SMTP Port:
587 - Email User: Your Gmail address
- Email Password: Gmail App Password (not regular password)
- Admin Email: Email to receive payment notifications
- UPI ID: Your UPI ID for payments
CORS Configuration:
- Allowed origin:
http://localhost:3000 - Update for production deployment
File Upload Configuration:
- Upload directory:
backend/uploads/pdfs/ - Allowed file type: PDF only
API Configuration (frontend/src/config.js):
- API URL:
http://localhost:8000 - Default port:
3000
Environment Variables (optional):
REACT_APP_API_URL: Backend API URL (defaults tohttp://localhost:8000)
The application uses simple email/password authentication:
- Registration: Users can register with email and password (minimum 7 characters)
- Login: Users login with email and password
- Authentication: Email and password are sent in request headers for protected endpoints
- Roles:
user: Can browse, purchase, and download booksadmin: Can upload books, view statistics, and manage orders
Creating an Admin User:
Run this SQL query in your MySQL database:
INSERT INTO users (email, password_hash, role, created_at)
VALUES ('admin@example.com', 'your_password', 'admin', NOW());- User clicks "Buy Now" on a book
- System creates a pending order
- UPI deep link is generated with payment details
- User is redirected to UPI app for payment
- After payment, user clicks "Payment Completed"
- System verifies payment and updates order status
- Email notification is sent to admin with payment details
- User can now download the purchased book
When a payment is successfully verified, an email is automatically sent to the admin email with:
- Order ID
- User email
- Book title
- Amount paid
- Payment time
- Payment status
- Universal theme toggle button on all pages
- Theme preference is saved in localStorage
- Smooth transitions between themes
- Theme variables for consistent styling
- Mobile-first approach
- Works on all screen sizes
- Adaptive layouts for different devices
- Loading states for async operations
- Error messages with clear instructions
- Confirmation dialogs for important actions
- Smooth navigation between pages
Database Connection Error:
- Verify MySQL server is running
- Check database credentials in
backend/db.py - Ensure database
online_bookshopexists
Module Not Found Error:
- Ensure virtual environment is activated
- Run
pip install -r requirements.txtagain
Port Already in Use:
- Change port:
uvicorn main:app --reload --host 0.0.0.0 --port 8001
Email Not Sending:
- Verify SMTP credentials
- For Gmail, use App Password (not regular password)
- Check firewall settings
Cannot Connect to API:
- Verify backend server is running on
http://localhost:8000 - Check CORS configuration in
backend/main.py - Verify API_URL in
frontend/src/config.js
npm Install Fails:
- Clear cache:
npm cache clean --force - Delete
node_modulesandpackage-lock.json, then runnpm installagain
Theme Not Working:
- Clear browser cache
- Check browser console for errors
- Verify ThemeContext is properly wrapped in App.js
- The database tables are automatically created on first run via SQLAlchemy's
Base.metadata.create_all() - Default user role is 'user' - admin accounts must be created manually in the database
- PDF files are stored with timestamp prefixes to avoid naming conflicts
- The application uses email/password in headers for authentication
- Passwords are stored as plain text (as per requirements)
- UPI payment requires manual verification by the user
- Email notifications require proper SMTP configuration
This project is provided as-is for educational and development purposes.
Happy Reading! π