# restuwahyu13/golang-pos architecture

> Architecture diagram of the GitHub repository restuwahyu13/golang-pos, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/restuwahyu13/golang-pos
- Repository: https://github.com/restuwahyu13/golang-pos

## Overview

#### Purpose and runtime
This is a Go REST API backend for a point-of-sale domain, built with Gin and GORM. It exposes versioned `/api/v1` HTTP endpoints for authentication and POS resources. The application entry point is `main.go`; it runs directly with Go or as a container through `Dockerfile` and `docker-compose.yml`.

#### Application composition
The API is organized as a layered CRUD-oriented service:
- HTTP route registration: `routes/route.user.go`, `routes/route.transaction.go`
- Request handlers: `handlers/handler.user.go`, `handlers/handler.transaction.go`
- Business-service layer: `services/service.user.go`, `services/service.transaction.go`
- Persistence repositories: `repositories/repository.user.go`, `repositories/repository.transaction.go`

This separation is repeated for each core resource, making the service layer the principal boundary between transport logic and database access.

#### POS domain model
The domain covers identity/access and POS master/operational data:
- Users and roles: `entities/entity.user.go`, `entities/entity.role.go`
- Merchant and outlet hierarchy: `entities/entity.merchant.go`, `entities/entity.outlet.go`
- Catalog and supply relationships: `entities/entity.product.go`, `entities/entity.supplier.go`
- Customers and sales transactions: `entities/entity.customer.go`, `entities/entity.transaksi.go`

GORM-facing entity definitions are separated from request/response schemas, keeping persistence representation distinct from API contracts.

#### HTTP/API flow
A typical protected request flows from a resource-specific route to middleware, handler, service, and repository, then returns through shared JSON/response helpers. Routes expose create, list, detail, update, and delete operations for merchants, outlets, customers, products, roles, suppliers, and transactions. Authentication endpoints handle registration and login through `routes/route.user.go` and `handlers/handler.user.go`.

#### Security and authorization boundary
Authentication and role enforcement are middleware concerns:
- `middlewares/middleware.auth.go`
- `middlewares/middleware.role.go`
- `helpers/helper.extractToken.go`

JWT creation/verification is centralized in `pkg/pkg.jwt.go`; password hashing is centralized in `pkg/pkg.bcrypt.go`. This makes handlers/services consumers of authenticated identity rather than token-parsing owners.

#### Contract validation and responses
Request and response DTOs live under `schemes`, including authentication/user and POS-resource payloads: `schemes/schema.request.go`, `schemes/schema.response.go`, `schemes/schema.transaction.go`. Validation is provided through `pkg/pkg.validator.go`; handlers use shared response and JSON utilities in `helpers/helper.response.go` and `helpers/helper.json.go`.

#### Infrastructure and external dependencies
Gin is the HTTP runtime and GORM is the ORM/database integration. Environment loading is encapsulated in `pkg/pkg.dotenv.go`, with expected settings represented by `.env.example`. Containerized deployment is supported by `Dockerfile` and `docker-compose.yml`; the repository does not identify the concrete database engine or hosted external services.

