Skip to content

Projects · Open source · 2025

Trendstore API

E-commerce backend in Go with a layered domain / application / infrastructure structure, SQL migrations, repository interfaces with generated mocks, and a documented REST API for products, categories, cart, checkout and admin.

Go · PostgreSQL · golang-migrate

Source

Problem

A practice ground for the layering questions that come up in every backend codebase: where business rules live, how handlers stay thin, and how to keep the database replaceable in tests.

What I built

A REST API for a fashion store: auth with roles, products and categories, cart, checkout and orders, plus an admin surface. Each domain has an entity and a repository interface; application services hold the use cases; HTTP handlers and Postgres repositories live in infrastructure.

Architecture

  • internal/domainentities and repository interfaces, no framework imports
  • internal/applicationuse-case services with DTOs and mappers
  • internal/infrastructure/httphandlers per aggregate, thin, map errors to a shared response envelope
  • internal/infrastructure/persistencePostgres repositories
  • db/migrationversioned up/down SQL migrations
  • test/mocksrepository mocks for service tests

Decisions and trade-offs

  1. 01

    Dependency direction points inward

    Domain packages import nothing from HTTP or SQL. The cost is some mapping code between DTOs, entities and rows; the benefit is that use cases can be tested with the repository mocks in `test/mocks` and the database can change without touching business rules.

  2. 02

    Migrations as versioned SQL, not ORM auto-sync

    Four numbered up/down migrations (schema, categories, timestamps, product–category linking) make the schema history explicit and reversible, which matters more than convenience once data exists.

  3. 03

    One response envelope

    All handlers return the same shape from `pkg/response`, so clients and admin tooling parse one format and error handling is consistent across endpoints.

Evidence

  • 32 commits; README documents every endpoint group (admin, auth, user, product, cart, checkout, order).
  • Repository interfaces have mocks in `test/mocks`, used by service tests.
  • `project-structure.md` records the layering rules.

Status · Feature-complete for the documented API; no load testing yet