Skill站外收录 @skilllib/skill-2014279378107052033
linear-reference-architecture
提供面向 Linear 平台的生产级集成架构方案,涵盖从轻量级单应用集成到高可用事件驱动、CQRS 等复杂模式,支持缓存、限流、审计、实时同步与多服务协同等能力,适用于不同规模团队的系统设计与架构演进。
软件开发 AI 技能
Skills.MD
# Linear Reference Architecture
## Overview
Production-grade architectural patterns for Linear integrations.
## Prerequisites
- Understanding of distributed systems
- Experience with cloud infrastructure
- Familiarity with event-driven architecture
## Architecture Patterns
### Pattern 1: Simple Integration
Best for: Small teams, single applications
```
┌─────────────────────────────────────────────────────────┐
│ Your Application │
├─────────────────────────────────────────────────────────┤
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Linear SDK │ │ Cache Layer │ │ Webhook │ │
│ │ (API calls) │ │ (In-memory) │ │ Handler │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────┘
│
▼
┌──────────────────────┐
│ Linear API │
│ api.linear.app │
└──────────────────────┘
```
```typescript
// Simple architecture implementation
// lib/simple-linear.ts
import { LinearClient } from "@linear/sdk";
const cache = new Map<string, { data: any; expires: number }>();
export class SimpleLinearService {
private client: LinearClient;
constructor() {
this.client = new LinearClient({
apiKey: process.env.LINEAR_API_KEY!,
});
}
async getWithCache<T>(key: string, fetcher: () => Promise<T>, ttl = 300): Promise<T> {
const cached = cache.get(key);
if (cached && cached.expires > Date.now()) {
return cached.data;
}
const data = await fetcher();
cache.set(key, { data, expires: Date.now() + ttl * 1000 });
return data;
}
async getTeams() {
return this.getWithCache("teams", () => this.client.teams());
}
}
```
### Pattern 2: Service-Oriented Architecture
Best for: Medium teams, multiple applications
```
┌────────────────────────────────────────────────────────────────┐
│ API Gateway │
└────────────────────────────────────────────────────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────────┐
│ Issues Service │ │ Projects Service│ │ Notifications Svc │
│ (CRUD + sync) │ │ (Planning) │ │ (Slack, Email) │
└─────────────────┘ └─────────────────┘ └─────────────────────┘
│ │ │
└────────────────────┼────────────────────┘
▼
┌─────────────────┐
│ Linear Gateway │
│ (Rate limiting, │
│ caching, auth) │
└─────────────────┘
│
▼
┌─────────────────┐
│ Linear API │
└─────────────────┘
```
```typescript
// lib/linear-gateway.ts
import { LinearClient } from "@linear/sdk";
import Redis from "ioredis";
export class LinearGateway {
private client: LinearClient;
private redis: Redis;
private rateLimiter: RateLimiter;
constructor() {
this.client = new LinearClient({ apiKey: process.env.LINEAR_API_KEY! });
this.redis = new Redis(process.env.REDIS_URL);
this.rateLimiter = new RateLimiter({
maxRequests: 1000, // Leave buffer from 1500 limit
windowMs: 60000,
});
}
async execute<T>(operation: string, fn: () => Promise<T>): Promise<T> {
// Check cache first
const cacheKey = `linear:${operation}`;
const cached = await this.redis.get(cacheKey);
if (cached) return JSON.parse(cached);
// Rate limit
await this.rateLimiter.acquire();
// Execute with metrics
const start = Date.now();
try {
const result = await fn();
// Cache result
await this.redis.setex(cacheKey, 60, JSON.stringify(result));
// Record metrics
metrics.requestDuration.observe(Date.now() - start);
return result;
} catch (error) {
metrics.errors.inc({ operation });
throw error;
}
}
}
```
### Pattern 3: Event-Driven Architecture
Best for: Large teams, real-time requirements
```
┌─────────────────────────────────────────────────────────────────────┐
│ Event Bus (Kafka/SQS) │
└─────────────────────────────────────────────────────────────────────┘
▲ │ │
│ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Webhook Ingester│ │ Event Processor │ │ Notification │
│ (Linear events) │ │ (Business logic)│ │ Service │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐
│ State Store │
│ (PostgreSQL) │
└─────────────────┘
│
▼
┌─────────────────┐
│ Linear Sync │
│ (Outbound) │
└─────────────────┘
│
▼
┌─────────────────┐
│ Linear API │
└─────────────────┘
```
```typescript
// services/webhook-ingester.ts
import { Kafka } from "kafkajs";
const kafka = new Kafka({
brokers: [process.env.KAFKA_BROKER!],
});
const producer = kafka.producer();
export async function ingestWebhook(event: LinearWebhookEvent): Promise<void> {
// Verify signature
if (!verifySignature(event)) {
throw new Error("Invalid signature");
}
// Publish to appropriate topic
await producer.send({
topic: `linear.${event.type.toLowerCase()}`,
messages: [{
key: event.data.id,
value: JSON.stringify(event),
headers: {
action: event.action,
timestamp: event.webhookTimestamp.toString(),
},
}],
});
}
// services/event-processor.ts
const consumer = kafka.consumer({ groupId: "linear-processor" });
await consumer.subscribe({ topics: ["linear.issue", "linear.comment"] });
await consumer.run({
eachMessage: async ({ topic, message }) => {
const event = JSON.parse(message.value!.toString());
switch (topic) {
case "linear.issue":
await processIssueEvent(event);
break;
case "linear.comment":
await processCommentEvent(event);
break;
}
},
});
```
### Pattern 4: CQRS with Event Sourcing
Best for: Complex domains, audit requirements
```
┌─────────────────────────────────────────────────────────────────────┐
│ Command Side │
├─────────────────────────────────────────────────────────────────────┤
│ Commands → Command Handler → Event Store → Event Publisher │
└─────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────┐
│ Query Side │
├─────────────────────────────────────────────────────────────────────┤
│ Event Subscriber → Projector → Read Models → Query API │
└─────────────────────────────────────────────────────────────────────┘
```
```typescript
// cqrs/event-store.ts
interface StoredEvent {
id: string;
aggregateId: string;
aggregateType: string;
eventType: string;
data: Record<string, unknown>;
metadata: {
userId: string;
correlationId: string;
causationId: string;
timestamp: Date;
};
version: number;
}
class EventStore {
async append(aggregateId: string, events: StoredEvent[]): Promise<void> {
await db.transaction(async (tx) => {
for (const event of events) {
await tx.insert(eventsTable).values(event);
}
});
// Publish to subscribers
for (const event of events) {
await eventBus.publish(event);
}
}
async getEvents(aggregateId: string): Promise<StoredEvent[]> {
return db.select().from(eventsTable)
.where(eq(eventsTable.aggregateId, aggregateId))
.orderBy(eventsTable.version);
}
}
// Projector for read model
class IssueProjector {
@Subscribe("IssueCreated")
async onIssueCreated(event: StoredEvent): Promise<void> {
await db.insert(issueReadModel).values({
id: event.aggregateId,
...event.data,
createdAt: event.metadata.timestamp,
});
}
@Subscribe("IssueUpdated")
async onIssueUpdated(event: StoredEvent): Promise<void> {
await db.update(issueReadModel)
.set(event.data)
.where(eq(issueReadModel.id, event.aggregateId));
}
}
```
## Project Structure
```
linear-integration/
├── src/
│ ├── api/ # REST/GraphQL API
│ │ ├── routes/
│ │ └── middleware/
│ ├── services/ # Business logic
│ │ ├── issue-service.ts
│ │ ├── project-service.ts
│ │ └── sync-service.ts
│ ├── infrastructure/ # External integrations
│ │ ├── linear/
│ │ │ ├── client.ts
│ │ │ ├── cache.ts
│ │ │ └── webhook-handler.ts
│ │ ├── database/
│ │ └── cache/
│ ├── domain/ # Domain models
│ │ ├── issue.ts
│ │ └── project.ts
│ └── config/ # Configuration
│ └── index.ts
├── tests/
│ ├── unit/
│ ├── integration/
│ └── e2e/
└── infrastructure/ # IaC
├── terraform/
└── kubernetes/
```
## Resources
- [Linear API Best Practices](https://developers.linear.app/docs/graphql/best-practices)
- [Event-Driven Architecture](https://martinfowler.com/articles/201701-event-driven.html)
- [CQRS Pattern](https://martinfowler.com/bliki/CQRS.html)
## Next Steps
Configure multi-environment setup with `linear-multi-env-setup`.
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「linear-reference-architecture」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次