Skip to content

William-eng/Intermediate2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›’ 3-Tier E-Commerce Application

A full-stack e-commerce application built with React, Node.js/Express, and PostgreSQL.

Architecture Frontend Backend Database


πŸ“‹ Table of Contents


🎯 Overview

This is a modern 3-tier web application demonstrating best practices for full-stack development. The application features a React frontend, RESTful API backend, and PostgreSQL database.

Tech Stack

  • Frontend: React 18, Axios, CSS3
  • Backend: Node.js, Express.js, pg (node-postgres)
  • Database: PostgreSQL
  • Dev Tools: nodemon, dotenv

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  React Frontend β”‚  (Port 3000)
β”‚   (Tier 1)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚ HTTP/REST
         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Node.js Backend β”‚  (Port 5000)
β”‚   (Tier 2)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚ SQL
         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   PostgreSQL    β”‚  (Port 5432)
β”‚   (Tier 3)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

✨ Features

  • βœ… Product catalog display
  • βœ… RESTful API architecture
  • βœ… Database connection with PostgreSQL
  • βœ… CORS-enabled backend
  • βœ… Environment-based configuration
  • βœ… Responsive UI design
  • βœ… Error handling
  • βœ… Hot reload for development

πŸ“¦ Prerequisites

Verify Installation

node -v
npm -v
psql --version
git --version

πŸš€ Installation

1. Clone the Repository

git clone <repository-url>
cd <project-folder>

2. Set Up Database

# Start PostgreSQL
# Linux: sudo systemctl start postgresql
# macOS: brew services start postgresql
# Windows: Start via Services

# Create database
psql -U postgres
CREATE DATABASE ecommerce;
\q

3. Install Dependencies

# Backend
cd backend
npm install

# Frontend (in new terminal)
cd frontend
npm install

4. Configure Environment Variables

backend/.env:

PORT=5000
DB_HOST=localhost
DB_USER=postgres
DB_PASS=your_postgres_password
DB_NAME=ecommerce

frontend/.env:

REACT_APP_API_URL=http://localhost:5000

πŸƒ Running the Application

Terminal 1 - Backend

cd backend
npm start
# or with auto-reload: npm run dev

Expected: βœ… Database connected! πŸš€ Backend on http://localhost:5000

Terminal 2 - Frontend

cd frontend
npm start

Expected: Browser opens at http://localhost:3000


πŸ“ Project Structure

project-root/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ index.js           # Express server
β”‚   β”œβ”€β”€ package.json       # Backend dependencies
β”‚   β”œβ”€β”€ .env              # Environment variables
β”‚   └── node_modules/
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ public/
β”‚   β”‚   └── index.html
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.js        # Main component
β”‚   β”‚   β”œβ”€β”€ App.css
β”‚   β”‚   β”œβ”€β”€ index.js
β”‚   β”‚   └── index.css
β”‚   β”œβ”€β”€ package.json      # Frontend dependencies
β”‚   β”œβ”€β”€ .env
β”‚   └── node_modules/
β”œβ”€β”€ .gitignore
└── README.md

πŸ”Œ API Endpoints

Base URL: http://localhost:5000

Method Endpoint Description Response
GET / Health check { message, database_time }
GET /api/products Get products { products: [...] }

Example

curl http://localhost:5000/api/products

Response:

{
  "products": [
    { "id": 1, "name": "Laptop", "price": 999.99 },
    { "id": 2, "name": "Mouse", "price": 29.99 }
  ]
}

πŸ› οΈ Troubleshooting

Port Already in Use

# Kill process on port 5000
# Linux/Mac: lsof -ti:5000 | xargs kill -9
# Windows: netstat -ano | findstr :5000

Cannot Connect to Database

  • Check PostgreSQL is running
  • Verify credentials in backend/.env
  • Test: psql -U postgres -d ecommerce -c "SELECT NOW();"

CORS Errors

  • Ensure app.use(cors()) in backend
  • Check REACT_APP_API_URL in frontend/.env

Module Not Found

rm -rf node_modules package-lock.json
npm install

πŸ“Š Next Steps

  • Add authentication (JWT)
  • Implement shopping cart
  • Add product CRUD operations
  • Create admin dashboard
  • Add payment integration
  • Implement search/filters
  • Add tests
  • Deploy to production

🀝 Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add AmazingFeature')
  4. Push to branch (git push origin feature/AmazingFeature)
  5. Open Pull Request

πŸ“ License

MIT License - see LICENSE file for details


