A full-stack online bookstore application with separate backend and frontend projects. The backend is built with Express and Supabase, while the frontend is a React + Vite app using Redux for state management and protected routing for both users and admins.
backend/src/index.jsstarts an Express server on port5000by default.- Uses
express.json(),cors, andcookie-parser. - Connects to Supabase using
backend/src/config/db.js. - Uses cookie-based JWT authentication in
backend/src/middleware/authMiddleware.js. - Supports user registration, login, admin registration/login, logout, and auth validation.
- Supports listing books, fetching book details, filtering books by genre, cart management, and checkout.
- React application bootstrapped with Vite in
frontend/. - Uses Redux Toolkit for state management in
frontend/src/reduxSlices/. - Uses
react-router-domfor routing and route guards:frontend/src/services/ProtectedRoutes.jsxfrontend/src/services/PublicRoutes.jsx
- Reads auth state from cookies and hydrates user session via
frontend/src/services/authServices.js. - Includes pages for user login/register, book browsing, cart, checkout, admin login/register, admin dashboard, and admin book operations.
- Includes theme state support via
themeSlice.
- User registration and login
- Admin registration and login
- JWT authentication stored in cookies
- Protected routes for authenticated users and admin-only pages
- Book listing, details, and genre-based filtering
- Add to cart and checkout endpoints
- Supabase-backed data storage for users, books, genres, and cart items
- Theme toggle support and global styling
The frontend allows users to browse books by selecting a genre from a dropdown.
When a genre is selected, the app calls:
- The backend looks up the
book_genrestable for rows wheregenre_id = :genreId. - It collects all matching
book_idvalues. - It then fetches the corresponding book details from the
bookstable. - The result is a list of books filtered by the chosen category.
- The
book_genrestable includes ascorecolumn (integer). - This score represents how strongly a book belongs to a given genre:
- Higher scores = more relevant.
- Lower scores = loosely related.
- The backend includes this score in the response as
relevanceScore. - The frontend sorts books by
relevanceScoredescending and displays it as a badge (★score/10) on each book card.
{
"listBooks": [
{
"id": 1,
"title": "Romantic Tales",
"author": "Author A",
"price": 299,
"cover_url": "https://...",
"description": "A love story...",
"relevanceScore": 9
},
{
"id": 2,
"title": "Psychology Basics",
"author": "Author B",
"price": 399,
"cover_url": "https://...",
"description": "Intro to psychology...",
"relevanceScore": 5
}
]
}
---
This section makes it clear how your **category filtering** and **relevance scoring** work, both for developers and contributors.
👉 Would you like me to also draft a **diagram (ASCII or markdown table)** showing the relationship between `books`, `book_genres`, and `genres` so your README visually explains the filtering logic?POST /register- Create a new normal userPOST /login- Login as a normal userPOST /admin/register- Create a new admin userPOST /admin/login- Login as an admin userGET /me- Verify token and return the current userPOST /logout- Clears auth cookie
GET /books- Fetch all booksGET /books/:id- Fetch details for a single bookGET /books-genre/:genreId- Fetch books by genre ID
GET /cart- Fetch cart items for authenticated userPOST /add-to-cart- Add or update a book in the cartPOST /confirm-payment- Clear cart after payment confirmation
Create a .env file in backend/ with:
SUPABASE_URL=https://your-supabase-url
SUPABASE_ANON_KEY=your-supabase-anon-key
JWT_SECRET=your_jwt_secret
PORT=5000Create a .env file in frontend/ with:
VITE_API_URL=http://localhost:5000cd backend
npm install
npm run startcd frontend
npm install
npm run dev- The backend uses cookie-based JWT authentication, so frontend requests should include credentials when calling protected endpoints.
- Supabase is used as the database provider, meaning you must configure your Supabase project and tables for
users,books,book_genres, andcart. - Redux stores user session, cart contents, and theme state for the UI.
- Add validation and improved error handling on the frontend.
- Add a dedicated logout action in Redux to clear user state.
- Implement more robust cart retrieval and user-specific cart filtering on the backend.
- Add tests for backend routes and frontend components.