Full-Stack Web Development Tutorial: Sample Catalog App

React + Node.js + SQLite

Project Structure

The application is split into two folders: a Node.js backend API and a React frontend.

project/ ├── backend/ │ ├── package.json │ ├── database.js │ ├── server.js │ ├── seed.js │ └── routes/ │ ├── products.js │ ├── orders.js │ └── users.js └── frontend/ ├── package.json ├── public/ │ └── index.html └── src/ ├── index.js ├── index.css ├── App.js ├── App.css ├── context/ │ ├── CartContext.js │ └── UserContext.js ├── components/ │ ├── Navbar.js │ └── ProductCard.js └── pages/ ├── Home.js ├── Products.js ├── Deals.js ├── OrderHistory.js ├── Rewards.js ├── Collection.js ├── Delivery.js └── Login.js

Setup Commands

Run these terminal commands in order to get the project running.

  1. Create the project folders: mkdir backend then mkdir frontend
  2. Create the frontend with React: cd frontend then npx create-react-app . (or manually create package.json and run npm install)
  3. Install backend dependencies: cd backend then npm install
  4. Create the route folder: mkdir routes (inside backend)
  5. Create all the files listed above and paste the code from each section below
  6. Seed the database: cd backend then node seed.js
  7. Start the backend: node server.js (runs on port 5000)
  8. Start the frontend: cd frontend then npm start (runs on port 3000)
Demo login after seeding: john@email.com / password123

Backend: package.json

Dependencies: Express for the server, cors for cross-origin requests, sql.js for SQLite, bcryptjs for password hashing.

backend/package.json

Backend: database.js

Sets up the SQLite database using sql.js. Creates a Statement wrapper class so we can use .prepare().all(), .get() and .run() methods. Also creates all 6 tables: users, products, deals, orders, order_items, and rewards.

backend/database.js

Backend: server.js

Main entry point. Initializes the database asynchronously, then sets up Express with CORS and JSON middleware, mounts the API routes, and starts listening on port 5000.

backend/server.js

Backend: seed.js

Run with node seed.js to populate the database with sample products (37 items across 8 categories), deals, demo users, and order history.

backend/seed.js

Backend: routes/products.js

REST API routes for products. Supports filtering by category, searching by name, fetching categories, getting active deals (with a JOIN to the products table), and fetching a single product by ID.

backend/routes/products.js

Backend: routes/orders.js

Handles fetching a user's order history (with a JOIN to get item details) and creating new orders. When an order is placed, it calculates the total, inserts order items, and awards loyalty reward points (1 point per pound spent).

backend/routes/orders.js

Backend: routes/users.js

User authentication routes (register and login with bcrypt password hashing), plus reward points endpoints for viewing history and redeeming points.

backend/routes/users.js

Frontend: package.json

React app dependencies. Uses react-router-dom for page navigation and react-scripts for the dev server and build tooling.

frontend/package.json

Frontend: public/index.html

The HTML shell. React mounts into the div with id "root".

frontend/public/index.html

Frontend: src/index.js

Entry point. Wraps the App in BrowserRouter (for routing), UserProvider and CartProvider (for global state).

frontend/src/index.js

Frontend: src/index.css

Global CSS reset. Removes default margins, sets the base font, and resets link/button/input styles.

frontend/src/index.css

Frontend: src/App.js

Root component. Renders the Navbar, defines all Routes using React Router, and includes a footer.

frontend/src/App.js

Frontend: src/App.css

All the styles for the entire application — navbar, slide-out basket, footer, hero, product grid, cards, forms, checkout layout, auth pages, and responsive breakpoints. This is the longest file.

frontend/src/App.css

State Management: CartContext.js

React Context for the checkout basket. Provides addToCart, removeFromCart, updateQuantity, clearCart, plus computed cartTotal and cartCount values to all components.

frontend/src/context/CartContext.js

State Management: UserContext.js

React Context for the logged-in user. Persists user data to localStorage so the session survives page refreshes.

frontend/src/context/UserContext.js

Component: Navbar.js

Navigation bar with logo, page links, basket button with item count badge, and login/logout. Includes a slide-out panel with quantity controls and checkout links for delivery or collection.

frontend/src/components/Navbar.js

Component: ProductCard.js

Reusable product card used on the Home, Products, and Deals pages. Shows the image (emoji), name, description, price (with deal price if applicable), and an add button with a brief confirmation state.

frontend/src/components/ProductCard.js

Page: Home.js

Landing page with a hero banner, category grid linking to filtered listings, a preview of current promotions, and featured items from the first category (Electronics).

frontend/src/pages/Home.js

Page: Products.js

Browse all products with a sidebar category filter and search bar. Uses useSearchParams to read/write the category from the URL query string. Fetches deals to show discount badges on matching products.

frontend/src/pages/Products.js

Page: Deals.js

Shows all active deals with a red banner and product cards displaying discount percentages and original/deal prices.

frontend/src/pages/Deals.js

Page: OrderHistory.js

Displays the logged-in user's past orders. Each order card shows the order number, date, status badge, item list, delivery/collection info, and total. Requires authentication.

frontend/src/pages/OrderHistory.js

Page: Rewards.js

Shows the user's loyalty points balance, points value in pounds, a redeem button (when 100+ points), and a full history of earned/redeemed points.

frontend/src/pages/Rewards.js

Page: Collection.js

Pickup checkout page. User selects a branch from a dropdown, picks a date and time slot, reviews the order summary, and submits. Success screen shows confirmation and loyalty points.

frontend/src/pages/Collection.js

Page: Delivery.js

Home delivery checkout page. User enters their address, postcode, selects a date and time slot. Includes a delivery fee (£3.99, free over £40). Order summary with running total. Success screen on completion.

frontend/src/pages/Delivery.js

Page: Login.js

Combined login and registration page. Toggles between login and register forms. Sends credentials to the backend API and stores the returned user data in UserContext on success.

frontend/src/pages/Login.js