agentsclimarketplace

Attio reference architecture

Skill ComeOnOliver/skillshub/skills/jeremylongshore/claude-code-plugins-plus-skills/attio-reference-architecture

🧠 The right skill, one API call. AI agent skills registry with token-efficient skill resolution. 5,000+ skills from 500+ top repos.

Install
npx -y skills add ComeOnOliver/skillshub --skill attio-reference-architecture

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

What its author says it does

Copied from the file, not written here

Production reference architecture for Attio CRM integrations -- layered project structure, sync patterns, webhook processing, and multi-environment setup. Trigger: "attio architecture", "attio best practices", "attio project structure", "how to organize attio", "attio integration design".

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

12.9 KB, ~2.7k tokens by cl100k_base, as published. Nobody here has run it

Attio Reference Architecture

Overview

Production architecture for applications that integrate with the Attio REST API (https://api.attio.com/v2). Covers project layout, layered service design, sync patterns, and operational concerns.

Project Structure

my-attio-integration/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ attio/                        # Attio API layer (isolated)
β”‚   β”‚   β”œβ”€β”€ client.ts                 # Typed fetch wrapper with retry
β”‚   β”‚   β”œβ”€β”€ types.ts                  # Attio API types (AttioRecord, AttioError, etc.)
β”‚   β”‚   β”œβ”€β”€ config.ts                 # Environment-based config loader
β”‚   β”‚   └── errors.ts                 # AttioApiError class
β”‚   β”œβ”€β”€ services/                     # Business logic (uses attio/ layer)
β”‚   β”‚   β”œβ”€β”€ contacts.ts              # People/company sync logic
β”‚   β”‚   β”œβ”€β”€ pipeline.ts              # Deal pipeline management
β”‚   β”‚   β”œβ”€β”€ activity.ts              # Notes, tasks, comments
β”‚   β”‚   └── sync.ts                  # Bi-directional sync orchestrator
β”‚   β”œβ”€β”€ webhooks/                     # Incoming webhook handlers
β”‚   β”‚   β”œβ”€β”€ router.ts                # Event type routing
β”‚   β”‚   β”œβ”€β”€ verify.ts                # Signature verification
β”‚   β”‚   └── handlers/
β”‚   β”‚       β”œβ”€β”€ record-events.ts     # record.created/updated/deleted/merged
β”‚   β”‚       β”œβ”€β”€ entry-events.ts      # list-entry.created/updated/deleted
β”‚   β”‚       └── activity-events.ts   # note/task/comment events
β”‚   β”œβ”€β”€ api/                         # Outbound API routes
β”‚   β”‚   β”œβ”€β”€ health.ts                # Health check (includes Attio)
β”‚   β”‚   └── webhooks.ts              # Webhook receiver endpoint
β”‚   β”œβ”€β”€ cache/                       # Caching layer
β”‚   β”‚   β”œβ”€β”€ schema-cache.ts          # Object/attribute definitions (30min TTL)
β”‚   β”‚   └── record-cache.ts          # Record data (5min TTL, webhook invalidation)
β”‚   └── index.ts                     # App entrypoint
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ mocks/                       # MSW handlers for Attio API
β”‚   β”œβ”€β”€ unit/                        # Service logic tests (mocked API)
β”‚   └── integration/                 # Live API tests (CI-gated)
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ attio.development.json
β”‚   β”œβ”€β”€ attio.staging.json
β”‚   └── attio.production.json
β”œβ”€β”€ .env.example
└── .github/workflows/attio.yml

Layered Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  API Layer (routes, webhook endpoint)            β”‚
β”‚  - Receives HTTP requests                        β”‚
β”‚  - Validates webhook signatures                  β”‚
β”‚  - Returns health status                         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Service Layer (business logic)                  β”‚
β”‚  - Contact sync, pipeline management             β”‚
β”‚  - Bi-directional data mapping                   β”‚
β”‚  - Event-driven automations                      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Attio Layer (API client, types, errors)         β”‚
β”‚  - Typed fetch wrapper with retry                β”‚
β”‚  - Error normalization (AttioApiError)            β”‚
β”‚  - Pagination helpers                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Infrastructure Layer (cache, queue, monitoring)  β”‚
β”‚  - LRU + Redis caching with webhook invalidation β”‚
β”‚  - Rate limit queue (p-queue)                    β”‚
β”‚  - Structured logging and metrics                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Rule: Each layer only calls the layer directly below it. The API layer never calls the Attio client directly.

Core Components

Component 1: Service Layer Facade

// src/services/contacts.ts
import { AttioClient } from "../attio/client";
import { cachedGet, invalidateRecord } from "../cache/record-cache";
import type { AttioRecord } from "../attio/types";

export class ContactService {
  constructor(private client: AttioClient) {}

  async findByEmail(email: string): Promise<AttioRecord | null> {
    const res = await this.client.post<{ data: AttioRecord[] }>(
      "/objects/people/records/query",
      {
        filter: { email_addresses: email },
        limit: 1,
      }
    );
    return res.data[0] || null;
  }

  async upsertPerson(data: {
    email: string;
    firstName: string;
    lastName: string;
    company?: string;
  }): Promise<AttioRecord> {
    // Use PUT (assert) for idempotent upsert
    const res = await this.client.put<{ data: AttioRecord }>(
      "/objects/people/records",
      {
        data: {
          values: {
            email_addresses: [data.email],
            name: [{
              first_name: data.firstName,
              last_name: data.lastName,
              full_name: `${data.firstName} ${data.lastName}`,
            }],
            ...(data.company ? { company: [{ target_object: "companies", target_record_id: data.company }] } : {}),
          },
        },
      }
    );
    return res.data;
  }

  async addToPipeline(
    recordId: string,
    listSlug: string,
    stage: string,
    value?: { currency: string; amount: number }
  ): Promise<void> {
    await this.client.post(`/lists/${listSlug}/entries`, {
      data: {
        parent_record_id: recordId,
        parent_object: "people",
        values: {
          stage: [{ status: stage }],
          ...(value ? {
            deal_value: [{ currency_code: value.currency, currency_value: value.amount }],
          } : {}),
        },
      },
    });
  }

  async addNote(recordId: string, title: string, content: string): Promise<void> {
    await this.client.post("/notes", {
      data: {
        parent_object: "people",
        parent_record_id: recordId,
        title,
        format: "markdown",
        content,
      },
    });
  }
}

Component 2: Webhook Event Router

// src/webhooks/router.ts
import type { AttioWebhookEvent } from "../attio/types";

type EventHandler = (event: AttioWebhookEvent) => Promise<void>;

export class WebhookRouter {
  private handlers = new Map<string, EventHandler[]>();

  on(eventType: string, handler: EventHandler): void {
    const existing = this.handlers.get(eventType) || [];
    this.handlers.set(eventType, [...existing, handler]);
  }

  async route(event: AttioWebhookEvent): Promise<void> {
    const handlers = this.handlers.get(event.event_type) || [];
    if (handlers.length === 0) {
      console.log(`No handler for event: ${event.event_type}`);
      return;
    }
    await Promise.allSettled(handlers.map((h) => h(event)));
  }
}

// Usage
const router = new WebhookRouter();
router.on("record.created", async (event) => {
  if (event.object?.api_slug === "people") {
    await syncNewContactToExternalCRM(event.record!.id.record_id);
  }
});
router.on("record.updated", async (event) => {
  invalidateRecord(event.record!.id.record_id);
});
router.on("list-entry.created", async (event) => {
  await triggerPipelineAutomation(event);
});

Component 3: Bi-Directional Sync

// src/services/sync.ts
export class AttioSyncService {
  private lastSyncCursor: string | null = null;

  /** Outbound: push local changes to Attio */
  async pushToAttio(localContact: LocalContact): Promise<string> {
    const attioRecord = await this.contacts.upsertPerson({
      email: localContact.email,
      firstName: localContact.firstName,
      lastName: localContact.lastName,
    });
    return attioRecord.id.record_id;
  }

  /** Inbound: pull Attio changes to local (webhook-driven) */
  async handleAttioChange(event: AttioWebhookEvent): Promise<void> {
    if (event.event_type === "record.updated") {
      const record = await this.client.get<{ data: AttioRecord }>(
        `/objects/${event.object!.api_slug}/records/${event.record!.id.record_id}`
      );
      await this.updateLocalFromAttio(record.data);
    }
  }

  /** Full sync: reconcile all records (run periodically or on demand) */
  async fullSync(objectSlug: string): Promise<{ created: number; updated: number }> {
    let created = 0, updated = 0;
    const PAGE_SIZE = 500;
    let offset = 0;

    while (true) {
      const page = await this.client.post<{ data: AttioRecord[] }>(
        `/objects/${objectSlug}/records/query`,
        { limit: PAGE_SIZE, offset }
      );

      for (const record of page.data) {
        const existed = await this.upsertLocal(record);
        existed ? updated++ : created++;
      }

      if (page.data.length < PAGE_SIZE) break;
      offset += PAGE_SIZE;
    }

    return { created, updated };
  }
}

Component 4: Multi-Environment Config

// src/attio/config.ts
interface AttioEnvironmentConfig {
  apiKey: string;
  webhookSecret: string;
  baseUrl: string;
  cache: { schemaTtlMs: number; recordTtlMs: number };
  rateLimit: { concurrency: number; intervalCap: number };
}

const configs: Record<string, Partial<AttioEnvironmentConfig>> = {
  development: {
    cache: { schemaTtlMs: 60_000, recordTtlMs: 10_000 },
    rateLimit: { concurrency: 2, intervalCap: 5 },
  },
  staging: {
    cache: { schemaTtlMs: 300_000, recordTtlMs: 60_000 },
    rateLimit: { concurrency: 5, intervalCap: 8 },
  },
  production: {
    cache: { schemaTtlMs: 1_800_000, recordTtlMs: 300_000 },
    rateLimit: { concurrency: 10, intervalCap: 15 },
  },
};

export function loadConfig(): AttioEnvironmentConfig {
  const env = process.env.NODE_ENV || "development";
  const envConfig = configs[env] || configs.development;
  return {
    apiKey: requireEnv("ATTIO_API_KEY"),
    webhookSecret: process.env.ATTIO_WEBHOOK_SECRET || "",
    baseUrl: "https://api.attio.com/v2",
    cache: envConfig.cache!,
    rateLimit: envConfig.rateLimit!,
  };
}

function requireEnv(key: string): string {
  const val = process.env[key];
  if (!val) throw new Error(`Missing required env: ${key}`);
  return val;
}

Data Flow Diagram

External System                    Your Application                      Attio CRM
     β”‚                                   β”‚                                  β”‚
     β”‚  Local change ──────────────────▢ β”‚                                  β”‚
     β”‚                                   β”‚  PUT /objects/people/records ──▢ β”‚
     β”‚                                   β”‚  ◀── 200 { data: record }       β”‚
     β”‚                                   β”‚                                  β”‚
     β”‚                                   β”‚       Webhook: record.updated    β”‚
     β”‚                                   β”‚  ◀──────────────────────────── β”‚
     β”‚  ◀── Sync update ──────────────  β”‚                                  β”‚
     β”‚                                   β”‚  GET /objects/.../records/... ─▢ β”‚
     β”‚                                   β”‚  ◀── 200 { data: record }       β”‚

Error Handling

Architecture issueSymptomFix
Service calls client directlyTight coupling, hard to testAdd service layer facade
No cache invalidationStale data after updatesWebhook-driven cache invalidation
Sync conflictsBoth sides updated same recordLast-write-wins or conflict resolution queue
No circuit breakerAttio outage cascadesAdd circuit breaker in Attio layer

Resources

Next Steps

This is the capstone skill. For specific implementations, refer to the individual skills in this pack.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.