Skip to content
Skillv1.0.0

apify-reference-architecture

Production-grade architecture patterns for Apify-powered applications. Use when designing scraping infrastructure, building multi-Actor pipelines, or integrating Apify into a larger system architectur

by jeremylongshore(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from jeremylongshore/tons-of-skills-marketplace (plugins/saas-packs/apify-pack/skills/apify-reference-architecture/SKILL.md). Install upstream with npx skills add jeremylongshore/tons-of-skills-marketplace --skill apify-reference-architecture. Copyright stays with the author (MIT).

Apify Reference Architecture

Overview

Production-ready architecture patterns for applications built on Apify. Three patterns scale from a single scraper to a full-stack integration:

  1. Standalone Actor — one scraper deployed to the Apify platform.
  2. Multi-Actor Pipeline — a discover → scrape → transform chain of Actors.
  3. Full-Stack Integration — an application using Apify as a data source behind a service layer.

This skill helps you choose the right pattern, lay out the directory structure, and wire the skeleton code. Full directory trees, diagrams, and code for every pattern live in references/architecture-patterns.md; the service layer, configuration loader, and health check live in references/implementation.md.

Prerequisites

  • Runtime: Node.js >=18, TypeScript, and the Apify CLI (npm i -g apify-cli).
  • Packages: apify + crawlee (inside an Actor), apify-client (calling Actors from an app), zod (input validation).
  • Auth: an Apify API token. Set APIFY_TOKEN in the environment; the Apify SDK and apify-client read it automatically (or pass it explicitly to new ApifyClient({ token })). Never hardcode the token — inject it via env var and validate at startup.
  • Access: Read and Grep the target repository so you can match the recommended layout against the code already on disk before proposing changes.

Instructions

  1. Pick the pattern. One scraper → Pattern 1. A staged workflow that discovers, scrapes, then cleans → Pattern 2. An app that consumes scraped data → Pattern 3.
  2. Grep the existing repo for apify, apify-client, and Actor.main to see what is already wired, so you extend rather than duplicate structure.
  3. Lay out the directory from the pattern's tree in references/architecture-patterns.md. Keep routing, extraction, and validation in separate modules.
  4. Add typed input validation with zod (see src/types.ts in the reference) so bad input fails fast at the Actor boundary instead of mid-crawl.
  5. Isolate every Apify call behind a service layer (Pattern 3) using the ApifyService class in references/implementation.md — the rest of the app never imports apify-client directly.
  6. Load configuration once at startup via loadConfig() and layer per-environment overrides on a single base object; validate required env vars before serving traffic.
  7. Expose an Apify health check so a bad token or platform outage surfaces before a user-facing scrape fails.

Output

Applying this skill produces an architecture, not a running command. Expect:

  • A recommended directory layout for the chosen pattern.
  • Skeleton TypeScript modules (main.ts, types.ts, service layer, config loader, health check).
  • A per-environment configuration strategy and an Apify health signal.
  • For pipelines, an orchestrator that reports per-stage item counts and total USD cost, e.g.:
=== Pipeline Summary ===
Discovered: 320 URLs
Scraped:    298 items
Clean:      271 items
Total cost: $0.4120

Error Handling

Issue Cause Solution
Circular dependencies Service imports service Use dependency injection
Missing config Env var not set Validate at startup with loadConfig()
Pipeline stage failure Actor crash mid-pipeline Add retry logic per stage
State management Tracking run status Use webhook handler + database
Run not ready error Fetching results before SUCCEEDED Poll getRunStatus or use a completion webhook

Examples

Standalone Actor entry point — the minimal skeleton; full file in references/architecture-patterns.md:

// src/main.ts
import { Actor } from 'apify';
import { CheerioCrawler } from 'crawlee';
import { router } from './routes/listing';
import { validateInput, ScraperInput } from './types';

await Actor.main(async () => {
  const input = validateInput(await Actor.getInput<ScraperInput>());
  const crawler = new CheerioCrawler({
    requestHandler: router,
    maxRequestsPerCrawl: input.maxItems ?? 100,
    maxConcurrency: input.concurrency ?? 10,
  });
  await crawler.run(input.startUrls.map(s => s.url));
});

Calling an Actor from an app — via the service layer:

const apify = new ApifyService(process.env.APIFY_TOKEN!);
const { runId } = await apify.startScrape(['https://example.com']);
const results = await apify.getResults<ProductOutput>(runId);

More: the multi-stage pipeline orchestrator and the full ApifyService class are in references/architecture-patterns.md and references/implementation.md. For multi-environment setup, see the companion apify-deploy-integration skill.

Resources

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/jeremylongshore-tons-of-skills-marketplace-apify-referen-45829e/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

jeremylongshore-tons-of-skills-marketplace-apify-referen-45829e.ocm.jsonjson
{
  "ocm": "1",
  "id": "jeremylongshore-tons-of-skills-marketplace-apify-referen-45829e",
  "kind": "skill",
  "name": "apify-reference-architecture",
  "description": "Production-grade architecture patterns for Apify-powered applications. Use when designing scraping infrastructure, building multi-Actor pipelines, or integrating Apify into a larger system architecture. Trigger with \"apify architecture\", \"apify best practices\", \"apify project structure\", \"scraping architecture\", \"apify system design\".",
  "publisher": "jeremylongshore",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "general"
    ],
    "tags": [
      "skill-md",
      "saas",
      "scraping",
      "automation",
      "apify",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Production-grade architecture patterns for Apify-powered applications. Use when designing scraping infrastructure, building multi-Actor pipelines, or integrating Apify into a larger system architecture. Trigger with \"apify architecture\", \"apify best practices\", \"apify project structure\", \"scraping architecture\", \"apify system design\"."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/jeremylongshore/tons-of-skills-marketplace",
      "path": "plugins/saas-packs/apify-pack/skills/apify-reference-architecture/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/jeremylongshore/tons-of-skills-marketplace/blob/HEAD/plugins/saas-packs/apify-pack/skills/apify-reference-architecture/SKILL.md",
      "key": "jeremylongshore/tons-of-skills-marketplace/plugins/saas-packs/apify-pack/skills/apify-reference-architecture/SKILL.md"
    },
    "compatibility": "Designed for Claude Code",
    "allowed_tools": [
      "Read,",
      "Grep"
    ],
    "license": "MIT"
  },
  "instructions": "# Apify Reference Architecture\n\n## Overview\n\nProduction-ready architecture patterns for applications built on Apify. Three patterns\nscale from a single scraper to a full-stack integration:\n\n1. **Standalone Actor** — one scraper deployed to the Apify platform.\n2. **Multi-Actor Pipeline** — a discover → scrape → transform chain of Actors.\n3. **Full-Stack Integration** — an application using Apify as a data source behind a service layer.\n\nThis skill helps you choose the right pattern, lay out the directory structure, and wire\nthe skeleton code. Full directory trees, diagrams, and code for every p",
  "cost": {
    "context_tokens": 1367
  }
}

Fetch it by URL: GET /api/v1/registry/jeremylongshore-tons-of-skills-marketplace-apify-referen-45829e/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.