{"id":50125714,"url":"https://github.com/papadanielvi/apadana","last_synced_at":"2026-06-08T20:01:10.570Z","repository":{"id":358692875,"uuid":"1241777724","full_name":"PapaDanielVi/apadana","owner":"PapaDanielVi","description":"Go SDK for building multi-tenant SaaS applications with tenant isolation, context propagation, and per-tenant config/metrics","archived":false,"fork":false,"pushed_at":"2026-05-18T16:22:48.000Z","size":79,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-18T17:39:01.463Z","etag":null,"topics":["context-propagation","go","go-middleware","go-sdk","golang","golang-sdk","grpc","http-middleware","metrics","middleware","multi-tenant","multi-tenant-saas","opentelemetry","prometheus","saas","sdk","tenant-isolation","tools"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/PapaDanielVi/apadana","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PapaDanielVi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-17T19:59:29.000Z","updated_at":"2026-05-18T16:22:53.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/PapaDanielVi/apadana","commit_stats":null,"previous_names":["papadanielvi/apadana"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/PapaDanielVi/apadana","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PapaDanielVi%2Fapadana","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PapaDanielVi%2Fapadana/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PapaDanielVi%2Fapadana/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PapaDanielVi%2Fapadana/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PapaDanielVi","download_url":"https://codeload.github.com/PapaDanielVi/apadana/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PapaDanielVi%2Fapadana/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33410345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-23T18:09:33.147Z","status":"ssl_error","status_checked_at":"2026-05-23T18:09:31.380Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["context-propagation","go","go-middleware","go-sdk","golang","golang-sdk","grpc","http-middleware","metrics","middleware","multi-tenant","multi-tenant-saas","opentelemetry","prometheus","saas","sdk","tenant-isolation","tools"],"created_at":"2026-05-23T20:00:24.489Z","updated_at":"2026-05-23T20:01:04.072Z","avatar_url":"https://github.com/PapaDanielVi.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Apadana: Multi-Tenant SDK for Go\n\n[![Test](https://github.com/PapaDanielVi/apadana/actions/workflows/test.yml/badge.svg)](https://github.com/PapaDanielVi/apadana/actions/workflows/test.yml)\n[![Lint](https://github.com/PapaDanielVi/apadana/actions/workflows/lint.yml/badge.svg)](https://github.com/PapaDanielVi/apadana/actions/workflows/lint.yml)\n[![Security](https://github.com/PapaDanielVi/apadana/actions/workflows/security.yml/badge.svg)](https://github.com/PapaDanielVi/apadana/actions/workflows/security.yml)\n[![Go Version](https://img.shields.io/github/go-mod/go-version/PapaDanielVi/apadana)](https://github.com/PapaDanielVi/apadana)\n[![License](https://img.shields.io/github/license/PapaDanielVi/apadana)](LICENSE)\n[![Go Report Card](https://goreportcard.com/badge/github.com/PapaDanielVi/apadana)](https://goreportcard.com/report/github.com/PapaDanielVi/apadana)\n[![GoDoc](https://pkg.go.dev/badge/github.com/PapaDanielVi/apadana)](https://pkg.go.dev/github.com/PapaDanielVi/apadana)\n\nA Go SDK providing building blocks for multi-tenant applications. Handles tenant identification, context propagation, per-tenant configuration, metrics, logging, and instrumentation across common infrastructure.\n\n## Features\n\n- **Tenant Isolation** — Extract, propagate, and inject tenant IDs across HTTP, gRPC, Kafka, NATS, and RabbitMQ\n- **SaaS-Ready** — Per-tenant configuration, singletons, timezones, and rate limiting out of the box\n- **Context Propagation** — Thread-safe tenant context with `context.Context` integration\n- **Multi-Tenant Middleware** — HTTP (standard lib \u0026 Echo) middlewares for header, query, subdomain, cookie, and JWT extraction\n- **Tenant Resolver Chain** — Chain-of-responsibility pattern for flexible tenant resolution\n- **Per-Tenant Infrastructure** — Kafka/NATS/RabbitMQ header injection\n- **Observability** — OpenTelemetry span processor, structured logging with `log/slog`\n- **Generic SDK Managers** — Type-safe `ConfigMgr[T]` and `SDKMgr[T,C]` for any multi-tenant resource\n- **YAML Config Expansion** — Merge default and per-tenant configs with `${tenant}` placeholder replacement\n- **gRPC Support** — Unary and stream interceptors for tenant metadata propagation\n\n## Installation\n\n```bash\ngo get github.com/PapaDanielVi/apadana\n```\n\n## Quick Start\n\n```go\npackage main\n\nimport (\n\t\"log/slog\"\n\t\"net/http\"\n\n\t\"github.com/PapaDanielVi/apadana/pkg/context\"\n\t\"github.com/PapaDanielVi/apadana/pkg/middleware\"\n)\n\nfunc main() {\n\thandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\ttenantID, _ := context.TenantIDFromContext(r.Context())\n\t\tslog.Info(\"request\", \"tenant\", tenantID)\n\t\tw.Write([]byte(\"hello \" + tenantID))\n\t})\n\n\tmw := middleware.TenantMiddleware(middleware.FromHeader(\"X-Tenant-Id\"))(handler)\n\thttp.ListenAndServe(\":8080\", mw)\n}\n```\n\nSee [examples/basic-http](examples/basic-http) for a complete runnable example.\n\n## Architecture\n\n```\n┌─────────────┐     ┌──────────────┐     ┌─────────────────┐\n│ HTTP/gRPC   │────▶│  Middleware  │────▶│ context.Context │\n│ Request     │     │  /Resolver   │     │ (tenant ID)     │\n└─────────────┘     └──────────────┘     └────────┬────────┘\n                                                   │\n                    ┌──────────────────────────────┼──────────────┐\n                    │              │               │              │\n              ┌─────▼─────┐ ┌──────▼──────┐ ┌─────▼─────┐ ┌─────▼─────┐\n              │ ConfigMgr │ │  SDKMgr     │ │  Logger   │ │  OTel     │\n              │ [T]       │ │  [S,C]      │ │  (slog)   │ │  SpanProc │\n              └───────────┘ └─────────────┘ └───────────┘ └───────────┘\n                    │              │               │              │\n              ┌─────▼──────────────▼───────────────▼──────────────▼─────┐\n              │              Kafka / NATS / RabbitMQ                    │\n              │              (X-Tenant-Id header injection)             │\n              └────────────────────────────────────────────────────────┘\n```\n\n## Packages\n\n| Package          | Description                              | Key Functions / Types                                                                                              |\n| ---------------- | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |\n| `pkg/context`    | Tenant ID in `context.Context`           | `WithTenantID`, `TenantIDFromContext`, `HasTenantID`                                                               |\n| `pkg/mt`         | Generic multi-tenant tools               | `SetDefTenant`, `ExtractTID`, `InjectTID`, `ConfigMgr[T]`, `SDKMgr[T,C]`, `CloneCtx`, `ExpandConfigReader`         |\n| `pkg/middleware` | HTTP middlewares (std, Echo)             | `TenantMiddleware`, `FromHeader`, `FromQuery`, `FromSubdomain`, `TenantEchoMiddleware`, `PrometheusEchoMiddleware` |\n| `pkg/resolver`   | Tenant resolver chain                    | `Chain`, `FromHeader`, `FromQuery`, `FromSubdomain`, `FromCookie`, `FromJWTClaim`, `Tenant`, `Registry`            |\n| `pkg/grpc`       | gRPC interceptors                        | `UnaryServerInterceptor`, `StreamServerInterceptor`, `UnaryClientInterceptor`, `StreamClientInterceptor`           |\n| `pkg/timezone`   | Per-tenant timezone settings             | `Set`, `Now` — returns time in tenant's timezone                                                                   |\n| `pkg/logger`     | Logger with `tenant_id` field            | `New(ctx)` — wraps `log/slog` with tenant ID                                                                       |\n| `pkg/otel`       | OpenTelemetry span processor             | `NewTenantIDProcessor()` — adds `tenant_id` to spans                                                               |\n| `pkg/rabbitmq`   | RabbitMQ with `X-Tenant-Id` header       | `Publisher`, `Consumer`                                                                                            |\n| `pkg/kafka`      | Kafka with `X-Tenant-Id` header          | `Producer`, `Consumer`                                                                                             |\n| `pkg/nats`       | NATS with `X-Tenant-Id` header           | `Publisher`, `Subscriber`                                                                                          |\n| `pkg/httpclient` | HTTP client with tenant header injection | `Do(ctx, req)` — auto-injects `X-Tenant-Id`                                                                        |\n| `pkg/burst`      | Per-tenant token bucket rate limiter     | `New(rate, burst)`, `Allow(ctx)`                                                                                   |\n\n## Design Decisions\n\nSee [docs/adr](docs/adr) for architecture decision records:\n\n- [ADR-001: Use Generics for Type-Safe Multi-Tenant Resources](docs/adr/001-generics.md)\n- [ADR-002: Context Propagation Strategy](docs/adr/002-context-propagation.md)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpapadanielvi%2Fapadana","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpapadanielvi%2Fapadana","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpapadanielvi%2Fapadana/lists"}