How enclaverunner/shareddeps works
Project Type and Purpose
• This is a Go-based backend microservice exposing a REST API (Gin Gonic) with OpenAPI/Swagger support, a gRPC health-check endpoint, and an authentication/authorization subsystem. It leverages code generation (oapi-codegen for REST, protoc for gRPC), Viper for configuration, Zap for structured logging, and go-playground/validator for request validation.
File Structure Overview
• Top-level:
• main.go → Entry point; bootstraps the HTTP and gRPC servers
• openapi.yml → OpenAPI 3 spec
• health-check.proto → gRPC health-check definition
• config/ → Viper-based configuration loader
• api/ → Generated + custom Gin handlers
• client/ → Generated REST client from OpenAPI spec
• middleware/ → Gin middleware (authentication, authz, logging)
• auth/ → Core authZ/authN logic (policies, groups, utils)
• proto_gen/ → Generated gRPC code
• utils/ → Misc helpers (e.g., ptr.go)
• integration_test.go, auth/auth_test.go, config/config_test.go
• CI/CD & tooling: .github/workflows, Makefile, go.mod/go.sum, Nix flake, golangci.yml
Key README Insights
• HTTP server: Gin Gonic
• Configuration: Viper
• Logging: Zap
• Validation: go-playground/validator
Main Components
a. API Layer
• Gin engine
• Routes generated from openapi.yml (api/gen.go)
• Handlers in api/impl.go
b. Middleware Layer
• Authentication (middleware/authentication.go → uses auth/init.go, userGroups, resourceGroups)
• Authorization (middleware/authz.go → policies in auth/policies.go)
• Logging (middleware/zerolog.go → Zap)
c. Business Logic / Domain
• auth/*.go (groupManager, policies, utils)
• config module (config/config.go)
• utils module
d. External Interfaces
• OpenAPI Spec (openapi.yml) → oapi-codegen → client/ and api/
• gRPC Health-Check (health-check.proto → proto_gen/)
• (Optional) Data store or external identity provider – inject via config
e. Infrastructure & Tooling
• CI/CD pipelines (.github/workflows)
• Build tools (Makefile, tools.go, Nix flake)
Relationships & Data Flow
• Client Request → Gin Router
↳ passes through Authentication middleware
↳ if authenticated, passes through Authorization middleware
↳ then to Handler → Business Logic → (optional) Data Store / External API
↳ returns response up the chain
• Spec/Protos → Code generators → api/ and client/ + proto_gen/
• Health-Check Probe → gRPC Health-Check Server
Architectural Patterns & Principles
• Layered architecture: Presentation (HTTP/gRPC) → Cross-cutting concerns (middleware) → Domain
• Code-first / spec-driven development: OpenAPI + gRPC Proto → generate stubs/clients
• Dependency injection via config (Viper) for external resources