$ show pastelsky/bundlephobia
Bundlephobia is a production web application that analyzes the bundle-size cost of npm packages by performing real builds with a bundler. It exposes a public REST API (endpoints for size, exports, history, trends, similar packages) and a rich Next.js frontend with interactive visualizations (treemaps, trends charts, export analysis). The architecture is microservice-oriented: a main Koa/Next.js server orchestrates requests, a Fastify build-service executes package builds with timeout and profiling, a cache-service backed by Firebase and LRU memory stores results, and an installation-service deduplicates npm installs with lease-based concurrency control. The system also includes a separate Kotlin/Gradle sub-project for JVM package analysis (Maven, Android AAR/JAR) and a curated similar-packages catalog maintained via automated AI research workflows. External dependencies include npm registry, GitHub API, Algolia, Contentful, and Amplitude analytics. Key design patterns include a language-agnostic analysis gateway with adapter registration, a middleware pipeline for request processing (caching, rate-limiting, error handling), typed service contracts using Zod schemas, and a queue service with priority and cancellation. The codebase demonstrates strong engineering practices with extensive unit and e2e tests, custom Oxlint lint rules enforcing internal TypeScript standards, and CI/CD automation for package recommendation updates and JVM releases. While primarily an application, the repository also contains data-research elements: a curated similar-packages catalog with weighted tags, trends analysis merging npm downloads and GitHub stars, and automated library research scripts that propose catalog updates. These are integrated into the application's recommendation features.
The LLM identified 5 files worth highlighting for reuse:
A standalone, dependency-injected runtime diagnostics module that collects process metrics (RSS, heap stats, event-loop delay, GC counts) and writes snapshots to disk with cooldown and disk-space guards. It is designed for easy extraction into other Node.js services, requiring only a logger and filesystem implementation.
A store for deduplicating concurrent package installations by exact version key, with lease-based expiration, persistence of metadata for recovery after restart, and sweeping of stale directories. It can be reused in any service that needs to coordinate expensive, idempotent operations across multiple workers.
A two-tier cache combining in-memory LRU with Firebase Realtime Database persistence, supporting typed result validation via Zod schemas, latest-built version lookups, and fallback read keys. The pattern of memory-first with remote fallback and schema validation is applicable to any latency-sensitive service.
A gateway that registers language-specific adapters (JavaScript, Java, Kotlin) implementing a common interface for package resolution, analysis, and export size computation. This pattern allows adding new package ecosystems without modifying the core pipeline, and can be extracted as a generic multi-backend analysis framework.
Zod schemas defining the cache payload contracts for package size and exports data, used by both the cache service and server clients to validate data integrity across service boundaries. These schemas can be extracted as a standalone contract library for any microservice ecosystem requiring type-safe communication.