How barbajs/barba works
Project Type & Purpose
• This is an open-source, monorepo JavaScript/TypeScript library (Barba.js) managed with Lerna.
• Its purpose is to provide a core engine for page-transition management in websites (SPA-like behavior) and expose an extensible plugin system (css, prefetch, router).
High-Level Architectural Components
A. Monorepo Root
• Lerna orchestrator (lerna.json)
• CI/CD (CircleCI config)
• Linters & formatters (.eslintrc.js, prettier.config.js, tsconfig.json)
• Documentation site (documentation/ with Handlebars theme)
• Test runners (jest.config.js, cypress.config.ts)
B. Core Package (packages/core)
• Core engine entry (src/index.ts, src/core.ts)
• Modules folder (Cache, Error, Headers, Ignore, Logger, Prevent, Store, Transitions, Views)
• Hook system & lifecycle definitions (src/defs, src/hooks.ts)
• Utilities & polyfills (src/utils, src/polyfills)
• Examples (packages/core/__web__)
• Tests: unit (__tests__), integration (__e2e__)
C. Plugin Packages
1. CSS Plugin (packages/css)
• Extends core with CSS state & prefixing APIs
• src/css.ts and defs
• Examples (__web__)
• Tests (__tests__, __e2e__)
2. Prefetch Plugin (packages/prefetch)
• Adds idle‐time prefetching capabilities
• src/prefetch.ts, polyfills
3. Router Plugin (packages/router)
• Exposes routing logic to navigate and intercept links
• src/router.ts, defs
D. External Ecosystem
• npm registry (package.json publishing)
• Consumers’ websites (user code integrates with Barba API)
• Browser environment (DOM, history API)
Relationships & Data Flows
• Modules process events, manipulate DOM, manage state, handle errors, etc. (intra-core flow).
• Tests and examples instantiate Core+plugins in an isolated environment (Cypress or Jest).
• CI/CD pipelines run linters, unit tests, E2E tests, and on success publish packages via Lerna.
Architectural Patterns & Principles
• Monorepo with Lerna for multi‐package management.
• Plugin architecture: core engine + opt-in extensions.
• Event‐driven & hook system for lifecycle management.
• Progressive enhancement: polyfills directory.
• Separation of concerns: modules encapsulate cache, error handling, view management.
• Test pyramid: unit tests → integration/E2E tests.