Sign inSign up

charllson717/product-app

By charllson717

•Updated 6 months ago

A full-stack web application built with **Node.js**, **Express 5**, **TypeScript** and Mysql

Image
0

10K+

charllson717/product-app repository overview

⁠⬡ ProductApp

A full-stack web application built with Node.js, Express 5, TypeScript, and MySQL — containerized with Docker. Users can sign up, log in, and search a product catalogue. Built as a CA project for ICT University.


⁠Tech Stack

LayerTechnology
BackendNode.js + Express 5 + TypeScript
DatabaseMySQL 8.0 (Docker container)
AuthSession-based (express-session + bcrypt)
FrontendVanilla HTML + CSS + JavaScript
Runtimetsx (runs TypeScript directly)
ContainerDocker + Docker Compose

⁠Features

  • Signup — register with username, email, and hashed password
  • Login — session-based authentication against MySQL users table
  • Protected Search — only logged-in users can access the product search page
  • Product Search — query products by name or description (partial match)
  • Persistent Storage — MySQL data survives container restarts via Docker volume
  • Auto DB Init — tables created and seeded automatically on first run

⁠Project Structure

product-app/
├── src/
│   ├── server.ts              # Entry point — starts server, inits DB
│   ├── app.ts                 # Express app, middleware, routes
│   ├── db.ts                  # MySQL connection pool
│   ├── routes/
│   │   ├── auth.ts            # POST /auth/signup, /auth/login, /auth/logout
│   │   └── products.ts        # GET /products/search?q=..., GET /products
│   └── middleware/
│       └── requireAuth.ts     # Protects routes that need a logged-in session
├── public/
│   ├── login.html
│   ├── signup.html
│   └── search.html
├── .env.example
├── .dockerignore
├── Dockerfile
├── docker-compose.yml
├── package.json
└── tsconfig.json

⁠Running Locally with Docker

Prerequisites: Docker Desktop installed and running.

# 1. Clone the repo
git clone https://github.com/fanyicharllson/product-app.git
cd product-app

# 2. Start all services (builds app image + pulls MySQL image)
docker compose up --build

# 3. Open in browser
# http://localhost:3000

That's it. No local MySQL install needed — everything runs in containers.


⁠API Endpoints

MethodEndpointAuth RequiredDescription
POST/auth/signupNoRegister a new user
POST/auth/loginNoLogin and create session
POST/auth/logoutNoDestroy session
GET/products/search?q=✅ YesSearch products by name/description
GET/products✅ YesList all products
⁠Example Request (Thunder Client / Postman)

POST http://localhost:3000/auth/signup

{
  "username": "john",
  "email": "[email protected]",
  "password": "password123"
}

GET http://localhost:3000/products/search?q=laptop

Requires an active session cookie from login.


⁠Environment Variables

Copy .env.example to .env and adjust if needed:

DB_HOST=db
DB_PORT=3306
DB_USER=appuser
DB_PASSWORD=apppassword
DB_NAME=productdb
SESSION_SECRET=super_secret_change_in_production
PORT=3000

When running with Docker Compose, environment variables are injected via docker-compose.yml and the .env file is not required.


⁠Docker Hub

# Pull the image directly
docker pull fanyicharllson/product-app:latest

⁠Docker Commands Reference

CommandWhat it does
docker compose up --buildBuild image and start all containers
docker compose up -dStart in detached mode (background)
docker compose downStop and remove containers (data kept)
docker compose down -vStop containers AND delete volumes (data lost)
docker compose logs -f appStream live logs from the app container
docker psList running containers
docker imagesList local Docker images

⁠Author

fanyicharllson — github.com/fanyicharllson⁠
Built with Node.js, Express, TypeScript, MySQL, Docker.

Tag summary

Content type

Image

Digest

sha256:84e8a6a22…

Size

79.4 MB

Last updated

6 months ago

docker pull charllson717/product-app