This repository contains the backend for a mini online shop website. It handles user authentication, product management, shopping cart functionality, order processing, and payment integration.
- User Authentication: Login and registration functionality.
- Product Management: List and manage products.
- Shopping Cart: Add, update, and remove items in the cart.
- Order Processing: Place and manage orders (only buyer).
- Payment Integration: Handle payment processing (dummy).
- Language: Go
- Framework: Fiber
- Database: PostgreSQL, Redis
- GoFiber (HTTP Framework): An Express-inspired web framework for Go.
- GORM (ORM): The fantastic ORM library for Go.
- Viper (Configuration): A complete configuration solution for Go applications.
- Golang Migrate (Database Migration): Database migrations for Golang.
- Go Playground Validator (Validation): A Go library for struct and field validation.
Here is the ERD for the database schema:
.
├── cmd # Entry point of the application
│ └── core
├── db # Database migrations
│ └── migrations
└── internal
├── config # Application configs
├── delivery
│ └── http
│ ├── controller # Route handlers
│ ├── middleware # Custom middlewares
│ └── route # Application routes
├── domain # Delivery models
├── model # Database models
├── repository # Database logic
├── usecase # Business logic
└── utils # Utility functions and helpers
- Go 1.20+
- PostgreSQL
- Redis
Connect to your PostgreSQL server, create the database, and do migration.
# Create the database
createdb db_mini_online_shop
# Apply migrations
migrate -path db/migrations -database postgres://[username]:[password]@localhost:5432/db_mini_online_shop?sslmode=disable up
Clone the repository:
git clone [email protected]:pravastacaraka/go-mini-online-shop-ws.git
cd go-mini-online-shop-ws
Install dependencies:
go mod vendor && go mod tidy
- Open
config.local.json
file to configure the app config. - Change the database dan redis credentials according to your previous setting via environment variables look at the
.env.example
file.
go run cmd/core/main.go
Having trouble running manually in local? You can directly use the docker that I have provided.
- Docker
# build the image
docker compose build
# start the app
docker compose up
# stop the app gracefully
docker compose down
You can see the API documentation on here Postman Collection.