Skip to content

E-commerce backend built with Go, Gin, and GORM. Features JWT authentication, product & order management, and Swagger API docs. πŸš€

Notifications You must be signed in to change notification settings

telman03/ecom-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

E-commerce Backend (Go + Gin + GORM)

This is a fully functional E-commerce Backend built using Go, Gin, and GORM. It includes authentication, product management, order management, and a review & ratings system.

swagger

πŸš€ Features

  • User Authentication (JWT-based)
  • Product Management (CRUD operations)
  • Cart & Orders (Add to cart, checkout, track orders)
  • Swagger API Documentation
  • Secure with Middleware (Auth & Role-based Access Control)

πŸ›  Tech Stack

  • Backend: Go (Gin framework)
  • Database: PostgreSQL (GORM ORM)
  • Authentication: JWT (JSON Web Tokens)
  • API Documentation: Swagger

πŸ“Œ Installation & Setup

1️⃣ Clone the Repository

git clone https://github.com/telman/ecom-go.git
cd ecom

2️⃣ Install Dependencies

go mod tidy

3️⃣ Setup Environment Variables

Create a .env file and add:

DB_HOST=localhost
DB_USER=youruser
DB_PASSWORD=yourpassword
DB_NAME=ecom_db
DB_PORT=5432
JWT_SECRET=your_secret_key

4️⃣ Run Migrations

go run main.go migrate

5️⃣ Start the Server

go run main.go

Server will run on http://localhost:8080


πŸ“– API Documentation (Swagger)

Swagger UI is available at:

http://localhost:8080/swagger/index.html

To regenerate Swagger docs, run:

swag init

πŸ”₯ API Endpoints

Auth Routes

Method Endpoint Description
POST /auth/register Register a new user
POST /auth/login Login user and get JWT
GET /user/profile Get user profile

Product Routes

Method Endpoint Description
POST /products/add Add a new product (Admin)
GET /products Get all products
GET /products/:id Get product details
PUT /products/:id Update product (Admin)
DELETE /products/:id Delete product (Admin)

Order & Cart Routes

Method Endpoint Description
POST /cart/add Add product to cart
GET /cart View cart items
POST /orders/place Place an order
GET /orders Get user orders
PATCH /orders/:id/status Update order status (Admin)

πŸ“‚ Project Structure

/ecom-backend
│── controllers/    # API handlers
│── middleware/     # JWT authentication middleware
│── models/         # Database models (GORM)
│── routes/         # API route definitions
│── db/             # Database connection
│── main.go         # Entry point
│── go.mod          # Go module file
│── swagger.json    # API documentation

πŸ”₯ Contributing

Feel free to fork and contribute! Open an issue or submit a PR.


πŸ“œ License

This project is licensed under the MIT License.


Happy Coding! πŸš€

About

E-commerce backend built with Go, Gin, and GORM. Features JWT authentication, product & order management, and Swagger API docs. πŸš€

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages