This project is built as a robust, low-level building block for Git-based applications. It follows strict engineering standards to ensure it is the most reliable Git plumbing library in the JavaScript ecosystem.
The codebase is strictly partitioned into three layers:
Contains the business logic, entities, and value objects. It is pure and has zero dependencies on infrastructure or specific runtimes.
- Entities:
GitCommit,GitTree,GitBlob. - Value Objects:
GitSha,GitRef,GitFileMode,GitSignature. - Services:
CommandSanitizer(security),ExecutionOrchestrator(retry/backoff),GitErrorClassifier,GitPersistenceService,ByteMeasurer.
Functional interfaces that define how the domain interacts with the outside world.
CommandRunner: A functional port defined insrc/ports/. It enforces a strict contract: every command must return astdoutStreamand anexitPromise.
Core services (CommandSanitizer, ExecutionOrchestrator) are designed as injectable instances. This allows developers to:
- Provide custom sanitization rules.
- Inject mock orchestrators for testing failure modes.
- Extend the
GitErrorClassifierfor specialized error handling.
We use Zod as our single source of truth for validation.
- Schema Location: All schemas reside in
src/domain/schemas/. - Strict Enforcement: No Entity or Value Object can be instantiated with invalid data. This ensures that errors are caught at the boundary, before any shell process is spawned.
- JSON Schema Ready: The Zod schemas are designed to be easily exportable to standard JSON schemas for cross-system interoperability.
In version 2.0.0, we eliminated the "buffered" execution path in the infrastructure layer.
- Consistency: Every runner behaves exactly the same way.
- Memory Safety: Large outputs (like
cat-fileon a massive blob) never hit the heap unless explicitly requested viacollect(). - OOM Protection: The
collect()method enforces amaxByteslimit, preventing malicious or accidental memory exhaustion.
- One File = One Class: Every file in
src/represents a single logical concept. No "utils.js" or "types.js" dumping grounds. - Total JSDoc: 100% of the public API is documented with JSDoc, enabling excellent IDE intellisense and automated documentation generation.
- Immutability: All Value Objects are immutable. Operations that "change" a state (like
GitTree.addEntry) return a new instance. - No Magic Literals: Constants like the
Empty Tree SHA, default timeouts (120s), and buffer limits are exported from the port layer.
- Multi-Runtime CI: We don't just "test in Node". Our CI environment (via Docker Compose) runs the exact same test suite in Bun and Deno simultaneously.
- Tests as Spec: Our tests define the behavior of the system. A change in logic requires a change in the corresponding test to ensure the "red -> green" story is preserved.