Skip to content

22bcs030/Sweet-Shop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🍬 Sweet Shop Management System

A full-stack Sweet Shop Management System built with modern technologies following Test-Driven Development (TDD) practices.

Sweet Shop TypeScript React Node.js SQLite Test Coverage

🌐 Live Demo

Service URL
Frontend https://sweet-shop-ten.vercel.app
Backend API https://sweet-shop-api-1fxc.onrender.com

Note: The backend is hosted on Render's free tier, so it may take ~30 seconds to wake up on first request.

πŸ“‹ Table of Contents

✨ Features

User Features

  • πŸ” User registration and login with JWT authentication
  • πŸ›’ Browse all available sweets
  • πŸ” Search and filter sweets by name, category, and price range
  • πŸ’° Purchase sweets (quantity decreases on purchase)
  • πŸ“± Responsive design for all devices

Admin Features

  • βž• Add new sweets to inventory
  • ✏️ Edit existing sweet details
  • πŸ—‘οΈ Delete sweets from catalog
  • πŸ“¦ Restock sweets (increase quantity)
  • πŸ‘‘ Admin-only access controls

πŸ› οΈ Tech Stack

Backend

  • Runtime: Node.js
  • Framework: Express.js
  • Language: TypeScript
  • Database: SQLite (using better-sqlite3)
  • Authentication: JWT (jsonwebtoken)
  • Password Hashing: bcryptjs
  • Validation: express-validator
  • Testing: Jest + Supertest

Frontend

  • Framework: React 18
  • Language: TypeScript
  • Build Tool: Vite
  • Routing: React Router DOM
  • HTTP Client: Axios
  • Styling: CSS (custom)

πŸ“ Project Structure

incubytevs/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”‚   └── database.ts      # SQLite database configuration
β”‚   β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”‚   └── auth.middleware.ts # JWT authentication middleware
β”‚   β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”‚   β”œβ”€β”€ user.model.ts    # User model and operations
β”‚   β”‚   β”‚   └── sweet.model.ts   # Sweet model and operations
β”‚   β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.routes.ts   # Auth endpoints
β”‚   β”‚   β”‚   └── sweets.routes.ts # Sweets CRUD + inventory endpoints
β”‚   β”‚   β”œβ”€β”€ tests/
β”‚   β”‚   β”‚   β”œβ”€β”€ setup.ts         # Test configuration
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.test.ts     # Auth endpoint tests
β”‚   β”‚   β”‚   β”œβ”€β”€ sweets.test.ts   # Sweets CRUD tests
β”‚   β”‚   β”‚   └── inventory.test.ts # Purchase/restock tests
β”‚   β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   β”‚   └── jwt.ts           # JWT utilities
β”‚   β”‚   β”œβ”€β”€ app.ts               # Express app configuration
β”‚   β”‚   └── index.ts             # Server entry point
β”‚   β”œβ”€β”€ data/                    # SQLite database files
β”‚   β”œβ”€β”€ coverage/                # Test coverage reports
β”‚   β”œβ”€β”€ package.json
β”‚   └── tsconfig.json
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ Navbar.tsx       # Navigation component
β”‚   β”‚   β”‚   β”œβ”€β”€ SweetCard.tsx    # Sweet display card
β”‚   β”‚   β”‚   └── SearchFilter.tsx # Search and filter component
β”‚   β”‚   β”œβ”€β”€ context/
β”‚   β”‚   β”‚   └── AuthContext.tsx  # Authentication context
β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”‚   β”œβ”€β”€ LoginPage.tsx    # Login page
β”‚   β”‚   β”‚   β”œβ”€β”€ RegisterPage.tsx # Registration page
β”‚   β”‚   β”‚   β”œβ”€β”€ DashboardPage.tsx # Main sweet listing
β”‚   β”‚   β”‚   └── AdminPage.tsx    # Admin management panel
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   β”œβ”€β”€ api.ts           # Axios configuration
β”‚   β”‚   β”‚   └── sweets.ts        # Sweets API service
β”‚   β”‚   β”œβ”€β”€ types/
β”‚   β”‚   β”‚   └── index.ts         # TypeScript type definitions
β”‚   β”‚   └── config/
β”‚   β”‚       └── api.ts           # API configuration
β”‚   β”œβ”€β”€ package.json
β”‚   └── vite.config.ts
β”‚
└── README.md

πŸš€ Getting Started

Prerequisites

  • Node.js (v18 or higher)
  • npm (v9 or higher)

Backend Setup

  1. Navigate to the backend directory:

    cd backend
  2. Install dependencies:

    npm install
  3. Create environment file (optional - uses defaults):

    # .env file
    PORT=3001
    NODE_ENV=development
    JWT_SECRET=your-super-secret-jwt-key
    DATABASE_PATH=./data/sweetshop.db
  4. Run tests to verify setup:

    npm test
  5. Start the development server:

    npm run dev

The backend will be running at http://localhost:3001

Frontend Setup

  1. Navigate to the frontend directory:

    cd frontend
  2. Install dependencies:

    npm install
  3. Start the development server:

    npm run dev

