# ndxbn/bun architecture

> Architecture diagram of the GitHub repository ndxbn/bun, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ndxbn/bun
- Repository: https://github.com/ndxbn/bun

## Overview

1. **Project shape**
   - This is a **single Bun + TypeScript package** generated from a template, with a clear split between:
     - a **public library entrypoint**,
     - a **CLI entrypoint**,
     - a **server entrypoint**,
     - and a small **application-specific implementation area** under `app/`.

2. **Public API boundary**
   - `src/index.ts` is the package-facing entrypoint.
   - The README explicitly says this is the file to import from other projects, so it acts as the **stable external surface** of the repository.

3. **Executable boundaries**
   - `src/cli.ts` is the command-line bootstrap used by `bun cli`.
   - `src/server.ts` is the server bootstrap used by `bun start`.
   - These are not the business logic themselves; they are the **runtime adapters** that wire execution into the underlying app code.

4. **Application layer**
   - `app/ConsoleApplication.ts` is the main named application module in the tree.
   - That suggests the repo keeps **domain/workflow logic separate from bootstrapping**, with `app/` serving as the place for application behavior while `src/` contains entrypoints and exported interfaces.

5. **Execution flows**
   - There are two primary runtime paths:
     - **CLI flow:** user runs `bun cli ...` → `src/cli.ts` → console application logic.
     - **Server flow:** user runs `bun start` → `src/server.ts` → server runtime and request handling.
   - Both flows likely share code through the package internals rather than duplicating logic.

6. **Testing strategy**
   - `src/main.test.ts` and `src/server.large.test.ts` indicate the repo uses **Bun’s built-in test runner** with both:
     - a general/main test suite,
     - and a larger server-focused suite.
   - This implies the server path is tested separately from lighter unit-style coverage.

7. **Developer tooling**
   - The project is configured around **Bun**, **Biome**, and **Lefthook**.
   - `biome.json` handles formatting/linting, and `.lefthook.yaml` suggests git hooks are used to enforce code quality locally before CI.

8. **Environment and typing**
   - `.env.example` and `.env.test` show the app is environment-driven, even if the exact variables are not visible here.
   - `src/env.d.ts` indicates typed environment access is part of the codebase, so configuration is treated as a first-class boundary.

9. **Containerization and local orchestration**
   - `Dockerfile` is for production packaging.
   - `compose.yaml` supports development dependencies and local middleware startup.
   - `.github/lint.compose.yaml` suggests Docker Compose is also used to run lint-related tooling in a reproducible environment.

10. **Automation and release pipeline**
   - GitHub Actions cover **linting, coverage, Docker publishing, and security checks**.
   - This means the repo is set up as a shippable artifact, not just a local app or library.

11. **Documentation boundary**
   - `README.md` is the developer-facing onboarding guide.
   - `docs/` contains additional documentation, including Japanese-localized docs under `docs/ja`, so documentation is maintained as a separate concern from code.

12. **What is not present**
   - There is no visible database layer, queue consumer, message broker, or cloud-service adapter in the tree.
   - Architecturally, this looks like a **small self-contained Bun application/library template** with CLI and server entrypoints rather than a distributed system.

13. **How to draw it**
   - A good diagram would show:
     - external users entering through **CLI** or **server**,
     - both reaching a shared **application/core layer**,
     - the **public package export** exposed via `src/index.ts`,
     - and separate surrounding boxes for **tests**, **tooling**, **Docker/Compose**, and **CI/CD**.

