How restuwahyu13/golang-pos works
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: handler.user.go Resource handlers · service.user.go Business services · route.user.go Versioned API routes · middleware.auth.go Auth and role middleware
Components 16
HTTP API
- Versioned API routes · Registers /api/v1 authentication and POS resource endpoints.
routes/route.user.go - Auth and role middleware · Protects routes and enforces roles.
middlewares/middleware.auth.go - Resource handlers · Maps requests to application services.
handlers/handler.user.go - Request/response DTOs · Separates API payloads from persistence entities.
schemes/schema.request.go - JSON response helpers
helpers/helper.response.go - Payload validation
pkg/pkg.validator.go - Token extraction
helpers/helper.extractToken.go
Application Core
- Business services · Principal boundary between transport and persistence.
services/service.user.go - JWT security · Creates and verifies authentication tokens.
pkg/pkg.jwt.go - Password hashing
pkg/pkg.bcrypt.go
Data & Domain
- Persistence repositories · Per-resource CRUD access through GORM.
repositories/repository.user.go - POS entities · Users, roles, merchant/outlet, catalog, customers, and transactions.
entities/entity.user.go - Database · Concrete database engine is not identified.
Platform
- Application entry · Starts the Gin API runtime.
main.go - Container deployment · Builds and runs the API container.
Dockerfile - Environment loader
pkg/pkg.dotenv.go
Connections 16
- 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