# ignfernandezmelipub/repo-w17-g3-bootcamp architecture

> Architecture diagram of the GitHub repository ignfernandezmelipub/repo-w17-g3-bootcamp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ignfernandezmelipub/repo-w17-g3-bootcamp
- Repository: https://github.com/ignfernandezmelipub/repo-w17-g3-bootcamp

## Overview

##### 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

## Diagram (Mermaid)

```mermaid
flowchart TB
    Client((Client)):::external
    Router["Router\ncmd/main.go"]:::router

    subgraph "Controller Layer"
        direction TB
        Handlers["Handlers\ninternal/handler"]:::controller
        DTOs["DTOs\ninternal/handler/dto"]:::controller
        HandlerUtils["Handler Utils\ninternal/handler/utils"]:::controller
    end

    subgraph "Service Layer"
        direction TB
        Services["Services\ninternal/service"]:::service
    end

    subgraph "Repository Layer"
        direction TB
        Repositories["Repositories\ninternal/repository/repositories"]:::repo
        SQLHelpers["SQL Helpers\ninternal/repository/sql_utils/helpers.go"]:::repo
        SQLQueries["SQL Queries\ninternal/repository/sql_utils/queries.go"]:::repo
    end

    Models["Models\npkg/models"]:::model

    subgraph Utilities
        direction TB
        Logger["Logger\ninternal/logger"]:::utils
        Errors["Custom Errors\npkg/custom_errors"]:::utils
    end

    DBInit["DB Init Scripts\ndocs/db/mysql-init.sql\nmysql-test-init.sql"]:::db
    Database[(MySQL DB)]:::db

    Client -->|HTTP Request| Router
    Router -->|routes to| Handlers
    Handlers -->|uses DTOs| DTOs
    Handlers -->|uses utils| HandlerUtils
    Handlers -->|calls| Services
    Services -->|calls| Repositories
    Repositories -->|uses| SQLHelpers
    Repositories -->|uses| SQLQueries
    Repositories -->|CRUD| Database
    DBInit -->|initializes| Database

    Services -->|uses| Models
    Repositories -->|uses| Models

    Router -->|logs & errors| Logger
    Handlers -->|logs & errors| Logger
    Services -->|logs & errors| Logger
    Repositories -->|logs & errors| Logger
    Router -->|errors| Errors
    Handlers -->|errors| Errors
    Services -->|errors| Errors
    Repositories -->|errors| Errors

    click Router "https://github.com/ignfernandezmelipub/repo-w17-g3-bootcamp/blob/main/cmd/main.go"
    click Handlers "https://github.com/ignfernandezmelipub/repo-w17-g3-bootcamp/tree/main/internal/handler"
    click DTOs "https://github.com/ignfernandezmelipub/repo-w17-g3-bootcamp/tree/main/internal/handler/dto"
    click HandlerUtils "https://github.com/ignfernandezmelipub/repo-w17-g3-bootcamp/tree/main/internal/handler/utils"
    click Services "https://github.com/ignfernandezmelipub/repo-w17-g3-bootcamp/tree/main/internal/service"
    click Repositories "https://github.com/ignfernandezmelipub/repo-w17-g3-bootcamp/tree/main/internal/repository/repositories"
    click SQLHelpers "https://github.com/ignfernandezmelipub/repo-w17-g3-bootcamp/blob/main/internal/repository/sql_utils/helpers.go"
    click SQLQueries "https://github.com/ignfernandezmelipub/repo-w17-g3-bootcamp/blob/main/internal/repository/sql_utils/queries.go"
    click DBInit "https://github.com/ignfernandezmelipub/repo-w17-g3-bootcamp/blob/main/docs/db/mysql-init.sql"
    click DBInit "https://github.com/ignfernandezmelipub/repo-w17-g3-bootcamp/blob/main/docs/db/mysql-test-init.sql"
    click Models "https://github.com/ignfernandezmelipub/repo-w17-g3-bootcamp/tree/main/pkg/models"
    click Logger "https://github.com/ignfernandezmelipub/repo-w17-g3-bootcamp/tree/main/internal/logger"
    click Errors "https://github.com/ignfernandezmelipub/repo-w17-g3-bootcamp/tree/main/pkg/custom_errors"

    classDef external fill:#f9f,stroke:#333,stroke-width:1px
    classDef router fill:#9f6,stroke:#333,stroke-width:1px
    classDef controller fill:#6cf,stroke:#333,stroke-width:1px
    classDef service fill:#36f,stroke:#333,stroke-width:1px
    classDef repo fill:#f90,stroke:#333,stroke-width:1px
    classDef db fill:#999,stroke:#333,stroke-width:1px
    classDef model fill:#ff9,stroke:#333,stroke-width:1px
    classDef utils fill:#fc0,stroke:#333,stroke-width:1px
```
