CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/go-project-structure

Go project structure -- cmd/internal layout, handler/service/repository layers, Makefile, config from environment, domain error types, test placement, dependency injection

90

1.02x
Quality

84%

Does it follow best practices?

Impact

100%

1.02x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-2/

Build a Go REST API for Warehouse Inventory Management

Problem/Feature Description

A logistics company needs a REST API to manage warehouse inventory. The API tracks products, stock levels, and inventory movements (receiving stock, shipping out, adjustments). It uses PostgreSQL for storage and needs to be production-ready with proper error handling and configuration.

The team is experienced with Go but has been writing everything in a single main.go file. They want this new service to follow best practices for project organization.

Output Specification

Produce a complete project structure with:

  • go.mod with module path
  • cmd/api/main.go -- entry point with dependency wiring, HTTP server setup with timeouts, graceful shutdown with signal handling
  • internal/config/config.go -- Config struct with fields for PORT, DATABASE_URL, READ_TIMEOUT, WRITE_TIMEOUT loaded from environment with defaults
  • internal/domain/ -- Domain types: Product (ID, SKU, Name, Description, Category), StockLevel (ProductID, Warehouse, Quantity, UpdatedAt), InventoryMovement (ID, ProductID, Type [receive/ship/adjust], Quantity, Reason, CreatedAt), relevant request types
  • internal/domain/errors.go -- Error types with AppError base, NotFoundError, ValidationError, ConflictError (for duplicate SKUs)
  • internal/handler/ -- Handler struct with constructor, route registration (chi or mux), endpoints for products CRUD and stock operations, centralized writeJSON/writeError helpers, middleware (logging, recovery)
  • internal/service/ -- ProductService and InventoryService with business logic, define repository interfaces
  • internal/repository/ -- SQL implementations of repository interfaces
  • Makefile with build, run, test, test-coverage, lint, fmt, tidy, clean targets
  • .gitignore appropriate for Go
  • Test files alongside source: at least internal/service/inventory_test.go with table-driven tests for stock level validation (cannot go negative, etc.)

Focus on correct package separation and the dependency flow: handler -> service -> repository.

evals

tile.json