Packages Architecture Codemap
This document provides a structural overview of the packages architecture in the AI Primitives Hub pnpm workspace.
Package Dependency Graph
graph TD
subgraph ext["apps/vscode-extension"]
ext_desc["VS Code extension - marketplace, tree view, commands"]
end
subgraph cli["@ai-primitives-hub/cli"]
cli_desc["CLI Interface - Clipanion-based command line tool"]
end
subgraph app["@ai-primitives-hub/app"]
app_desc["Application Layer - orchestration, install, registry, SDK surface"]
end
subgraph infra["@ai-primitives-hub/infra"]
infra_desc["Infrastructure Layer - adapters, GitHub, harvest, search, storage, writers"]
end
subgraph core["@ai-primitives-hub/core"]
core_desc["Domain Layer - types, interfaces, ports - no package deps"]
end
ext --> app
ext --> infra
ext --> core
cli --> app
cli --> core
cli --> infra
app --> core
app --> infra
infra --> core
Package Details
@ai-primitives-hub/core (Domain Layer)
Purpose: Core domain types and port interfaces with minimal external dependencies.
Dependencies:
js-yaml(schema parsing and YAML utilities)semver(version parsing and constraints)
Key Modules:
domain/- Domain types and business logicbundle/- Bundle types (BundleManifest,BundleRef,HarvestedFile,BundleProvider)collection/- Collection types and validationdiscovery/- Discovery typeshub/- Hub configuration types and validationinstall/- Installation types (Target,Installable,CopilotFileType, layout, transforms)primitive/- Primitive typesregistry/- Registry configuration types, guards, and settingsscaffold/- Scaffolding typesskill/- Skill validationsource/- Source typessource-id.ts- Source ID utilitieserrors.ts/registry-error.ts- Domain errors
ports/- Port interfaces for external implementationsfilesystem.ts,http.ts,github-api.ts,clock.ts,process-runner.tsbundle-downloader.ts,bundle-extractor.ts,source-adapter.ts,source-resolver.tstarget-writer.ts,layout-config-loader.ts,resource-transformer.tsapp-storage.ts(universal XDG-based storage abstraction)registry-operations.ts,update-notifier.ts,update-store.ts,telemetry.ts
public/- Public APIs and schemasschemas/- JSON schemas (collection.schema.json, etc.)
Exports:
SCHEMA_DIR- Path to the schema directoryCOLLECTION_SCHEMA- Embedded collection schema JSON
Design Principle: Pure domain layer with no dependencies on other packages.
@ai-primitives-hub/infra (Infrastructure Layer)
Purpose: Infrastructure adapters for external systems and shared services.
Dependencies:
@ai-primitives-hub/core(workspace:*)adm-zip(ZIP extraction)archiver(ZIP creation)js-yaml(YAML parsing)@elastic/elasticsearch(optional telemetry transport)
Key Modules:
adapters/- Source adapters (LocalAdapter,GitHubAdapter,AwesomeCopilotAdapter,ApmAdapter,SkillsAdapter, local variants)auth/- Token providers (GhCliTokenProvider,StaticTokenProvider)clock/-SystemClockimplementationdownloaders/- Bundle downloadersextractors/- Bundle extraction (AdmZipBundleExtractor)fs/-FileSystemport adapterharvest/- Bundle discovery and harvesting- Bundle providers, tree enumerators,
Harvester,HubHarvester blob-cache.ts,etag-store.ts,progress-log.ts,integrity.ts,default-paths.ts
- Bundle providers, tree enumerators,
http/-NodeHttpClientand GitHub host helpershub/- Hub config parsingprocess/-NodeProcessRunnerimplementationresolvers/- Path resolution helpersscaffolding/-TemplateEngineand template filessearch/- BM25 search engine,PrimitiveIndex, tokenizer, tuningstorage/- Index storage utilitiesstores/- JSON lockfile, target-state, and layout-config storestelemetry/- Telemetry and optional Elasticsearch transporttransports/- Telemetry transport abstractionswriters/- Per-target file writing (FileTreeTargetWriter) anddefault-layouts.json
Exports:
TEMPLATE_ROOT/TEMPLATE_PATHS- Template directory pathsdefaultLayouts- Built-in target layoutsNodeHttpClient,FileSystem,SystemClock,GitHubApiClient- Concrete adapters
Design Principle: Infrastructure implementations depend only on core domain types and ports.
@ai-primitives-hub/app (Application Layer)
Purpose: Use-case orchestration and the public SDK surface until a dedicated SDK package is needed.
Dependencies:
@ai-primitives-hub/core(workspace:*)@ai-primitives-hub/infra(workspace:*)js-yaml(YAML parsing)
Key Modules:
collection/- Collection reading and validationcontext-detection/- Repository context detectiondiscovery/- Discovery orchestrationinstall/- Installation orchestrationinstall-bundle.ts,uninstall-bundle.ts,pipeline.tslayout-resolver.ts- Layout configuration resolution
registry/- Registry management (hub, profile, activation, user config paths)search/- Search orchestrationtransform/- Multi-target content transforms (kiro-transformer, windsurf/devin, claude-code)writers/- Application-level writersstores/- Application-level storesupdate/- Update orchestration
Design Principle: Application layer orchestrates infrastructure adapters for business use cases and exposes the public SDK surface.
@ai-primitives-hub/cli (CLI Layer)
Purpose: CLI interface for end users using the Clipanion framework.
Dependencies:
@ai-primitives-hub/app(workspace:*)@ai-primitives-hub/core(workspace:*)@ai-primitives-hub/infra(workspace:*)clipanion(CLI framework — pinned to4.0.0-rc.4)inquirer(interactive prompts)archiver(ZIP creation)semver(version management)typanion(validation)js-yaml(YAML parsing)
Key Modules:
commands/- CLI command implementations- Collection commands (
collection-create,collection-validate,collection-list,collection-affected) - Primitive scaffolding (
prompt-create,instruction-create,agent-create,skill-create,skill-new,skill-validate,plugin-create,hook-create) - Bundle commands (
bundle-build,bundle-manifest) - Hub commands (
hub add/list/use/remove/create/sync/refresh) - Source commands (
source add/list/remove) - Profile commands (
profile list/show/activate/deactivate/current/create/edit/publish) - Target commands (
target add/list/remove/types) - Index commands (
index build/harvest/search/shortlist/export/stats/report/eval/bench) - Install commands (
install,uninstall,update,apply) - Utility commands (
init,status,doctor,explain,discover,config get/list,plugins list,version compute,completion)
- Collection commands (
framework/- CLI framework abstractionscommand-class.ts- Command base classerror.ts- Error handlingoutput.ts- Output formattingcontext.ts- I/O abstraction
validate.ts- Collection validation utilitiescollections.ts- Collection utilitiesskills.ts- Skill utilitiescli.ts- CLI entry pointmain.ts- Main entry point
Binary: ai-primitives-hub
Design Principle: CLI layer provides thin, user-facing commands that delegate all business logic to app.
apps/vscode-extension (VS Code Extension)
Purpose: VS Code extension delivering the AI Primitives Hub marketplace, tree view, and IDE commands.
Dependencies:
@ai-primitives-hub/app(workspace:*)@ai-primitives-hub/core(workspace:*)@ai-primitives-hub/infra(workspace:*)vscodeAPIs
Key Modules:
src/commands/- VS Code command handlerssrc/services/- Extension-specific services (being migrated toappvia strangler fig)src/ui/- Marketplace webview and tree viewsrc/storage/- Persistent state managementsrc/adapters/- Source-specific adapters
Design Principle: The extension is a delivery mechanism; business logic is shared through app/core/infra.
Layering Principles
- Domain Layer (core): No dependencies on other packages. Pure types and interfaces.
- Infrastructure Layer (infra): Depends only on core. Implements external integrations.
- Application Layer (app): Depends on core and infra. Orchestrates business logic and serves as the public SDK surface.
- CLI Layer (cli): Depends on core, infra, and app. Provides user interface.
- VS Code Extension (apps/vscode-extension): Depends on core, infra, and app. Provides IDE integration.
Cross-Package Boundaries
The architecture enforces clear boundaries:
- Template paths are exported from
@ai-primitives-hub/infraviaTEMPLATE_PATHS - Default layouts are exported from
@ai-primitives-hub/infraviadefaultLayouts - Schema paths are exported from
@ai-primitives-hub/coreviaSCHEMA_DIR COLLECTION_SCHEMAis embedded in@ai-primitives-hub/corefor single-executable apps- No hardcoded relative paths across package boundaries
- Each package has its own build process with resource copying as needed
See Also
- Clean Architecture — Clean Architecture principles and how they apply to AI Primitives Hub
- System Context — External relationships and user personas
- Container Diagram — High-level containers and technology choices
- Component Diagrams — Detailed component views