算法艺术创作
algorithmic-art
通过代码和可调参数创作生成艺术与交互式视觉效果。
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 architecture. Trigger with "apify architecture", "apify best practices", "apify project structure", "scraping architecture", "apify system design".
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
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". allowed-tools: Read, Grep version: 1.5.0 license: MIT author: Jeremy Longshore jeremy@intentsolutions.io tags:
Production-ready architecture patterns for applications built on Apify. Three patterns scale from a single scraper to a full-stack integration:
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.
>=18, TypeScript, and the Apify CLI (npm i -g apify-cli).apify + crawlee (inside an Actor), apify-client (calling Actors from an app), zod (input validation).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.Read and Grep the target repository so you can match the recommended
layout against the code already on disk before proposing changes.Grep the existing repo for apify, apify-client, and Actor.main to see what
is already wired, so you extend rather than duplicate structure.zod (see src/types.ts in the reference) so bad
input fails fast at the Actor boundary instead of mid-crawl.ApifyService
class in references/implementation.md — the rest of the
app never imports apify-client directly.loadConfig() and layer per-environment
overrides on a single base object; validate required env vars before serving traffic.Applying this skill produces an architecture, not a running command. Expect:
main.ts, types.ts, service layer, config loader, health check).=== Pipeline Summary ===
Discovered: 320 URLs
Scraped: 298 items
Clean: 271 items
Total cost: $0.4120
| 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 |
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.