A RESTful ecommerce API built with Go, Gin, GORM, and PostgreSQL.
Warning
This project was partially vibe-coded. I have not reviewed all of the code, I cannot guarantee quality, use at your own risk.
See frontend/README.md for details about the frontend.
-
Authentication & Authorization
- JWT-based authentication
- User registration and login
- Role-based access control (admin/customer)
- OpenID Connect support
-
Product Management
- Product CRUD operations (admin)
- Product search and filtering
- Pagination support
- Price range filtering
- Sorting (by price, name, date)
- Stock/inventory management
-
Shopping Cart
- Add items to cart
- Update cart item quantities
- Remove items from cart
- View cart
-
Order Management
- Create orders
- View order history
- Order status tracking (PENDING, PAID, FAILED)
- Mock payment processing
- Admin order management
-
User Management
- User profiles
- Profile updates
- Admin user management
- Go 1.21 or higher
- Docker or Podman (for running Postgres database)
- Make
- FFmpeg (for media processing)
- NPM/Bun/Yarn/PNPM (for frontend)
-
Clone the repository
git clone https://git.colormatic.org/ColormaticStudios/ecommerce.git cd ecommerce -
Install dependencies
go mod download
-
Set up environment variables
cp .env.example .env # Edit .env with your configuration -
Run a temporary database
sudo scripts/run-dev-db-docker.sh # Or scripts/run-dev-db-podman.sh -
Start the backend
make run
Or build and run:
make api bin/ecommerce-api
-
Populate the database with placeholder products
scripts/populate-test-database.sh
-
Start the frontend
cd frontend bun install bun run dev --open
See .env.example for all required environment variables.
DATABASE_URL: PostgreSQL connection stringPORT: Server port (default: 3000)JWT_SECRET: Secret key for JWT token signingDISABLE_LOCAL_SIGN_IN: Disable local sign-in (default: false)OIDC_PROVIDER: OIDC provider URL (optional)OIDC_CLIENT_ID: OIDC client ID (optional)OIDC_CLIENT_SECRET: OIDC client secret (optional)OIDC_REDIRECT_URI: OIDC redirect URI (optional)DEV_MODE: Whether to allow connections from localhost (optional)PUBLIC_URL: What host to allow connections from in production
See API.md for documentation on the API.
The project includes a command-line tool for administrative tasks.
make cliSet a user as admin:
bin/ecommerce-cli user set-admin --email user@example.com
# or by username
bin/ecommerce-cli user set-admin --username johndoeCreate a new user:
bin/ecommerce-cli user create \
--email admin@example.com \
--username admin \
--password securepassword \
--name "Admin User" \
--role adminList all users:
bin/ecommerce-cli user list
# Filter by role
bin/ecommerce-cli user list --role adminDelete a user:
bin/ecommerce-cli user delete --email user@example.com
# Skip confirmation
bin/ecommerce-cli user delete --email user@example.com --yesCreate a product:
bin/ecommerce-cli product create \
--sku PROD-001 \
--name "Product Name" \
--description "Product description" \
--price 29.99 \
--stock 100List products:
bin/ecommerce-cli product list
# Limit results
bin/ecommerce-cli product list --limit 10Edit a product:
# Change stock to 20
bin/ecommerce-cli product edit \
--id 1 \
--stock 20
# Products can be identified by either ID or SKU
# Change SKU
bin/ecommerce-cli product edit \
--sku PROD-001 \
--new-sku PROD-002Set related products:
bin/ecommerce-cli product related-set --id 1 --related-id 2,3,4
# or by SKU
bin/ecommerce-cli product related-set --sku PROD-001 --related-sku PROD-002 --related-sku PROD-003Upload media and attach to a product:
bin/ecommerce-cli product media-upload \
--id 1 \
--file ./path/to/image.jpg \
--api-base http://localhost:3000 \
--token <admin-jwt>Delete a product:
bin/ecommerce-cli product delete --id 1
# or by SKU
bin/ecommerce-cli product delete --sku PROD-001Get help for any command:
bin/ecommerce-cli --help
bin/ecommerce-cli user --help
bin/ecommerce-cli user set-admin --help# Run all tests
make testThe test suite includes:
- Authentication tests - JWT generation, password hashing, subject ID generation
- Validation tests - Currency validation, product validation, input validation
- Business logic tests - Order total calculation, stock validation, pagination
- Middleware tests - Auth middleware with various scenarios (valid/invalid tokens, role requirements, expired tokens)
API Server:
go build -o bin/ecommerce-api -ldflags="-s -w" main.goCLI Tool:
go build -o bin/ecommerce-cli -ldflags="-s -w" ./cmd/cliMigrations are handled automatically by GORM on server start.