Main entry points: [`src/index.ts`](https://github.com/ndxbn/bun/blob/main/src/index.ts) (Package API), [`src/cli.ts`](https://github.com/ndxbn/bun/blob/main/src/cli.ts) (CLI Boot), [`src/server.ts`](https://github.com/ndxbn/bun/blob/main/src/server.ts) (Server Boot), [`src/main.test.ts`](https://github.com/ndxbn/bun/blob/main/src/main.test.ts) (Main Test)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_entrypoints["Entrypoints"]
  node_n_src_index["Package API<br/>public entrypoint<br/>[index.ts]"]
  node_n_src_cli["CLI Boot<br/>runtime adapter<br/>[cli.ts]"]
  node_n_src_server["Server Boot<br/>runtime adapter<br/>[server.ts]"]
end

subgraph group_g_app["Application"]
  node_n_app_console["Console App<br/>application logic"]
  node_n_src_env["Typed Env<br/>config boundary<br/>[env.d.ts]"]
end

subgraph group_g_tests["Tests"]
  node_n_src_main_test["Main Test<br/>test suite<br/>[main.test.ts]"]
  node_n_src_server_test["Server Test<br/>integration test"]
end

subgraph group_g_tooling["Tooling"]
  node_n_scripts_dev["Dev Script<br/>developer script<br/>[dev.ts]"]
  node_n_biome["Biome<br/>lint/format config<br/>[biome.json]"]
  node_n_lefthook["Lefthook<br/>git hook config<br/>[.lefthook.yaml]"]
  node_n_compose["Compose<br/>local orchestration<br/>[compose.yaml]"]
end

subgraph group_g_delivery["Delivery"]
  node_n_dockerfile["Dockerfile<br/>container build"]
  node_n_readme["README<br/>documentation<br/>[README.md]"]
  node_n_docs["Docs<br/>documentation tree<br/>[README.md]"]
  node_n_github_lint_compose["Lint Compose<br/>ci support<br/>[lint.compose.yaml]"]
  node_n_github_lint["Lint CI<br/>workflow<br/>[lint.yaml]"]
  node_n_github_coverage["Coverage CI<br/>workflow<br/>[coverage.yaml]"]
  node_n_github_coveralls["Coveralls<br/>workflow"]
  node_n_github_docker["Docker Publish<br/>workflow<br/>[docker-push.yaml]"]
  node_n_github_security["Security CI<br/>workflow<br/>[security.yml]"]
end

node_n_src_cli -->|"uses"| node_n_app_console
node_n_src_server -->|"shares core"| node_n_app_console
node_n_src_index -->|"exports"| node_n_app_console
node_n_src_cli -->|"reads config"| node_n_src_env
node_n_src_server -->|"reads config"| node_n_src_env
node_n_src_main_test -.->|"tests"| node_n_src_cli
node_n_src_main_test -.->|"tests"| node_n_src_index
node_n_src_server_test -.->|"tests"| node_n_src_server
node_n_scripts_dev -->|"drives"| node_n_src_cli
node_n_biome -->|"formats"| node_n_src_index
node_n_lefthook -->|"enforces"| node_n_biome
node_n_compose -.->|"mirrors"| node_n_github_lint_compose
node_n_dockerfile -->|"packages"| node_n_src_server
node_n_readme -->|"documents"| node_n_src_index
node_n_docs -.->|"extends"| node_n_readme
node_n_github_lint -->|"runs"| node_n_biome
node_n_github_coverage -->|"runs"| node_n_src_main_test
node_n_github_coveralls -.->|"publishes"| node_n_github_coverage
node_n_github_docker -->|"builds"| node_n_dockerfile
node_n_github_security -.->|"checks"| node_n_src_index

click node_n_src_index "https://github.com/ndxbn/bun/blob/main/src/index.ts"
click node_n_src_cli "https://github.com/ndxbn/bun/blob/main/src/cli.ts"
click node_n_src_server "https://github.com/ndxbn/bun/blob/main/src/server.ts"
click node_n_app_console "https://github.com/ndxbn/bun/blob/main/app/ConsoleApplication.ts"
click node_n_src_env "https://github.com/ndxbn/bun/blob/main/src/env.d.ts"
click node_n_src_main_test "https://github.com/ndxbn/bun/blob/main/src/main.test.ts"
click node_n_src_server_test "https://github.com/ndxbn/bun/blob/main/src/server.large.test.ts"
click node_n_scripts_dev "https://github.com/ndxbn/bun/blob/main/scripts/dev.ts"
click node_n_biome "https://github.com/ndxbn/bun/blob/main/biome.json"
click node_n_lefthook "https://github.com/ndxbn/bun/blob/main/.lefthook.yaml"
click node_n_compose "https://github.com/ndxbn/bun/blob/main/compose.yaml"
click node_n_dockerfile "https://github.com/ndxbn/bun/tree/main/Dockerfile"
click node_n_readme "https://github.com/ndxbn/bun/blob/main/README.md"
click node_n_docs "https://github.com/ndxbn/bun/blob/main/docs/README.md"
click node_n_github_lint_compose "https://github.com/ndxbn/bun/blob/main/.github/lint.compose.yaml"
click node_n_github_lint "https://github.com/ndxbn/bun/blob/main/.github/workflows/lint.yaml"
click node_n_github_coverage "https://github.com/ndxbn/bun/blob/main/.github/workflows/coverage.yaml"
click node_n_github_coveralls "https://github.com/ndxbn/bun/blob/main/.github/workflows/coverage.coveralls.yaml"
click node_n_github_docker "https://github.com/ndxbn/bun/blob/main/.github/workflows/docker-push.yaml"
click node_n_github_security "https://github.com/ndxbn/bun/blob/main/.github/workflows/security.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_src_index,node_n_src_cli,node_n_src_server toneBlue
class node_n_app_console,node_n_src_env toneAmber
class node_n_src_main_test,node_n_src_server_test toneMint
class node_n_scripts_dev,node_n_biome,node_n_lefthook,node_n_compose toneRose
class node_n_dockerfile,node_n_readme,node_n_docs,node_n_github_lint_compose,node_n_github_lint,node_n_github_coverage,node_n_github_coveralls,node_n_github_docker,node_n_github_security toneIndigo
```

## Components

### Entrypoints

Public package surface and runtime bootstraps

- [Package API](https://github.com/ndxbn/bun/blob/main/src/index.ts): public entrypoint · Stable import surface for consumers · `src/index.ts`
- [CLI Boot](https://github.com/ndxbn/bun/blob/main/src/cli.ts): runtime adapter · Bun CLI entrypoint · `src/cli.ts`
- [Server Boot](https://github.com/ndxbn/bun/blob/main/src/server.ts): runtime adapter · Bun server entrypoint · `src/server.ts`

### Application

Shared application logic

- [Console App](https://github.com/ndxbn/bun/blob/main/app/ConsoleApplication.ts): application logic · Main application workflow and command handling · `app/ConsoleApplication.ts`
- [Typed Env](https://github.com/ndxbn/bun/blob/main/src/env.d.ts): config boundary · Typed environment declarations · `src/env.d.ts`

### Tests

Bun test suites

- [Main Test](https://github.com/ndxbn/bun/blob/main/src/main.test.ts): test suite · General Bun test coverage · `src/main.test.ts`
- [Server Test](https://github.com/ndxbn/bun/blob/main/src/server.large.test.ts): integration test · Larger server-focused test coverage · `src/server.large.test.ts`

### Tooling

Formatting, hooks, scripts, and container orchestration

- [Dev Script](https://github.com/ndxbn/bun/blob/main/scripts/dev.ts): developer script · Local development helper · `scripts/dev.ts`
- [Biome](https://github.com/ndxbn/bun/blob/main/biome.json): lint/format config · Formatting and linting rules · `biome.json`
- [Lefthook](https://github.com/ndxbn/bun/blob/main/.lefthook.yaml): git hook config · Local pre-commit and pre-push automation · `.lefthook.yaml`
- [Compose](https://github.com/ndxbn/bun/blob/main/compose.yaml): local orchestration · Development and tooling services · `compose.yaml`

### Delivery

CI, packaging, and documentation

- [Dockerfile](https://github.com/ndxbn/bun/tree/main/Dockerfile): container build · Production image definition · `Dockerfile`
- [README](https://github.com/ndxbn/bun/blob/main/README.md): documentation · Primary onboarding and usage guide · `README.md`
- [Docs](https://github.com/ndxbn/bun/blob/main/docs/README.md): documentation tree · Additional documentation and localized guides · `docs/README.md`
- [Lint Compose](https://github.com/ndxbn/bun/blob/main/.github/lint.compose.yaml): ci support · Compose file for reproducible lint execution · `.github/lint.compose.yaml`
- [Lint CI](https://github.com/ndxbn/bun/blob/main/.github/workflows/lint.yaml): workflow · Automated lint checks · `.github/workflows/lint.yaml`
- [Coverage CI](https://github.com/ndxbn/bun/blob/main/.github/workflows/coverage.yaml): workflow · Coverage reporting pipeline · `.github/workflows/coverage.yaml`
- [Coveralls](https://github.com/ndxbn/bun/blob/main/.github/workflows/coverage.coveralls.yaml): workflow · Coverage publishing integration · `.github/workflows/coverage.coveralls.yaml`
- [Docker Publish](https://github.com/ndxbn/bun/blob/main/.github/workflows/docker-push.yaml): workflow · Container image publishing pipeline · `.github/workflows/docker-push.yaml`
- [Security CI](https://github.com/ndxbn/bun/blob/main/.github/workflows/security.yml): workflow · Security checks and automation · `.github/workflows/security.yml`

## Connections

- CLI Boot → Console App: uses · CLI bootstrap delegates to console application logic
- Server Boot → Console App: shares core · Server runtime reuses shared application behavior
- Package API → Console App: exports · Package API exposes the shared implementation surface
- CLI Boot → Typed Env: reads config · CLI path depends on typed environment access
- Server Boot → Typed Env: reads config · Server path depends on typed environment access
- Main Test → CLI Boot: tests · General suite covers the CLI/runtime boundary
- Main Test → Package API: tests · General suite covers the public package surface
- Server Test → Server Boot: tests · Server-focused suite covers request/runtime behavior
- Dev Script → CLI Boot: drives · Development helper likely launches the CLI workflow
- Biome → Package API: formats · Code style applies across the package
- Lefthook → Biome: enforces · Git hooks likely run formatting and lint checks
- Compose → Lint Compose: mirrors · Local orchestration supports reproducible lint tooling
- Dockerfile → Server Boot: packages · Container image is built around the server runtime
- README → Package API: documents · README points consumers to the package entrypoint
- Docs → README: extends · Additional docs expand on the main guide
- Lint CI → Biome: runs · CI lint workflow enforces repository style
- Coverage CI → Main Test: runs · Coverage pipeline executes the test suite
- Coveralls → Coverage CI: publishes · Coveralls workflow consumes coverage output
- Docker Publish → Dockerfile: builds · Workflow publishes the container image
- Security CI → Package API: checks · Security automation guards the shipped package
