ring:adding-multi-tenancy
Adding database-per-tenant isolation into a Go service end-to-end via an 11-gate cycle: detects the stack, audits compliance, then dispatches backend agents to implement tenantId-from-JWT routing through the lib-commons v5 dispatch layer (config, middleware, repositories, metrics, tests) and runs reviewers. Use when adding tenant isolation to a Go service. Skip for non-Go services or organization_id-style soft tenancy.
What this skill does
# Multi-Tenant Development Cycle ## When to use - User requests multi-tenant implementation for a Go service - User asks to add tenant isolation to an existing service - Task mentions "multi-tenant", "tenant isolation", "dispatch layer", "postgres.Manager", "WithPG", "WithMB", "EventListener", "TenantCache", "TenantLoader" ## Skip when - Service is not a Go project - Task does not involve multi-tenancy or tenant isolation - Service is a shared infrastructure component operating outside tenant context - Task is documentation-only or non-code You orchestrate. Agents implement. NEVER use Edit/Write/Bash on Go source files. All code changes go through `Task(subagent_type="ring:backend-go")`. TDD mandatory for all implementation gates (RED → GREEN → REFACTOR). ## Multi-Tenant Architecture Isolation: `tenantId` from JWT → dispatch layer middleware → database-per-tenant. `organization_id` is NOT multi-tenant. `tenantId` from JWT is the ONLY mechanism. **Standards reference:** `https://raw.githubusercontent.com/LerianStudio/ring/main/dev-team/docs/standards/golang/multi-tenant.md` **Sub-package import reference:** | Alias | Import Path | Purpose | |-------|-------------|---------| | `client` | `github.com/LerianStudio/lib-commons/v5/commons/dispatch layer/client` | Tenant Manager HTTP client | | `tmcore` | `github.com/LerianStudio/lib-commons/v5/commons/dispatch layer/core` | Context helpers, resolvers | | `tmmiddleware` | `github.com/LerianStudio/lib-commons/v5/commons/dispatch layer/middleware` | TenantMiddleware (WithPG/WithMB) | | `tmpostgres` | `github.com/LerianStudio/lib-commons/v5/commons/dispatch layer/postgres` | PostgresManager | | `tmmongo` | `github.com/LerianStudio/lib-commons/v5/commons/dispatch layer/mongo` | MongoManager | | `tmrabbitmq` | `github.com/LerianStudio/lib-commons/v5/commons/dispatch layer/rabbitmq` | RabbitMQ Manager | | `valkey` | `github.com/LerianStudio/lib-commons/v5/commons/dispatch layer/valkey` | Redis key prefixing | | `s3` | `github.com/LerianStudio/lib-commons/v5/commons/dispatch layer/s3` | S3 key prefixing | | `secretsmanager` | `github.com/LerianStudio/lib-commons/v5/commons/secretsmanager` | M2M credentials | **Key mandatory requirements:** - `MULTI_TENANT_URL` — correct env var name (NOT `TENANT_MANAGER_ADDRESS`) - 4 canonical metrics (from multi-tenant.md) — all MANDATORY - Circuit breaker: `client.WithCircuitBreaker` — MANDATORY - Service API key: `client.WithServiceAPIKey` — MANDATORY - Tenant middleware: per-route `WhenEnabled()` — NOT global `app.Use` - All context helpers: `tmcore.GetPGContext(ctx)` / `tmcore.GetMBContext(ctx)` — NEVER `.GetDB()` directly **Mandatory agent instruction (include in EVERY dispatch):** > WebFetch `https://raw.githubusercontent.com/LerianStudio/ring/main/dev-team/docs/standards/golang/multi-tenant.md`. > Use exact import paths from skill. Do NOT invent sub-package paths. > TDD: RED → GREEN → REFACTOR for every gate. ## Gate Overview | Gate | Name | Condition | Agent | |------|------|-----------|-------| | 0 | Stack Detection + Compliance Audit | Always | Orchestrator | | 1 | Codebase Analysis (multi-tenant focus) | Always | ring:codebase-explorer | | 1.5 | Implementation Preview | Always | ring:visualizing | | 2 | lib-commons v5 + lib-auth v2 Upgrade | Skip only if both already pinned in go.mod | ring:backend-go | | 3 | Multi-Tenant Configuration | Always | ring:backend-go | | 4 | Tenant Middleware (TenantMiddleware with WithPG/WithMB) | Always | ring:backend-go | | 5 | Repository Adaptation | Always per detected DB | ring:backend-go | | 5.5 | M2M Secret Manager | Skip if service has no targetServices | ring:backend-go | | 6 | RabbitMQ Multi-Tenant | Skip if no RabbitMQ | ring:backend-go | | 7 | Metrics & Backward Compat | Always | ring:backend-go | | 8 | Tests | Always | ring:backend-go | | 9 | Code Review | Always | 9 defaults + triggered specialists in parallel | | 10 | User Validation | Always | User | | 11 | Activation Guide | Always | Orchestrator | Gates execute sequentially. Existing multi-tenant code ≠ compliance. Gate 0 audit is mandatory. ## Gate 0: Stack Detection + Compliance Audit Orchestrator executes directly. Two phases: **Phase 1: Stack Detection** ```bash grep "lib-commons" go.mod grep "lib-auth" go.mod grep -rn "postgresql\|pgx" internal/ go.mod grep -rn "mongodb\|mongo" internal/ go.mod grep -rn "redis\|valkey" internal/ go.mod grep -rn "rabbitmq\|amqp" internal/ go.mod grep -rn "s3\|ObjectStorage" internal/ grep -rn "MULTI_TENANT_ENABLED\|dispatch layer" internal/ grep -rn "client_credentials\|M2M\|secretsmanager" internal/ ``` **Phase 2: Compliance Audit** (if multi-tenant code detected) Run A1-A8 checks (grep-based): - A1: `MULTI_TENANT_URL` used (not `TENANT_MANAGER_ADDRESS` or variants) - A2: `WithCircuitBreaker` on TM client - A3: `WithServiceAPIKey` on TM client - A4: `tmcore.GetPGContext` / `tmcore.GetMBContext` used (not `.GetDB()` / `.GetDatabase()`) - A5: Tenant middleware per-route `WhenEnabled()` (not global `app.Use`) - A6: Redis keys use `valkey.GetKeyContext` - A7: S3 keys use `s3.GetS3KeyStorageContext` - A8: No global DB singletons (`var db *sql.DB` or `var client *mongo.Client`) Any NON-COMPLIANT → corresponding gate MUST execute. ## Severity Reference | Severity | Criteria | |----------|----------| | CRITICAL | Cross-tenant data leak; wrong tenant identifier (`organization_id`) | | HIGH | Missing TenantMiddleware; wrong env var names; no circuit breaker | | MEDIUM | Missing circuit breaker; incomplete metrics | | LOW | Missing env var comments; pool tuning notes |
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.