https://github.com/codisim/ecommerce
A fully functional e-commerce backend built with Golang, PostgreSQL, and JWT authentication.
https://github.com/codisim/ecommerce
golang jwt-authentication postgresql
Last synced: 5 days ago
JSON representation
A fully functional e-commerce backend built with Golang, PostgreSQL, and JWT authentication.
- Host: GitHub
- URL: https://github.com/codisim/ecommerce
- Owner: codisim
- Created: 2025-09-18T00:25:07.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2026-04-14T08:44:37.000Z (3 months ago)
- Last Synced: 2026-04-14T10:26:50.279Z (3 months ago)
- Topics: golang, jwt-authentication, postgresql
- Language: Go
- Homepage:
- Size: 138 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# 🛍️ GoCommerce — E-commerce Backend API (Go + PostgreSQL)
A fully functional **e-commerce backend** built with **Golang**, **PostgreSQL**, and **JWT authentication**.
This project is designed to power a modern e-commerce platform with features like product management, user authentication, and order handling.
---
## 🚀 Tech Stack
- **Language:** Go (Golang)
- **Database:** PostgreSQL
- **Query:** `database/sql` + `pgx` driver
- **Authentication:** JWT (JSON Web Token)
- **Password Hashing:** bcrypt
- **API Format:** RESTful JSON
- **Architecture:** Domain-driven design
- **Environment Management:** `.env` file
- **Dependency Management:** Go Modules
---
## 🗂️ Project Structure
---
## 🔗 API Endpoints
### 👤 **Auth Routes**
| Method | Endpoint | Description |
|--------|-----------|-------------|
| `POST` | `/api/auth/register` | Register a new user |
| `POST` | `/api/auth/login` | Login user and receive JWT token |
---
### 🛒 **Product Routes**
| Method | Endpoint | Description | Access |
|--------|-----------|-------------|--------|
| `GET` | `/api/products` | Get all products | Public |
| `GET` | `/api/products/:id` | Get product by ID | Public |
| `POST` | `/api/products` | Create product | Admin |
| `PUT` | `/api/products/:id` | Update product | Admin |
| `DELETE` | `/api/products/:id` | Delete product | Admin |
---
### 📦 **Order Routes**
| Method | Endpoint | Description | Access |
|--------|-----------|-------------|--------|
| `GET` | `/api/orders` | Get all orders (Admin) | Admin |
| `POST` | `/api/orders` | Create a new order | Authenticated User |
| `GET` | `/api/orders/:id` | Get order details | Authenticated User |
| `PUT` | `/api/orders/:id` | Update order status | Admin |
---
### 🧑💼 **Admin Routes**
| Method | Endpoint | Description | Access |
|--------|-----------|-------------|--------|
| `GET` | `/api/admin/dashboard` | Get summary stats (users, sales, orders) | Admin |
| `GET` | `/api/admin/users` | Get all registered users | Admin |
| `PUT` | `/api/admin/users/:id/role` | Update user role | Admin |
---
## ⚙️ Environment Variables
Create a `.env` file in your root directory:
```bash
# PostgreSQL
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=yourpassword
DB_NAME=gocommerce
# JWT
JWT_SECRET=your_jwt_secret_key
JWT_EXPIRE_HOURS=24
# Server
PORT=8080