# zmskv/sales-app architecture

> Architecture diagram of the GitHub repository zmskv/sales-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zmskv/sales-app
- Repository: https://github.com/zmskv/sales-app

## Overview

##### Main Components
- Entry Point: The application starts at cmd/main.go. This is where the server is initialized.
- Configuration: The internal/config directory holds config.go, indicating centralized configuration management.
- Handlers/Controllers: The internal/handler folder contains various endpoint handlers (app.go, auth.go, sales.go, user.go, etc.). These handle incoming HTTP requests.
- Business Logic/Services: The internal/service directory contains service.go, sales.go, and user.go, representing the business logic for processing requests.
- Data Models: The internal/model folder stores model definitions for products and users.
- Data Access/Repository: The internal/repository directory (with files like postgres.go, repository.go, and sales & user repositories) interfaces with the underlying database.
- Persistence: Migrations and the PostgreSQL-specific files in the repository suggest that there is a PostgreSQL database managing persistent data.
- API Documentation: The docs folder with swagger.json, swagger.yaml, and docs.go signifies the API is self-documented (via Swagger).
- Deployment: Files like Dockerfile, docker-compose.yaml, and the Makefile are used for building, containerizing, and running the microservice.

##### Out the Interactions and Flow
- Client & API Requests: Start with the external client sending HTTP requests (e.g., for generating a sales report). Explicitly indicate that Swagger is used to document these endpoints.
- API Handler Layer: Show that the HTTP request is first received by the Handler layer (with auth, sales, and user-related handlers) responsible for validating and routing requests.
- Service Layer: The business logic will process, transform the request, perform auth checks if any, and call the relevant service functions.
- Deployment & Containerization: Optionally, include a boundary for Docker showing that the whole microservice is containerized and orchestrated (via docker-compose).

##### Architectural Patterns and Technical Stack
- Layered Architecture: Illustrate the clear separation between the HTTP/API layer, the business logic (Service layer), and the data access (Repository).
- Microservices: Even though this microservice is self-contained, note that it is designed to integrate into a larger sales application ecosystem.
- Tools & Technologies: Highlight Golang as the core language, PostgreSQL as the database (as seen from postgres.go), Docker for deployment, and Swagger for API documentation.
- Development Utilities: Include a note regarding the Makefile which simplifies running, building, and migrating the service.

- Supplementary documentation layer (Swagger) and the deployment container (Docker) outside or around the main components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["External Client"]:::external
    Swagger["API Documentation (Swagger)"]:::external
    Database["Database (PostgreSQL)"]:::database

    subgraph "Sales Report Microservice (Docker Container)"
        Entry["Entry Point (cmd/main.go)"]:::internal
        Config["Configuration (internal/config/config.go)"]:::internal
        Handlers["API Handlers (internal/handler)"]:::internal
        Services["Business Logic (internal/service)"]:::internal
        Repository["Data Access (internal/repository)"]:::internal
        Models["Data Models (internal/model)"]:::internal
    end

    subgraph "Deployment & Persistence"
        Dockerfile["Dockerfile"]:::deployment
        DockerCompose["docker-compose.yaml"]:::deployment
        Makefile["Makefile"]:::deployment
        Migrations["Migrations (migrations)"]:::deployment
    end

    Client -->|"HTTPRequest"| Entry
    Entry -->|"LoadConfig"| Config
    Config -->|"InitHandlers"| Handlers
    Handlers -->|"RouteRequest"| Services
    Services -->|"BusinessLogic"| Repository
    Repository -->|"DataOps"| Database
    Database -->|"SchemaUpdates"| Migrations

    Swagger -->|"APIReference"| Handlers

    Dockerfile -->|"Deploys"| Entry
    DockerCompose -->|"Orchestrates"| Entry
    Makefile -->|"Utilizes"| Entry

    click Entry "https://github.com/zmskv/sales-app/blob/main/cmd/main.go"
    click Config "https://github.com/zmskv/sales-app/blob/main/internal/config/config.go"
    click Handlers "https://github.com/zmskv/sales-app/tree/main/internal/handler"
    click Services "https://github.com/zmskv/sales-app/tree/main/internal/service"
    click Models "https://github.com/zmskv/sales-app/tree/main/internal/model"
    click Repository "https://github.com/zmskv/sales-app/tree/main/internal/repository"
    click Swagger "https://github.com/zmskv/sales-app/tree/main/docs"
    click Dockerfile "https://github.com/zmskv/sales-app/tree/main/Dockerfile"
    click DockerCompose "https://github.com/zmskv/sales-app/blob/main/docker-compose.yaml"
    click Makefile "https://github.com/zmskv/sales-app/tree/main/Makefile"
    click Migrations "https://github.com/zmskv/sales-app/tree/main/migrations"

    classDef external fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef internal fill:#87CEEB,stroke:#4682B4,stroke-width:2px;
    classDef database fill:#C0C0C0,stroke:#808080,stroke-width:2px;
    classDef deployment fill:#90EE90,stroke:#32CD32,stroke-width:2px;
```