Main entry points: [`handlers/handler.user.go`](https://github.com/restuwahyu13/golang-pos/blob/main/handlers/handler.user.go) (Resource handlers), [`services/service.user.go`](https://github.com/restuwahyu13/golang-pos/blob/main/services/service.user.go) (Business services), [`routes/route.user.go`](https://github.com/restuwahyu13/golang-pos/blob/main/routes/route.user.go) (Versioned API routes), [`middlewares/middleware.auth.go`](https://github.com/restuwahyu13/golang-pos/blob/main/middlewares/middleware.auth.go) (Auth and role middleware)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_routes["Versioned API routes<br/>Gin routes<br/>[route.user.go]"]
  node_auth_middleware["Auth and role middleware<br/>Gin middleware<br/>[middleware.auth.go]"]
  node_handlers["Resource handlers<br/>HTTP handlers<br/>[handler.user.go]"]
  node_contracts["Request/response DTOs<br/>API schemas<br/>[schema.request.go]"]
  node_responses["JSON response helpers<br/>HTTP utilities<br/>[helper.response.go]"]
  node_validator["Payload validation<br/>[pkg.validator.go]"]
  node_token_extractor["Token extraction<br/>security helper"]
end

subgraph group_core["Application Core"]
  node_services["Business services<br/>service layer<br/>[service.user.go]"]
  node_jwt["JWT security<br/>token utility<br/>[pkg.jwt.go]"]
  node_bcrypt["Password hashing<br/>security utility<br/>[pkg.bcrypt.go]"]
end

subgraph group_data["Data &amp; Domain"]
  node_repositories["Persistence repositories<br/>repository layer<br/>[repository.user.go]"]
  node_entities["POS entities<br/>GORM models<br/>[entity.user.go]"]
  node_database[("Database<br/>external datastore")]
end

subgraph group_platform["Platform"]
  node_entry["Application entry<br/>Go bootstrap<br/>[main.go]"]
  node_deployment["Container deployment<br/>Docker"]
  node_environment["Environment loader<br/>configuration<br/>[pkg.dotenv.go]"]
end

node_deployment -->|"runs"| node_entry
node_environment -.->|"configures"| node_entry
node_entry -->|"initializes"| node_routes
node_routes -->|"protects endpoints with"| node_auth_middleware
node_routes -->|"dispatches to"| node_handlers
node_auth_middleware -->|"extracts token via"| node_token_extractor
node_auth_middleware -->|"verifies"| node_jwt
node_handlers -->|"validates"| node_validator
node_handlers -->|"binds DTOs"| node_contracts
node_handlers -->|"invokes"| node_services
node_handlers -->|"returns JSON through"| node_responses
node_services -->|"uses"| node_repositories
node_services -->|"hashes passwords with"| node_bcrypt
node_services -->|"issues tokens with"| node_jwt
node_repositories -->|"persists"| node_entities
node_repositories -->|"accesses via GORM"| node_database

click node_entry "https://github.com/restuwahyu13/golang-pos/blob/main/main.go"
click node_deployment "https://github.com/restuwahyu13/golang-pos/blob/main/Dockerfile"
click node_environment "https://github.com/restuwahyu13/golang-pos/blob/main/pkg/pkg.dotenv.go"
click node_routes "https://github.com/restuwahyu13/golang-pos/blob/main/routes/route.user.go"
click node_auth_middleware "https://github.com/restuwahyu13/golang-pos/blob/main/middlewares/middleware.auth.go"
click node_handlers "https://github.com/restuwahyu13/golang-pos/blob/main/handlers/handler.user.go"
click node_contracts "https://github.com/restuwahyu13/golang-pos/blob/main/schemes/schema.request.go"
click node_responses "https://github.com/restuwahyu13/golang-pos/blob/main/helpers/helper.response.go"
click node_validator "https://github.com/restuwahyu13/golang-pos/blob/main/pkg/pkg.validator.go"
click node_services "https://github.com/restuwahyu13/golang-pos/blob/main/services/service.user.go"
click node_repositories "https://github.com/restuwahyu13/golang-pos/blob/main/repositories/repository.user.go"
click node_entities "https://github.com/restuwahyu13/golang-pos/blob/main/entities/entity.user.go"
click node_jwt "https://github.com/restuwahyu13/golang-pos/blob/main/pkg/pkg.jwt.go"
click node_bcrypt "https://github.com/restuwahyu13/golang-pos/blob/main/pkg/pkg.bcrypt.go"
click node_token_extractor "https://github.com/restuwahyu13/golang-pos/blob/main/helpers/helper.extractToken.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_routes,node_auth_middleware,node_handlers,node_contracts,node_responses,node_validator,node_token_extractor toneBlue
class node_services,node_jwt,node_bcrypt toneAmber
class node_repositories,node_entities,node_database toneMint
class node_entry,node_deployment,node_environment toneRose
```

## Components

### HTTP API

- [Versioned API routes](https://github.com/restuwahyu13/golang-pos/blob/main/routes/route.user.go): Gin routes · Registers /api/v1 authentication and POS resource endpoints. · `routes/route.user.go`
- [Auth and role middleware](https://github.com/restuwahyu13/golang-pos/blob/main/middlewares/middleware.auth.go): Gin middleware · Protects routes and enforces roles. · `middlewares/middleware.auth.go`
- [Resource handlers](https://github.com/restuwahyu13/golang-pos/blob/main/handlers/handler.user.go): HTTP handlers · Maps requests to application services. · `handlers/handler.user.go`
- [Request/response DTOs](https://github.com/restuwahyu13/golang-pos/blob/main/schemes/schema.request.go): API schemas · Separates API payloads from persistence entities. · `schemes/schema.request.go`
- [JSON response helpers](https://github.com/restuwahyu13/golang-pos/blob/main/helpers/helper.response.go): HTTP utilities · `helpers/helper.response.go`
- [Payload validation](https://github.com/restuwahyu13/golang-pos/blob/main/pkg/pkg.validator.go): validation · `pkg/pkg.validator.go`
- [Token extraction](https://github.com/restuwahyu13/golang-pos/blob/main/helpers/helper.extractToken.go): security helper · `helpers/helper.extractToken.go`

### Application Core

- [Business services](https://github.com/restuwahyu13/golang-pos/blob/main/services/service.user.go): service layer · Principal boundary between transport and persistence. · `services/service.user.go`
- [JWT security](https://github.com/restuwahyu13/golang-pos/blob/main/pkg/pkg.jwt.go): token utility · Creates and verifies authentication tokens. · `pkg/pkg.jwt.go`
- [Password hashing](https://github.com/restuwahyu13/golang-pos/blob/main/pkg/pkg.bcrypt.go): security utility · `pkg/pkg.bcrypt.go`

### Data & Domain

- [Persistence repositories](https://github.com/restuwahyu13/golang-pos/blob/main/repositories/repository.user.go): repository layer · Per-resource CRUD access through GORM. · `repositories/repository.user.go`
- [POS entities](https://github.com/restuwahyu13/golang-pos/blob/main/entities/entity.user.go): GORM models · Users, roles, merchant/outlet, catalog, customers, and transactions. · `entities/entity.user.go`
- **Database**: external datastore · Concrete database engine is not identified.

### Platform

- [Application entry](https://github.com/restuwahyu13/golang-pos/blob/main/main.go): Go bootstrap · Starts the Gin API runtime. · `main.go`
- [Container deployment](https://github.com/restuwahyu13/golang-pos/blob/main/Dockerfile): Docker · Builds and runs the API container. · `Dockerfile`
- [Environment loader](https://github.com/restuwahyu13/golang-pos/blob/main/pkg/pkg.dotenv.go): configuration · `pkg/pkg.dotenv.go`

## Connections

- Container deployment → Application entry: runs
- Environment loader → Application entry: configures
- Application entry → Versioned API routes: initializes
- Versioned API routes → Auth and role middleware: protects endpoints with
- Versioned API routes → Resource handlers: dispatches to
- Auth and role middleware → Token extraction: extracts token via
- Auth and role middleware → JWT security: verifies
- Resource handlers → Payload validation: validates
- Resource handlers → Request/response DTOs: binds DTOs
- Resource handlers → Business services: invokes
- Resource handlers → JSON response helpers: returns JSON through
- Business services → Persistence repositories: uses
- Business services → Password hashing: hashes passwords with
- Business services → JWT security: issues tokens with
- Persistence repositories → POS entities: persists
- Persistence repositories → Database: accesses via GORM
