This project is a Campus Shop Assistant, a full-stack e-commerce application. It consists of a React frontend and a Node.js (Express) backend with a PostgreSQL database.
Key Features:
- User authentication (registration and login).
- Product browsing and searching.
- Shopping cart and checkout process.
- Order management for users and sellers.
- Seller dashboard for inventory and order management.
- User profiles.
- AI-powered Chatbot for product search, price queries, and recommendations.
- Install PostgreSQL: Ensure you have PostgreSQL installed and running on your system.
- Create a User: Create a PostgreSQL user with appropriate permissions for the database.
- Initialize Database Schema:
Navigate to the
backenddirectory and run the following command to initialize the database schema:You should see a message like "Schema applied successfully." upon successful initialization.cd backend npm run db:init
After initial setup, you can use these commands to manage your database:
# Complete database rebuild with seed data (recommended for fresh start)
npm run db:reset-seed
# Reset database only (drop and recreate tables from schema)
npm run db:reset
# Seed data only (requires tables to exist)
npm run db:seedSeed Data Includes:
- 5 test users (sellers)
- 5 product categories (Stationery, Books, Clothing, Electronics, Accessories)
- 32 sample products with varied descriptions
-
Start the Backend Server: From the
backenddirectory, run:npm run dev
The backend server will start on
http://localhost:5000. -
Start the Frontend Development Server: Navigate to the
frontenddirectory and run:cd frontend npm run devThe frontend application will typically be available at
http://localhost:5173(or another port if 5173 is in use).
- Register a new user:
curl -X POST http://localhost:5000/api/users/register -H "Content-Type: application/json" -d '{"username": "testuser", "password": "password", "email": "test@example.com", "user_type": "buyer"}'
- Login a user:
curl -X POST http://localhost:5000/api/users/login -H "Content-Type: application/json" -d '{"email": "test@example.com", "password": "password"}'
- Get user profile: (Requires authentication token)
curl -X GET http://localhost:5000/api/users/me -H "Authorization: Bearer <YOUR_TOKEN>" - Update user profile: (Requires authentication token)
curl -X PUT http://localhost:5000/api/users/me -H "Content-Type: application/json" -H "Authorization: Bearer <YOUR_TOKEN>" -d '{"username": "newusername"}'
- Get all products:
curl -X GET http://localhost:5000/api/product
- Get a product by ID:
curl -X GET http://localhost:5000/api/product/1
- Create a new product: (Requires seller authentication token)
curl -X POST http://localhost:5000/api/product -H "Content-Type: application/json" -H "Authorization: Bearer <YOUR_SELLER_TOKEN>" -d '{"name": "My Product", "description": "This is a great product.", "price": 19.99, "quantity": 100}'
- Update a product: (Requires seller authentication token)
curl -X PUT http://localhost:5000/api/product/1 -H "Content-Type: application/json" -H "Authorization: Bearer <YOUR_SELLER_TOKEN>" -d '{"price": 24.99}'
- Delete a product: (Requires seller authentication token)
curl -X DELETE http://localhost:5000/api/product/1 -H "Authorization: Bearer <YOUR_SELLER_TOKEN>"
- Create a new order: (Requires authentication token)
curl -X POST http://localhost:5000/api/orders -H "Content-Type: application/json" -H "Authorization: Bearer <YOUR_TOKEN>" -d '{"products": [{"product_id": 1, "quantity": 2}]}'
- Get all orders for the logged-in user: (Requires authentication token)
curl -X GET http://localhost:5000/api/orders -H "Authorization: Bearer <YOUR_TOKEN>" - Get a specific order by ID: (Requires authentication token)
curl -X GET http://localhost:5000/api/orders/1 -H "Authorization: Bearer <YOUR_TOKEN>" - Update order status: (Requires seller authentication token)
curl -X PUT http://localhost:5000/api/orders/1/status -H "Content-Type: application/json" -H "Authorization: Bearer <YOUR_SELLER_TOKEN>" -d '{"status": "shipped"}'
-
Send a message to the chatbot:
curl -X POST http://localhost:5000/api/chatbot/query -H "Content-Type: application/json" -d '{"message": "show me laptops"}'
-
Example queries:
# Search for products curl -X POST http://localhost:5000/api/chatbot/query -H "Content-Type: application/json" -d '{"message": "find electronics"}' # Ask for price curl -X POST http://localhost:5000/api/chatbot/query -H "Content-Type: application/json" -d '{"message": "how much is the laptop"}' # Get recommendations curl -X POST http://localhost:5000/api/chatbot/query -H "Content-Type: application/json" -d '{"message": "what do you recommend"}' # Get help curl -X POST http://localhost:5000/api/chatbot/query -H "Content-Type: application/json" -d '{"message": "help"}'
The chatbot works out of the box with regex-based intent detection. For enhanced NLP using spaCy:
cd backend/nlp_service
setup.bat # Windows - creates venv, installs dependencies, sets up model
start.bat # Windows - starts NLP service on port 5001
# Linux/macOS
chmod +x setup.sh start.sh
./setup.sh && ./start.shThis project includes a custom trained spaCy model (models/campus_shop_nlp) optimized for campus shopping queries with:
- Text Classification: greeting, get_recommendations, search_product, ask_price, help
- Named Entity Recognition: CATEGORY, CONDITION, PRICE, PRODUCT
The setup scripts will automatically use this custom model if available, falling back to en_core_web_sm otherwise.
cd backend/nlp_service
python -m venv venv && venv\Scripts\activate # Windows
pip install -r requirements.txt
# Custom model (recommended):
set SPACY_MODEL=models/campus_shop_nlp && uvicorn app:app --port 5001
# Or generic model:
python -m spacy download en_core_web_sm
set SPACY_MODEL=en_core_web_sm && uvicorn app:app --port 5001Note: If NLP service is unavailable, chatbot automatically falls back to regex-based detection.
cd backend
npm testcd frontend
npm test# Backend
npm test -- chatbot.test.js
# Frontend
npm test -- --run chatbotService.test.js