Backend service for an e-commerce platform using Golang and PostgreSQL. It provides APIs for user authentication, product management, cart functionality, and order processing.
- Modular Architecture: Clean and scalable codebase for easy maintenance.
- Authentication: Secure user authentication with JWT and password hashing.
- Products: Get, create and update products.
- Cart: Get and create orders with multiple products and secure validation.
- Database Migrations: Easy setup and migration of database schemas.
- Automated Testing: Easy-to-run tests for ensuring code reliability, using Go's built-in testing framework.
- Makefile Automation: Simplified commands for building, running, testing, and managing migrations.
bin/ - Compiled binaries
cmd/ - Main application entry points
config/ - Configuration files
services/ - Business logic and API handlers
types/ - Shared data types
utils/ - Utility functions
-
Clone this repository:
git clone https://github.com/matimortari/go-ecom-backend .
-
Install dependencies:
go mod tidy
-
Create a
.env
file in the project root with the following environment variables (modify as needed):# Server configuration PUBLIC_HOST=http://localhost/ PORT=8080 # PostgreSQL database configuration DB_USER=postgres DB_PASSWORD=postgres DB_HOST=localhost DB_PORT=5432 DB_NAME=ecom
-
Use the
Makefile
to automate common tasks.
-
Build the application to a binary at
bin/ecom
:make build
-
Run the compiled binary:
make run
-
Run tests:
make test
-
Create a new migration file at
cmd/migrate/migrations
:make migration-create name=<migration_name>
-
Run migrations "up" to apply all pending migrations:
make migrate-up
-
Run migrations "down" to roll back the last applied migration:
make migrate-down
-
Check migration status and version:
make migrate-status
Feel free to reach out to discuss collaboration opportunities or to say hello!