The frontend will be running at http://localhost:5173

Running Both Together

  1. Open two terminal windows
  2. In terminal 1: cd backend && npm run dev
  3. In terminal 2: cd frontend && npm run dev

πŸ“‘ API Documentation

Authentication Endpoints

Method Endpoint Description Auth Required
POST /api/auth/register Register a new user No
POST /api/auth/login Login and get token No

Register Request Body

{
  "email": "user@example.com",
  "password": "password123",
  "name": "John Doe",
  "role": "user"  // or "admin"
}

Login Request Body

{
  "email": "user@example.com",
  "password": "password123"
}

Sweets Endpoints (Protected)

Method Endpoint Description Admin Only
GET /api/sweets Get all sweets No
GET /api/sweets/search Search sweets No
POST /api/sweets Create a new sweet No
PUT /api/sweets/:id Update a sweet No
DELETE /api/sweets/:id Delete a sweet Yes

Sweet Object

{
  "id": "uuid",
  "name": "Chocolate Cake",
  "category": "Cakes",
  "price": 25.99,
  "quantity": 10,
  "description": "Delicious chocolate cake",
  "image_url": "https://example.com/cake.jpg"
}

Search Query Parameters

  • name - Search by name (partial match)
  • category - Filter by category
  • minPrice - Minimum price
  • maxPrice - Maximum price

Inventory Endpoints (Protected)

Method Endpoint Description Admin Only
POST /api/sweets/:id/purchase Purchase a sweet No
POST /api/sweets/:id/restock Restock a sweet Yes

Purchase Request Body

{
  "quantity": 2  // optional, defaults to 1
}

Restock Request Body

{
  "quantity": 50  // required
}

πŸ§ͺ Testing

Run All Tests

cd backend
npm test

Run Tests with Watch Mode

npm run test:watch

Test Coverage Report

npm run test:coverage

Current Test Results

  • Total Tests: 47
  • All Passing: βœ…
  • Coverage: ~86%
Test Suites: 3 passed, 3 total
Tests:       47 passed, 47 total
Snapshots:   0 total

Test Categories

  • Auth Tests (12): Registration and login validation
  • Sweets Tests (20): CRUD operations and search
  • Inventory Tests (15): Purchase and restock operations

πŸ€– My AI Usage

AI Tools Used

  • GitHub Copilot (Claude Opus 4.5): Primary AI assistant for code generation and development

How AI Was Used

  1. Project Architecture & Planning

    • I used AI to help design the project structure and determine the best technology stack for the requirements
    • The AI helped outline the TDD approach and test categories
  2. Boilerplate Generation

    • Initial Express.js setup with TypeScript configuration
    • Database schema design and SQLite integration
    • JWT authentication middleware structure
    • React component scaffolding
  3. Test Writing (TDD Red Phase)

    • AI helped generate comprehensive test cases following TDD principles
    • Tests were written BEFORE implementation to define expected behavior
    • Coverage includes edge cases like validation errors, authentication failures, and insufficient stock scenarios
  4. Implementation (TDD Green Phase)

    • Routes and controllers were implemented to make tests pass
    • Model layer with SQLite operations
    • Frontend React components with proper TypeScript types
  5. Code Review & Refactoring

    • AI suggested improvements for code organization
    • Helped identify and fix bugs (e.g., the purchase route bug with undefined body)
    • TypeScript type safety improvements

AI Impact on Workflow

Positive Impacts:

  • Significantly accelerated boilerplate code generation
  • Helped maintain consistency across the codebase
  • Provided comprehensive test coverage suggestions
  • Reduced time spent on syntax and configuration issues

Learning Experience:

  • AI is excellent for repetitive patterns but requires human oversight for edge cases
  • The TDD process was enhanced by AI generating test scenarios I might have missed
  • AI suggestions needed validation against project requirements

Responsible AI Usage:

  • All AI-generated code was reviewed and understood before inclusion
  • Business logic and architectural decisions were made by me
  • AI was used as a productivity tool, not a replacement for understanding

Commit Co-authorship

All commits in this project where AI was used include the co-author trailer:

Co-authored-by: GitHub Copilot <copilot@github.com>

πŸ“Έ Screenshots

Login Page

User authentication with email and password

Login Page

Register Page

New user registration with admin option

Register Page

Dashboard

Browse, search, and purchase sweets

For user

Dashboard

For admin

Dashboard View 2

Search & Filter

Filter sweets by category, name, and price range

Search Filter

Admin Panel - Add New Sweet

Add new sweets to inventory

Admin Add New

Admin Panel - Edit Sweet

Edit existing sweet details

Admin Edit

Mobile Responsive

Optimized for all screen sizes

Mobile View


πŸ“„ License

This project is licensed under the ISC License.

πŸ‘€ Author

Built as part of the Sweet Shop Management System TDD Kata assignment.


Made with ❀️ and 🍬

About

🍬 Full-stack Sweet Shop Management System built with TDD. Node.js/Express/TypeScript backend, React frontend, SQLite database, JWT auth. Features: user registration, sweet catalog, search/filter, purchase & inventory management. 47 tests, 86% coverage.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages