Skip to content

abdelkodoussrahimi/Ecommerce-backend-API

Repository files navigation

Ecommerce Application

An ecommerce application consisting of a Backend API (PHP) and a Flutter mobile app for customers.

📋 Components

Backend API (PHP)

A RESTful API that provides all necessary functions for the ecommerce application.

Flutter Mobile App

A Flutter app for customers to interact with the API.

🚀 Features

  • Authentication: Login, Sign up, Code verification, Password recovery
  • Products: View products, Search, Categories
  • Shopping Cart: Add, Remove, View products
  • Orders: Create orders, View pending and archived orders
  • Favorites: Add and remove favorite products
  • Addresses: Manage shipping addresses
  • Coupons: Validate coupon codes
  • Promotions: Display promotional offers

📁 Project Structure

ecommerce/
├── address/          # Address management
│   ├── add.php
│   ├── delete.php
│   ├── edit.php
│   └── view.php
├── auth/             # Authentication
│   ├── login.php
│   ├── signup.php
│   └── verfiycode.php
├── cart/             # Shopping cart
│   ├── add.php
│   ├── delete.php
│   ├── getcountitems.php
│   └── view.php
├── categories/       # Categories
│   └── view.php
├── coupon/           # Coupons
│   └── checkcoupon.php
├── favorite/         # Favorites
│   ├── add.php
│   ├── deletefromfavroite.php
│   ├── remove.php
│   └── view.php
├── forgetpassword/   # Password recovery
│   ├── checkemail.php
│   ├── resetpassword.php
│   └── verifycode.php
├── items/            # Products
│   ├── items.php
│   └── search.php
├── orders/           # Orders
│   ├── archive.php
│   ├── checkout.php
│   ├── delete.php
│   ├── details.php
│   └── pending.php
├── connect.php       # Database connection
├── functions.php     # Helper functions
├── home.php          # Home page
├── view.sql          # Database file
└── test.php

⚙️ Setup & Installation

Requirements

  • PHP 7.4 or higher
  • MySQL 5.7 or higher
  • Apache/Nginx Web Server

Installation Steps

  1. Clone the repository

    git clone https://github.com/yourusername/ecommerce-app.git
    cd ecommerce
  2. Setup Database

    • Create a new database
    • Import the view.sql file into your database
    mysql -u username -p database_name < view.sql
  3. Configure Database Connection

    • Open connect.php file
    • Update connection details:
    $dsn = "mysql:host=localhost;dbname=your_database_name";
    $user = "your_username";
    $pass = "your_password";
  4. Setup Upload Directory

    • Create an upload folder in the root directory for image uploads
    mkdir upload
    chmod 755 upload

📡 API Endpoints

Authentication

  • POST /auth/signup.php - Register new account
  • POST /auth/login.php - User login
  • POST /auth/verfiycode.php - Verify code

Forget Password

  • POST /forgetpassword/checkemail.php - Verify email
  • POST /forgetpassword/verifycode.php - Verify recovery code
  • POST /forgetpassword/resetpassword.php - Reset password

Home & Categories

  • GET /home.php - Home page (Promotions, Categories, Products)
  • GET /categories/view.php - View all categories

Products

  • GET /items/items.php - View products
  • GET /items/search.php - Search products

Cart

  • POST /cart/add.php - Add product to cart
  • GET /cart/view.php - View cart contents
  • POST /cart/delete.php - Remove product from cart
  • GET /cart/getcountitems.php - Get cart items count

Orders

  • POST /orders/checkout.php - Create new order
  • GET /orders/pending.php - View pending orders
  • GET /orders/archive.php - View archived orders
  • GET /orders/details.php - Order details
  • POST /orders/delete.php - Delete order

Favorites

  • POST /favorite/add.php - Add product to favorites
  • GET /favorite/view.php - View favorite products
  • POST /favorite/remove.php - Remove from favorites
  • POST /favorite/deletefromfavroite.php - Remove from favorites (alternative)

Addresses

  • POST /address/add.php - Add address
  • GET /address/view.php - View addresses
  • POST /address/edit.php - Edit address
  • POST /address/delete.php - Delete address

Coupons

  • POST /coupon/checkcoupon.php - Validate coupon

🔧 Helper Functions (functions.php)

The project includes ready-to-use helper functions:

  • filterRequest() - Sanitize input data
  • getAllData() - Fetch all data from a table
  • getData() - Fetch single record from a table
  • insertData() - Insert new data
  • updateData() - Update data
  • deleteData() - Delete data
  • imageUpload() - Upload images
  • deleteFile() - Delete files
  • checkAuthenticate() - Authentication check
  • printSuccess() - Print success message
  • printFailure() - Print failure message

📱 Usage with Flutter

All endpoints return JSON responses in a standardized format:

Success:

{
  "status": "success",
  "data": {...}
}

Failure:

{
  "status": "failure"
}

🔒 Security

  • ⚠️ Important: Do not upload connect.php file to GitHub as it contains sensitive information
  • Use .gitignore to protect sensitive files
  • Use HTTPS in production
  • Enable checkAuthenticate() in admin files

📝 Notes

  • All responses are in JSON format
  • Database uses UTF-8 encoding
  • Uploaded images are limited to 2MB
  • Uploaded images are saved in the upload/ folder

👨‍💻 Developer

This project was developed as part of an Ecommerce course.

📄 License

This project is for educational purposes.


Note: Make sure to update database credentials in connect.php before use.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages