Skip to content

niteesh7777/sweet-shop-fullstack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Sweet Shop - Full-Stack E-Commerce Application

A modern full-stack e-commerce application for managing and selling sweets online. Built with React, TypeScript, Node.js, Express, and PostgreSQL.

🎯 Features

For Customers

  • 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

For Admins

  • 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

Security

  • 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

πŸ› οΈ Tech Stack

Frontend

  • React 18 - UI framework
  • TypeScript - Type safety
  • Tailwind CSS - Styling
  • Vite - Build tool
  • Axios - HTTP client
  • Lucide React - Icons
  • React Router - Client-side routing

Backend

  • Node.js - Runtime
  • Express.js - Web framework
  • TypeScript - Type safety
  • Prisma - ORM
  • PostgreSQL - Database
  • JWT - Authentication
  • Bcrypt - Password hashing
  • Vitest - Testing framework

πŸ“‹ Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn
  • PostgreSQL (v12 or higher)
  • Git

πŸš€ Installation

1. Clone the Repository

git clone <repository-url>
cd sweet-shop

2. Backend Setup

cd 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 dev

The backend will run on http://localhost:4000

3. Frontend Setup

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 dev

The frontend will run on http://localhost:5173

πŸ“ Project Structure

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

πŸ” User Roles

Customer (USER)

  • Register and login
  • Browse and search sweets
  • Make purchases
  • View purchase history

Administrator (ADMIN)

  • All customer features plus:
  • Create/Read/Update/Delete sweets
  • Manage inventory levels
  • View sales analytics
  • Manage low stock alerts

πŸ“‘ API Endpoints

Authentication

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

Sweets (Public)

  • GET /api/sweets - Get all sweets
  • GET /api/sweets/search - Search sweets by criteria
  • POST /api/sweets/:id/purchase - Purchase sweets

Sweets (Admin Only)

  • POST /api/sweets - Create new sweet
  • PUT /api/sweets/:id - Update sweet details
  • DELETE /api/sweets/:id - Delete sweet
  • POST /api/sweets/:id/restock - Add to stock

πŸ—„οΈ Database Schema

User Model

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
}

Sweet Model

model Sweet {
  id        String   @id @default(cuid())
  name      String
  category  String
  price     Float
  quantity  Int
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

πŸ§ͺ Testing

Backend Tests

cd server
npm run test

Frontend (Manual Testing)

  • Use the provided UI to test features
  • Test with both admin and user roles
  • Verify role-based access controls

🚒 Deployment

Frontend (Vercel)

cd client
npm run build
# Deploy the dist/ folder to Vercel

Backend (Render/Railway)

cd server
npm run build
# Deploy to your hosting provider

Environment Variables

Backend (.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

🎨 UI/UX Features

  • 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 (β‚Ή)

πŸ“ Default Test Credentials

Admin Account

  • Email: admin@sweetshop.com
  • Password: admin@123

Regular User Account

  • Email: user@sweetshop.com
  • Password: user@123

πŸ› Troubleshooting

Backend Issues

  • Port already in use: Change PORT in .env
  • Database connection error: Verify DATABASE_URL
  • JWT errors: Ensure JWT_SECRET is set

Frontend Issues

  • API connection error: Check VITE_API_URL
  • CORS errors: Verify backend CORS configuration
  • Build errors: Run npm install and clear cache

πŸ“š Additional Resources

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“§ Support

For issues and questions, please create an issue in the repository.


Built with ❀️ using React, Node.js, and PostgreSQL

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published