How ignfernandezmelipub/repo-w17-g3-bootcamp works
Project Type and Purpose
• This is a Go-based, HTTP microservice (monolith) implementing a warehouse management API.
• It follows a layered architecture: router → handler (controller) → service → repository → MySQL database, with shared models and utility packages.
Main Components
a. Router Layer (cmd/main.go)
• The HTTP router (e.g., net/http or chi/mux).
• Entry point for incoming client requests (docs/requests/*.http).
b. Controller Layer (internal/handler)
• Each handler corresponds to a resource: buyer, seller, product, sections, inbound_order, etc.
• Handlers parse requests (using dto structs), validate, call services, and return HTTP responses.
• Handler utils (internal/handler/utils) for error mapping and helpers.
c. Service Layer (internal/service)
• Business logic for each resource.
• Coordinates calls across multiple repositories if needed.
• Returns domain models or errors.
d. Repository Layer (internal/repository)
• CRUD operations against MySQL using SQL helpers (internal/repository/sql_utils).
• Separate packages per entity repository under repositories/*.
e. Database
• MySQL instance initialized by docs/db/mysql-init.sql.
f. Models (pkg/models)
• Domain entities shared between layers.
g. Utilities
• Logger (internal/logger) for structured logs.
• Custom errors (pkg/custom_errors) for uniform error handling.
• SQL helpers (internal/repository/sql_utils).
Relationships and Data Flow
• HTTP Client → Router → Controller → Service → Repository → MySQL DB
• Responses flow back up the same chain.
• Models flow from repositories to services/controllers.
• Utility packages (logger, custom_errors, sql_utils) are cross-cutting and used in each layer as needed.
Architectural Patterns and Design Principles
• Layered (Onion) architecture: each layer only depends on the one directly below it.
• Single responsibility per package: controllers handle HTTP concerns, services implement business rules, repositories manage persistence.
• DTOs isolate API schema from domain models.
• Dependency injection in main.go: wire router, handlers, services, repositories, and config.
Technologies and Frameworks
• Go modules (go.mod)
• net/http (or chi/mux) for routing
• MySQL for persistence
• Makefile for build/test
• Staticcheck CI via .github/workflows/staticcheck.yml
Essential Elements Checklist
• [ ] Router component with registered routes
• [ ] Controller/handler layer with resource-specific handlers
• [ ] Service layer per domain entity
• [ ] Repository layer per table/entity
• [ ] MySQL DB
• [ ] pkg/models entities
• [ ] Utilities: logger, custom_errors, sql_utils