A modern full-stack e-commerce application for managing and selling sweets online. Built with React, TypeScript, Node.js, Express, and PostgreSQL.
- User Registration & Login - Secure JWT-based authentication
- Browse Sweets - Explore all available sweet products
- Advanced Search - Filter sweets by name, category, and price range
- Shopping Cart - Purchase multiple sweets with quantity selection
- Purchase History - Track all purchases
- Real-time Inventory - See actual stock availability
- Admin Dashboard - Complete inventory management system
- Product Management - Create, read, update, and delete sweets
- Inventory Control - Manage stock levels and restocking
- Sales Analytics - View total inventory value and item counts
- Low Stock Alerts - Real-time notifications for items with less than 10 units
- Category Management - Organize sweets by categories
- Role-Based Access Control - Admin and User roles with different permissions
- JWT Authentication - Secure token-based authentication
- Protected Routes - Frontend and backend route protection
- Admin-Only Operations - Restricted access to admin features
- Password Security - Secure password handling
- React 18 - UI framework
- TypeScript - Type safety
- Tailwind CSS - Styling
- Vite - Build tool
- Axios - HTTP client
- Lucide React - Icons
- React Router - Client-side routing
- Node.js - Runtime
- Express.js - Web framework
- TypeScript - Type safety
- Prisma - ORM
- PostgreSQL - Database
- JWT - Authentication
- Bcrypt - Password hashing
- Vitest - Testing framework
- Node.js (v16 or higher)
- npm or yarn
- PostgreSQL (v12 or higher)
- Git
git clone <repository-url>
cd sweet-shopcd server
# Install dependencies
npm install
# Create .env file
cp .env.example .env
# Configure your database in .env
DATABASE_URL="postgresql://user:password@localhost:5432/sweet_shop"
JWT_SECRET="your-secret-key-here"
PORT=4000
# Run migrations
npm run migrate
# Start the server
npm run devThe backend will run on http://localhost:4000
cd ../client
# Install dependencies
npm install
# Create .env file (optional)
echo 'VITE_API_URL=http://localhost:4000/api' > .env.local
# Start the development server
npm run devThe frontend will run on http://localhost:5173
sweet-shop/
βββ client/ # React Frontend
β βββ src/
β β βββ components/ # Reusable UI components
β β β βββ SweetCard.tsx # Product card component
β β β βββ ProtectedRoute.tsx # Route protection wrapper
β β β βββ Layout/ # Layout components
β β β βββ UI/ # UI components (Button, Input, Modal, etc.)
β β βββ contexts/ # React contexts
β β β βββ AuthContext.tsx # Authentication state management
β β βββ lib/ # Utilities and API client
β β β βββ api.ts # Axios API client
β β β βββ auth.ts # Auth utilities
β β β βββ utils.ts # Helper functions
β β βββ pages/ # Page components
β β β βββ Login.tsx # Login page
β β β βββ Register.tsx # Registration page
β β β βββ Dashboard.tsx # User dashboard
β β β βββ AdminPanel.tsx # Admin dashboard
β β βββ App.tsx # Main app component
β β βββ main.tsx # Entry point
β βββ package.json
β
βββ server/ # Express Backend
β βββ src/
β β βββ modules/ # Feature modules
β β β βββ auth/ # Authentication routes/controllers/services
β β β βββ sweets/ # Products routes/controllers/services
β β βββ middleware/ # Express middleware
β β β βββ authMiddleware.ts # Auth verification
β β β βββ roleMiddleware.ts # Role-based access
β β β βββ validate.ts # Request validation
β β βββ common/ # Shared utilities
β β β βββ errors/ # Custom error classes
β β β βββ jwt/ # JWT utilities
β β βββ app.ts # Express app setup
β β βββ server.ts # Server entry point
β β βββ prisma.ts # Prisma client
β βββ prisma/
β β βββ schema.prisma # Database schema
β β βββ migrations/ # Database migrations
β βββ package.json
β
βββ README.md
- Register and login
- Browse and search sweets
- Make purchases
- View purchase history
- All customer features plus:
- Create/Read/Update/Delete sweets
- Manage inventory levels
- View sales analytics
- Manage low stock alerts
POST /api/auth/register- Register new userPOST /api/auth/login- Login user
GET /api/sweets- Get all sweetsGET /api/sweets/search- Search sweets by criteriaPOST /api/sweets/:id/purchase- Purchase sweets
POST /api/sweets- Create new sweetPUT /api/sweets/:id- Update sweet detailsDELETE /api/sweets/:id- Delete sweetPOST /api/sweets/:id/restock- Add to stock
model User {
id String @id @default(cuid())
email String @unique
password String
name String?
role Role @default(USER)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
enum Role {
USER
ADMIN
}model Sweet {
id String @id @default(cuid())
name String
category String
price Float
quantity Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}cd server
npm run test- Use the provided UI to test features
- Test with both admin and user roles
- Verify role-based access controls
cd client
npm run build
# Deploy the dist/ folder to Vercelcd server
npm run build
# Deploy to your hosting providerBackend (.env)
DATABASE_URL=your_postgresql_url
JWT_SECRET=your_secret_key
NODE_ENV=production
PORT=4000
Frontend (.env.local)
VITE_API_URL=https://your-api-url.com/api
- Dark Theme - Eye-friendly dark interface
- Responsive Design - Works on all devices
- Toast Notifications - User feedback for actions
- Loading States - Smooth loading indicators
- Modal Dialogs - Confirmation and input modals
- Real-time Updates - Data refreshes after actions
- Price Display - All prices shown in Indian Rupees (βΉ)
Admin Account
- Email:
admin@sweetshop.com - Password:
admin@123
Regular User Account
- Email:
user@sweetshop.com - Password:
user@123
- Port already in use: Change PORT in .env
- Database connection error: Verify DATABASE_URL
- JWT errors: Ensure JWT_SECRET is set
- API connection error: Check VITE_API_URL
- CORS errors: Verify backend CORS configuration
- Build errors: Run
npm installand clear cache
This project is licensed under the MIT License - see the LICENSE file for details.
For issues and questions, please create an issue in the repository.
Built with β€οΈ using React, Node.js, and PostgreSQL