linear-reference-architecture
Production-grade Linear integration architecture patterns. Use when designing system architecture, choosing integration patterns, or reviewing architectural decisions for Linear integrations. Trigger: "linear architecture", "linear system design", "linear integration patterns", "linear best practices architecture".
What this skill does
# Linear Reference Architecture
## Overview
Production-grade architectural patterns for Linear integrations. Choose the right pattern based on team size, complexity, and real-time requirements.
## Architecture Decision Matrix
| Pattern | Best For | Complexity | Rate Budget | Example |
|---------|----------|------------|-------------|---------|
| Simple | Single app, small team | Low | < 500 req/hr | Internal dashboard |
| Service-Oriented | Multiple apps, shared state | Medium | 500-2,000 req/hr | Platform with Linear sync |
| Event-Driven | Real-time needs, many consumers | High | < 500 req/hr + webhooks | Multi-service notification system |
| CQRS | Audit trails, complex queries | Very High | Minimal API calls | Compliance-grade tracking |
## Architecture 1: Simple Integration
Direct SDK calls from your application. Best for scripts, internal tools, and prototypes.
```typescript
// src/linear.ts — single module, shared client
import { LinearClient } from "@linear/sdk";
const client = new LinearClient({ apiKey: process.env.LINEAR_API_KEY! });
// Direct SDK calls from any part of your app
export async function getOpenIssues(teamKey: string) {
return client.issues({
first: 50,
filter: {
team: { key: { eq: teamKey } },
state: { type: { nin: ["completed", "canceled"] } },
},
orderBy: "priority",
});
}
export async function createBugReport(teamId: string, title: string, description: string) {
const labels = await client.issueLabels({ filter: { name: { eq: "Bug" } } });
return client.createIssue({
teamId,
title,
description,
priority: 2,
labelIds: labels.nodes.length ? [labels.nodes[0].id] : [],
});
}
```
## Architecture 2: Service-Oriented with Gateway
Centralized Linear access through a gateway service with caching and rate limiting.
```typescript
// src/linear-gateway.ts
import { LinearClient } from "@linear/sdk";
class LinearGateway {
private client: LinearClient;
private cache = new Map<string, { data: any; expiresAt: number }>();
private requestQueue: Array<{ fn: () => Promise<any>; resolve: Function; reject: Function }> = [];
private processing = false;
constructor(apiKey: string) {
this.client = new LinearClient({ apiKey });
}
// Cached reads
async getTeams() {
return this.cachedQuery("teams", () => this.client.teams().then(r => r.nodes), 600);
}
async getStates(teamId: string) {
return this.cachedQuery(`states:${teamId}`, async () => {
const team = await this.client.team(teamId);
return (await team.states()).nodes;
}, 1800);
}
// Rate-limited writes
async createIssue(input: any) {
return this.enqueue(() => this.client.createIssue(input));
}
async updateIssue(id: string, input: any) {
return this.enqueue(() => this.client.updateIssue(id, input));
}
// Custom queries through the gateway
async rawQuery(query: string, variables?: any) {
return this.enqueue(() => this.client.client.rawRequest(query, variables));
}
// Cache invalidation (called from webhook handler)
invalidate(pattern: string) {
for (const key of this.cache.keys()) {
if (key.startsWith(pattern)) this.cache.delete(key);
}
}
private async cachedQuery<T>(key: string, fn: () => Promise<T>, ttlSec: number): Promise<T> {
const cached = this.cache.get(key);
if (cached && Date.now() < cached.expiresAt) return cached.data;
const data = await this.enqueue(fn);
this.cache.set(key, { data, expiresAt: Date.now() + ttlSec * 1000 });
return data;
}
private async enqueue<T>(fn: () => Promise<T>): Promise<T> {
return new Promise((resolve, reject) => {
this.requestQueue.push({ fn, resolve, reject });
if (!this.processing) this.processQueue();
});
}
private async processQueue() {
this.processing = true;
while (this.requestQueue.length > 0) {
const { fn, resolve, reject } = this.requestQueue.shift()!;
try { resolve(await fn()); } catch (e) { reject(e); }
if (this.requestQueue.length > 0) {
await new Promise(r => setTimeout(r, 100)); // 10 req/sec max
}
}
this.processing = false;
}
}
export const gateway = new LinearGateway(process.env.LINEAR_API_KEY!);
```
## Architecture 3: Event-Driven
Webhook-centric architecture. Minimal API calls, real-time processing.
```typescript
// src/event-processor.ts
import express from "express";
import crypto from "crypto";
import { EventEmitter } from "events";
// Internal event bus
const bus = new EventEmitter();
// Webhook ingester
const app = express();
app.post("/webhooks/linear", express.raw({ type: "*/*" }), (req, res) => {
const sig = req.headers["linear-signature"] as string;
const body = req.body.toString();
const expected = crypto.createHmac("sha256", process.env.LINEAR_WEBHOOK_SECRET!)
.update(body).digest("hex");
if (!crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected))) {
return res.status(401).end();
}
const event = JSON.parse(body);
res.json({ ok: true });
// Emit to internal consumers
bus.emit(`${event.type}.${event.action}`, event);
bus.emit(event.type, event);
bus.emit("*", event);
});
// Consumer: Slack notifications
bus.on("Issue.update", async (event) => {
if (event.updatedFrom?.stateId && event.data.state?.type === "completed") {
await notifySlack(`Done: ${event.data.identifier} ${event.data.title}`);
}
});
// Consumer: Database sync
bus.on("Issue", async (event) => {
if (event.action === "create") await db.issues.insert(event.data);
if (event.action === "update") await db.issues.update(event.data.id, event.data);
if (event.action === "remove") await db.issues.softDelete(event.data.id);
});
// Consumer: Cache invalidation
bus.on("*", (event) => {
gateway.invalidate(event.type.toLowerCase());
});
```
## Architecture 4: CQRS with Local State
Separate read and write paths. Full local state for complex queries, API for writes.
```typescript
// Write side: mutations go through Linear API
async function createIssue(input: any) {
const result = await gateway.createIssue(input);
// Local state updated via webhook, not here
return result;
}
// Read side: queries against local database (no API calls)
async function getSprintVelocity(teamKey: string, sprints: number) {
return db.query(`
SELECT c.name, SUM(i.estimate) as velocity
FROM cycles c
JOIN issues i ON i.cycle_id = c.id AND i.state_type = 'completed'
WHERE c.team_key = ? AND c.completed_at IS NOT NULL
ORDER BY c.completed_at DESC
LIMIT ?
`, [teamKey, sprints]);
}
// Sync: webhook events keep local state fresh
// Full sync: daily consistency check (see linear-data-handling)
```
## Project Structure
```
src/
linear/
gateway.ts # Rate-limited, cached API access
webhook-handler.ts # Signature verification + routing
event-bus.ts # Internal event distribution
cache.ts # TTL cache with invalidation
services/
issue-service.ts # Business logic
sync-service.ts # Data synchronization
config/
linear.ts # Environment config + validation
```
## Error Handling
| Error | Cause | Solution |
|-------|-------|----------|
| Rate limit exceeded | Too many direct API calls | Route all calls through gateway |
| Stale cache | TTL too long, missed webhook | Webhook invalidation + periodic full sync |
| Event loss | Webhook delivery failure | Idempotent handlers + consistency checks |
| Schema drift | SDK version mismatch | Pin version, test upgrades in staging |
## Resources
- [Linear API Best Practices](https://linear.app/developers/graphql)
- [Event-Driven Architecture](https://martinfowler.com/articles/201701-event-driven.html)
- [CQRS Pattern](https://martinfowler.com/bliki/CQRS.html)
Related in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.