brain/wiki/pieces-engine/pieces.md
The metadata catalog of automation integrations ("pieces") — each a named integration like @activepieces/piece-gmail providing actions and triggers. Stored in piece_metadata and served from an in-memory pieceCache rebuilt from the DB on startup and refreshed via pub/sub.
piece_metadata (PieceMetadataEntity) — unique on (name, version, platformId); platformId null = official, set = custom piece for that platform. actions/triggers are JSON maps (each may carry an optional outputSchema).pieceMetadataService — list / getOrThrow / listVersions / create / delete / registry; owns cache interactions.pieceInstallService.installPiece — saves archive, dispatches an EXECUTE_METADATA engine job to extract metadata, then stores it.pieceSyncService.sync — upserts official pieces from the bundled registry file./v1/pieces: list, :name get, :name/versions, POST /options (dynamic dropdown eval on a worker), POST / (platformAdmin — install custom piece), POST /sync, DELETE /:id.OFFICIAL (bundled) or CUSTOM (platform-installed).REGISTRY (NPM) or ARCHIVE (uploaded tarball; archiveId FKs to file).fields, itemLabel); set by the piece author, consumed by the builder's Smart Output Viewer and data selector. Opt-in and non-breaking.resolveVisibility (ee/pieces/filters/piece-filtering-utils.ts), which returns a VisibilityPolicy or null on CE / when platformId/projectId is nil (callers treat null as no filtering). The policy is derived from the project's piece set (via project.pieceSetId, falling back to the platform Default).isToolSearchEnabled(); no-op otherwise.delete removes all versions sharing the name on that platform, and only for CUSTOM pieces the caller owns.Entry point: pieceModule, the Fastify plugin registered in packages/server/api/src/app/app.ts that mounts every /v1/pieces route.
packages/server/api/src/app/pieces/metadata/ — controller, service, TypeORM entity, and the pub/sub-invalidated piece-cache.tspackages/server/api/src/app/pieces/ — community-piece-module.ts (POST /v1/pieces install), piece-install-service.ts, piece-sync-service.tspackages/server/api/src/app/ee/pieces/filters/piece-filtering-utils.ts — resolveVisibility and the EE/Cloud VisibilityPolicypackages/web/src/features/pieces/api/ — frontend HTTP clientpackages/web/src/features/pieces/hooks/ — React Query hooks for listing, piece model, options, and output schemapackages/web/src/features/pieces/components/ — PieceIcon, PieceIconList, PieceSelectorSearch, InstallPieceDialogpackages/pieces/framework/src/lib/output-schema.ts — OutputSchema / OutputSchemaField / FieldFormat typesPaths verified 2026-07-17.