Skip to main content

Common Packages

To maintain consistency across Citadel's distributed architecture, we use shared packages for cross-cutting concerns like authentication, configuration, and caching.

Go Commons

The go-commons package is the foundational shared library for all Go-based microservices in the Citadel ecosystem. It mirrors the functionality of our NestJS shared libraries to ensure standardized behavior across languages.

Key Features

  • Standardized Configuration: A type-safe YAML loader that ensures all services follow the same configuration patterns.
  • Middleware Suite: A set of Gin middleware for:
    • Request Context: Extracting tracing and tenant headers.
    • Authentication: Supporting both TRUST_PROXY and ZERO_TRUST strategies.
    • Authorization: Role-based access control (RBAC) enforcement.
  • Caching & Locking: A Redis-backed cache implementation with support for distributed locking.
  • S2S Authentication: Secure server-to-server communication using identity provider admin tokens.

Location

citadel/packages/go-commons


Development Workflow

When adding functionality that is needed by multiple services (e.g., a new logging format or a shared metric), it should be implemented in the appropriate common package first.

  1. Modify the package in citadel/packages/.
  2. Run Tests for the package to ensure no regressions.
  3. Update the go.mod (for Go) or package.json (for TS) in the dependent services to use the new version.