Happy Coding! πŸš€# πŸ›’ 3-Tier E-Commerce Application

A full-stack e-commerce application built with React, Node.js/Express, and PostgreSQL.

Architecture Frontend Backend Database


πŸ“‹ Table of Contents


🎯 Overview

This is a modern 3-tier web application demonstrating best practices for full-stack development. The application features a React frontend, RESTful API backend, and PostgreSQL database.

Tech Stack

  • Frontend: React 18, Axios, CSS3
  • Backend: Node.js, Express.js, pg (node-postgres)
  • Database: PostgreSQL
  • Dev Tools: nodemon, dotenv

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  React Frontend β”‚  (Port 3000)
β”‚   (Tier 1)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚ HTTP/REST
         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Node.js Backend β”‚  (Port 5000)
β”‚   (Tier 2)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚ SQL
         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   PostgreSQL    β”‚  (Port 5432)
β”‚   (Tier 3)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

✨ Features

  • βœ… Product catalog display
  • βœ… RESTful API architecture
  • βœ… Database connection with PostgreSQL
  • βœ… CORS-enabled backend
  • βœ… Environment-based configuration
  • βœ… Responsive UI design
  • βœ… Error handling
  • βœ… Hot reload for development

πŸ“¦ Prerequisites

Verify Installation

node -v
npm -v
psql --version
git --version

πŸš€ Installation

1. Clone the Repository

git clone <repository-url>
cd <project-folder>

2. Set Up Database

# Start PostgreSQL
# Linux: sudo systemctl start postgresql
# macOS: brew services start postgresql
# Windows: Start via Services

# Create database
psql -U postgres
CREATE DATABASE ecommerce;
\q

3. Install Dependencies

# Backend
cd backend
npm install

# Frontend (in new terminal)
cd frontend
npm install

4. Configure Environment Variables

backend/.env:

PORT=5000
DB_HOST=localhost
DB_USER=postgres
DB_PASS=your_postgres_password
DB_NAME=ecommerce

frontend/.env:

REACT_APP_API_URL=http://localhost:5000

πŸƒ Running the Application

Terminal 1 - Backend

cd backend
npm start
# or with auto-reload: npm run dev

Expected: βœ… Database connected! πŸš€ Backend on http://localhost:5000

Terminal 2 - Frontend

cd frontend
npm start

Expected: Browser opens at http://localhost:3000


πŸ“ Project Structure

project-root/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ index.js           # Express server
β”‚   β”œβ”€β”€ package.json       # Backend dependencies
β”‚   β”œβ”€β”€ .env              # Environment variables
β”‚   └── node_modules/
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ public/
β”‚   β”‚   └── index.html
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.js        # Main component
β”‚   β”‚   β”œβ”€β”€ App.css
β”‚   β”‚   β”œβ”€β”€ index.js
β”‚   β”‚   └── index.css
β”‚   β”œβ”€β”€ package.json      # Frontend dependencies
β”‚   β”œβ”€β”€ .env
β”‚   └── node_modules/
β”œβ”€β”€ .gitignore
└── README.md

πŸ”Œ API Endpoints

Base URL: http://localhost:5000

Method Endpoint Description Response
GET / Health check { message, database_time }
GET /api/products Get products { products: [...] }

Example

curl http://localhost:5000/api/products

Response:

{
  "products": [
    { "id": 1, "name": "Laptop", "price": 999.99 },
    { "id": 2, "name": "Mouse", "price": 29.99 }
  ]
}

πŸ› οΈ Troubleshooting

Port Already in Use

# Kill process on port 5000
# Linux/Mac: lsof -ti:5000 | xargs kill -9
# Windows: netstat -ano | findstr :5000

Cannot Connect to Database

  • Check PostgreSQL is running
  • Verify credentials in backend/.env
  • Test: psql -U postgres -d ecommerce -c "SELECT NOW();"

CORS Errors

  • Ensure app.use(cors()) in backend
  • Check REACT_APP_API_URL in frontend/.env

Module Not Found

rm -rf node_modules package-lock.json
npm install

πŸ“Š Next Steps

  • Add authentication (JWT)
  • Implement shopping cart
  • Add product CRUD operations
  • Create admin dashboard
  • Add payment integration
  • Implement search/filters
  • Add tests
  • Deploy to production

🀝 Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add AmazingFeature')
  4. Push to branch (git push origin feature/AmazingFeature)
  5. Open Pull Request

πŸ“ License

MIT License - see LICENSE file for details


Happy Coding! πŸš€

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors