---
name: intercom-reference-architecture
description: 'Implement Intercom reference architecture with layered project structure.

  Use when designing new Intercom integrations, reviewing project structure,

  or establishing architecture standards for Intercom applications.

  Trigger with phrases like "intercom architecture", "intercom project structure",

  "how to organize intercom", "intercom layout", "intercom design patterns".'
allowed-tools: Read, Grep
version: 1.6.0
license: MIT
author: Jeremy Longshore <jeremy@intentsolutions.io>
tags:
  - saas
  - support
  - messaging
  - intercom
compatibility: Designed for Claude Code
title: intercom-reference-architecture
canonical_url: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/intercom-reference-architecture
last_updated: 2026-10-07T06:06:28.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/intercom-reference-architecture/references/examples.md), [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/intercom-reference-architecture/references/implementation.md), [references/project-structure.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/intercom-reference-architecture/references/project-structure.md).
>
> If the user asked to install this Skill, run `npx skilld install jeremylongshore/tons-of-skills-marketplace/intercom-reference-architecture`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/intercom-reference-architecture`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jeremylongshore/tons-of-skills-marketplace/intercom-reference-architecture) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/intercom-reference-architecture`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/intercom-reference-architecture --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/intercom-reference-architecture --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Intercom Reference Architecture

## Overview

A production-ready reference architecture for Intercom integrations built on
four layers — API/webhook, service, Intercom client, and infrastructure — with
type-safe SDK usage, webhook processing, contact sync, and Help Center
management. Use it to scaffold a new integration or to review an existing one
against a known-good structure.

The layers (top to bottom): the **API / Webhook layer** (Express routes, webhook
endpoints) calls into the **service layer** (contacts, conversations, articles —
business logic and orchestration), which calls the **Intercom client layer** (a
singleton `intercom-client` SDK wrapper with typed errors, caching, and rate
limit handling), all resting on **infrastructure** (Redis cache, job queue,
monitoring). Keeping dependencies flowing strictly downward is what prevents the
circular imports and test-isolation problems listed under Error Handling.

## Prerequisites

- Node.js project with TypeScript and the `intercom-client` npm package
  installed.
- An **Intercom access token** — the SDK authenticates every request with a
  Bearer token read from the `INTERCOM_ACCESS_TOKEN` environment variable (see
  Step 1). Create one under Intercom → Developer Hub → your app →
  Authentication. Never commit it; load it from the environment.
- For webhook verification, your app's **client secret** to validate the
  `X-Hub-Signature` header on inbound webhook POSTs.
- Redis (optional) if you enable the caching layer.

## Instructions

Use `Read`/`Grep` to inspect the current project layout, then build each layer
in order — the client layer is the dependency root for every service.

1. **Client layer** (`src/intercom/client.ts`) — a lazy singleton
   `getClient()` that reads `INTERCOM_ACCESS_TOKEN` once, plus an
   `IntercomServiceError` that wraps raw SDK errors into a typed, retry-aware
   shape. Skeleton:

   ```typescript
   let instance: IntercomClient | null = null;
   export function getClient(): IntercomClient {
     if (!instance) {
       const token = process.env.INTERCOM_ACCESS_TOKEN;
       if (!token) throw new Error("INTERCOM_ACCESS_TOKEN required");
       instance = new IntercomClient({ token });
     }
     return instance;
   }
   ```

2. **Contacts service** (`src/services/contacts.service.ts`) —
   `findOrCreate` (search-before-create to avoid 409s), `syncFromCRM`,
   `mergeLead`, and a `searchAll` async generator for cursor pagination.
3. **Conversations service** (`src/services/conversations.service.ts`) —
   `replyAsAdmin`, `addNote`, `closeWithMessage`, and a scoped open-queue
   search.
4. **Articles service** (`src/services/articles.service.ts`) — Help Center
   article create/list, defaulting new articles to `draft`.
5. **Wire the data flow** — Intercom pushes events to your webhook router; the
   service layer makes API calls back and persists to your database + cache.

The full project tree, every service method, and the layer/data-flow diagrams
are in [the full implementation walkthrough](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/intercom-reference-architecture/references/implementation.md); the
complete directory layout is in
[project-structure.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/intercom-reference-architecture/references/project-structure.md).

## Output

Applying this skill produces a layered Intercom integration:

- A `src/intercom/` client layer (singleton SDK wrapper + typed errors).
- A `src/services/` layer with contacts, conversations, and articles services.
- `src/webhooks/`, `src/sync/`, `src/api/`, and `src/cache/` directories wired
  to the layers above.
- Per-environment `config/` files and a `tests/` tree with unit + integration
  suites.

When used to review an existing project, the output is a gap report: which
layers exist, which are missing, and where dependency direction is violated.

## Error Handling

| Issue | Cause | Solution |
|-------|-------|----------|
| Circular dependencies | Service A imports B imports A | Use dependency injection |
| Client initialization race | Async token fetch | Lazy singleton pattern |
| Cache inconsistency | Stale data after update | Webhook-driven invalidation |
| Test isolation | Shared SDK state | `resetClient()` in beforeEach |
| `401 Unauthorized` | Missing/invalid `INTERCOM_ACCESS_TOKEN` | Verify the env var is loaded before `getClient()` |
| `429 Too Many Requests` | Rate limit exceeded | Retry with backoff — `IntercomServiceError.retryable` is `true` here |

## Examples

Once the client and service layers exist, wiring them together is a few lines —
sync a CRM user, reply to and close a conversation, page through contacts, or
publish an article:

```typescript
const contacts = new ContactsService();
const contact = await contacts.syncFromCRM({
  id: "crm_8842", email: "ada@example.com", name: "Ada Lovelace",
  plan: "enterprise", company: "Analytical Engines Ltd",
});
```

See [examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/intercom-reference-architecture/references/examples.md) for the full set of runnable usage
snippets (conversation reply/close, paginated search, Help Center publish).

## Resources

- [Full implementation walkthrough](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/intercom-reference-architecture/references/implementation.md) — every layer, method, and diagram
- [Project structure reference](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/intercom-reference-architecture/references/project-structure.md) — complete directory tree
- [Usage examples](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/intercom-reference-architecture/references/examples.md) — runnable wiring snippets
- [Intercom API Reference](https://developers.intercom.com/docs/references/rest-api/api.intercom.io)
- [Articles API](https://developers.intercom.com/docs/references/rest-api/api.intercom.io/articles)
- [Help Center API](https://developers.intercom.com/docs/references/rest-api/api.intercom.io/help-center)
- [intercom-client npm](https://www.npmjs.com/package/intercom-client)

## Next Steps

For multi-environment configuration and deployment, see the
`intercom-multi-env-setup` skill, which extends the `config/` layer described
above into per-environment credential and rate-limit management.
