Coolshop API is a RESTful API built with Golang, Gin, PostgreSQL, Redis, and JWT authentication.
It provides user authentication, session management, and user data operations for an e-commerce system.
✅ User Authentication - Sign up, login, logout, password update
✅ JWT-based Authorization - Secure API using access & refresh tokens
✅ Role-based Access Control - Protected API endpoints
✅ Swagger API Documentation - Interactive API docs
✅ Structured Logging - Powered by Uber's zap
✅ Error Handling Middleware - Centralized error handling
✅ Dockerized Setup - Easy deployment
If you don't have Go installed, download and install it:
- Go: Install Go
Verify installation:
go version
Install swag
globally:
go install github.com/swaggo/swag/cmd/swag@latest
Verify installation:
swag --version
- Docker: Install Docker
- Docker Compose: Install Docker Compose
Coolshop API provides interactive API documentation via Swagger.
📌 Access Swagger Docs after running the server:
📞 http://localhost:8080/swagger/index.html
To regenerate Swagger docs:
swag init -g cmd/main.go
git clone https://github.com/kemalkochekov/CoolShop.git
cd CoolShop
go mod tidy
docker-compose up
📦 Coolshop
┣ 📂 cmd # Main entry point
┃ ┗ 📜 main.go # Starts the API server
┣ 📂 internal
┃ ┣ 📂 app # App initialization & routes
┃ ┣ 📂 auth # JWT authentication & middleware
┃ ┣ 📂 cache # Redis caching
┃ ┣ 📂 config # App configuration
┃ ┣ 📂 connection # Database & Redis connections
┃ ┣ 📂 migrations # Database migrations
┃ ┣ 📂 model # Data models
┃ ┣ 📂 user # User business logic (handlers, repository, usecase)
┣ 📂 logger # Logging with Uber Zap
┣ 📂 middleware # Custom middlewares (logging, error handling)
┣ 📂 pkg # Utility packages (errors, constants, request validation)
┣ 📂 docs # Swagger API documentation
┣ 📂 tmp # Temporary files
┣ 📜 docker-compose.yml # Docker configuration
┣ 📜 Makefile # Task automation
┣ 📜 go.mod # Go module dependencies
┗ 📜 README.md # Project documentation
---
## 🏠 Tech Stack
- **Language:** [Golang](https://go.dev/)
- **Framework:** [Gin](https://github.com/gin-gonic/gin)
- **Database:** [PostgreSQL](https://www.postgresql.org/)
- **Caching:** [Redis](https://redis.io/)
- **Authentication:** JWT (JSON Web Token)
- **Logging:** [Uber Zap](https://github.com/uber-go/zap)
- **API Docs:** [Swagger](https://swagger.io/)
---
## 🔒 Authentication & Authorization
### **🔑 Access Token (JWT)**
- Used for **authenticated requests**
- Sent in the `Authorization` header:
```http
Authorization: YOUR_ACCESS_TOKEN
- Stored in cookies
- Used to refresh the access token when it expires.
Run the project using Docker:
docker-compose up --build
Stops and removes all containers:
docker-compose down
Method | Endpoint | Description | Auth Required |
---|---|---|---|
POST |
/auth/sign_up |
User registration | ❌ No |
POST |
/auth/login |
User login (returns JWT) | ❌ No |
POST |
/auth/refresh |
Refresh access token | ✅ Yes |
Method | Endpoint | Description | Auth Required |
---|---|---|---|
GET |
/user/{id} |
Get user by ID | ✅ Yes |
PUT |
/user/update_password |
Update password | ✅ Yes |
DELETE |
/user/ |
Delete user account | ✅ Yes |
POST |
/user/logout |
Logout user | ✅ Yes |
Method | Endpoint | Description |
---|---|---|
GET |
/health |
API health check |
🚀 We welcome contributions!
To contribute:
- Fork the repository.
- Create a new branch:
git checkout -b feature-new
- Make your changes & commit:
git commit -m "Add new feature"
- Push the branch:
git push origin feature-new
- Submit a Pull Request 🚀
If you find this project useful, give it a star ⭐ on GitHub!