Skip to main content

pkg — Shared Utility Libraries

Under Reviewv0.1.0-alpha

The pkg/ directory contains framework-agnostic, reusable Go packages that provide cross-cutting infrastructure to the rest of the application. These packages have no knowledge of domain logic and can be imported by any layer (internal/core, internal/gateway, adapters, etc.) without creating circular dependencies.


Package Index

PackagePurposeKey Exports
ctxkeysType-safe context key constantsUserIDKey, UserRoleKey, CorrelationIDKey
errorsDomain-aware HTTP error typeAppError, NewBadRequest, NewInternal, …
idgenCryptographically secure UUIDv7 ID generationGenerate, MustGenerate, ToUUID, FromUUID
loggerStructured logging with OTel trace correlationLogger, NewLogger, ECSHandler, context-aware methods
responseJSON API envelope + RFC 7807 Problem DetailsAPIResponse, ProblemDetail, GinOK, GinWriteError
telemetryOpenTelemetry tracing bootstrapConfig, ReadConfigFromEnv, Init
tokenInternal HMAC token manager + OIDC validatorJWTManager, OIDCValidator
validatorInput validation helpersValidateStruct, ValidateEmail, ValidatePassword
dbDatabase connection interface and adaptersConnection, SQLConnection, MongoConnection
metricsPrometheus metrics registrationHTTP metrics, DB pool collector, cache metrics

Design Principles

  1. No domain imports — packages under pkg/ never import from internal/core or internal/infra (with the exception of metrics, which references an infra interface for pool stats — see the metrics doc for details).
  2. Minimal coupling — each package is independently importable with no hard dependencies on sibling packages.
  3. Env-driven config — runtime behaviour (log format, telemetry sampling, etc.) is controlled via environment variables.
  4. OTel-first observability — logging and response writing integrate natively with OpenTelemetry trace context, attaching trace_id and span_id to every log record and error response automatically.