# yassinebenaid/bunster architecture

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

- Interactive diagram: https://gitdiagram.com/yassinebenaid/bunster
- Repository: https://github.com/yassinebenaid/bunster

## Overview

Bunster compiles shell scripts into standalone Go-based binaries. The main workflow is CLI build → module preparation and source parsing → static analysis → Go generation → Go toolchain output; generated programs use Bunster’s runtime rather than an external shell. The parser is split across lexical, syntax, and AST stages, while runtime capabilities include flags, environment files, and embedded assets. Module/package resolution is also a documented product capability. Relationships involving unsampled implementation details are omitted or marked unverified.

Main entry points: [`builder/builder.go`](https://github.com/yassinebenaid/bunster/blob/master/builder/builder.go) (Build orchestration), [`runtime/shell.go`](https://github.com/yassinebenaid/bunster/blob/master/runtime/shell.go) (Shell runtime), [`cmd/bunster/main.go`](https://github.com/yassinebenaid/bunster/blob/master/cmd/bunster/main.go) (Bunster CLI), [`parser/parser.go`](https://github.com/yassinebenaid/bunster/blob/master/parser/parser.go) (Shell parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Shell frontend"]
  node_lexer["Lexer<br/>[lexer.go]"]
  node_parser["Shell parser<br/>[parser.go]"]
  node_ast["Shell AST<br/>[statement.go]"]
  node_analyser["Static analyser<br/>[analyser.go]"]
end

subgraph group_compile["Compilation"]
  node_cli["Bunster CLI<br/>[main.go]"]
  node_builder["Build orchestration<br/>[builder.go]"]
  node_generator["Go generator<br/>[generator.go]"]
  node_ir["Go instruction IR<br/>[ir.go]"]
end

subgraph group_modules["Modules"]
  node_module_manager["Module resolution<br/>[mod.go]"]
end

subgraph group_runtime["Generated runtime"]
  node_runtime_shell["Shell runtime<br/>[shell.go]"]
  node_runtime_flags["Flag parsing<br/>[flag.go]"]
  node_runtime_env["Environment loading<br/>[loadenv.go]"]
  node_runtime_embed["Embedded assets<br/>[embed.go]"]
end

node_developer(("Script author"))
node_go_toolchain["Go toolchain"]
node_binary["Compiled binary"]

node_developer -->|"invokes"| node_cli
node_cli -->|"builds via"| node_builder
node_cli -->|"creates lexer"| node_lexer
node_cli -->|"parses for AST"| node_parser
node_lexer -->|"supplies tokens"| node_parser
node_parser -->|"produces"| node_ast
node_builder -->|"parses sources"| node_parser
node_builder -->|"checks scripts"| node_analyser
node_builder -.->|"resolves modules"| node_module_manager
node_analyser -->|"validates"| node_ast
node_builder -.->|"generates Go"| node_generator
node_generator -->|"creates instructions"| node_ir
node_ir -->|"emits runtime calls"| node_runtime_shell
node_builder -->|"compiles generated code"| node_go_toolchain
node_go_toolchain -->|"produces"| node_binary
node_binary -->|"runs with"| node_runtime_shell
node_runtime_shell -.->|"uses flag parser"| node_runtime_flags
node_runtime_shell -.->|"supports env files"| node_runtime_env
node_runtime_shell -.->|"supports embedded assets"| node_runtime_embed

click node_cli "https://github.com/yassinebenaid/bunster/blob/master/cmd/bunster/main.go"
click node_lexer "https://github.com/yassinebenaid/bunster/blob/master/lexer/lexer.go"
click node_parser "https://github.com/yassinebenaid/bunster/blob/master/parser/parser.go"
click node_ast "https://github.com/yassinebenaid/bunster/blob/master/ast/statement.go"
click node_analyser "https://github.com/yassinebenaid/bunster/blob/master/analyser/analyser.go"
click node_builder "https://github.com/yassinebenaid/bunster/blob/master/builder/builder.go"
click node_generator "https://github.com/yassinebenaid/bunster/blob/master/generator/generator.go"
click node_ir "https://github.com/yassinebenaid/bunster/blob/master/ir/ir.go"
click node_module_manager "https://github.com/yassinebenaid/bunster/blob/master/builder/mod.go"
click node_runtime_shell "https://github.com/yassinebenaid/bunster/blob/master/runtime/shell.go"
click node_runtime_flags "https://github.com/yassinebenaid/bunster/blob/master/runtime/flag.go"
click node_runtime_env "https://github.com/yassinebenaid/bunster/blob/master/runtime/builtin/loadenv.go"
click node_runtime_embed "https://github.com/yassinebenaid/bunster/blob/master/runtime/builtin/embed.go"

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_lexer,node_parser,node_ast,node_analyser toneBlue
class node_cli,node_builder,node_generator,node_ir toneAmber
class node_module_manager toneMint
class node_runtime_shell,node_runtime_flags,node_runtime_env,node_runtime_embed toneRose
class node_developer,node_go_toolchain,node_binary toneIndigo
```

## Components

### Shell frontend

- [Lexer](https://github.com/yassinebenaid/bunster/blob/master/lexer/lexer.go): `lexer/lexer.go`
- [Shell parser](https://github.com/yassinebenaid/bunster/blob/master/parser/parser.go): `parser/parser.go`
- [Shell AST](https://github.com/yassinebenaid/bunster/blob/master/ast/statement.go): `ast/statement.go`
- [Static analyser](https://github.com/yassinebenaid/bunster/blob/master/analyser/analyser.go): `analyser/analyser.go`

### Compilation

- [Bunster CLI](https://github.com/yassinebenaid/bunster/blob/master/cmd/bunster/main.go): `cmd/bunster/main.go`
- [Build orchestration](https://github.com/yassinebenaid/bunster/blob/master/builder/builder.go): `builder/builder.go`
- [Go generator](https://github.com/yassinebenaid/bunster/blob/master/generator/generator.go): `generator/generator.go`
- [Go instruction IR](https://github.com/yassinebenaid/bunster/blob/master/ir/ir.go): `ir/ir.go`

### Modules

- [Module resolution](https://github.com/yassinebenaid/bunster/blob/master/builder/mod.go): `builder/mod.go`

### Generated runtime

- [Shell runtime](https://github.com/yassinebenaid/bunster/blob/master/runtime/shell.go): `runtime/shell.go`
- [Flag parsing](https://github.com/yassinebenaid/bunster/blob/master/runtime/flag.go): `runtime/flag.go`
- [Environment loading](https://github.com/yassinebenaid/bunster/blob/master/runtime/builtin/loadenv.go): `runtime/builtin/loadenv.go`
- [Embedded assets](https://github.com/yassinebenaid/bunster/blob/master/runtime/builtin/embed.go): `runtime/builtin/embed.go`

### Other components

- **Script author**
- **Go toolchain**
- **Compiled binary**

## Connections

- Script author → Bunster CLI: invokes (evidence: `cmd/bunster/main.go`)
- Bunster CLI → Build orchestration: builds via (evidence: `cmd/bunster/main.go`)
- Bunster CLI → Lexer: creates lexer (evidence: `cmd/bunster/main.go`)
- Bunster CLI → Shell parser: parses for AST (evidence: `cmd/bunster/main.go`)
- Lexer → Shell parser: supplies tokens (evidence: `parser/parser.go`)
- Shell parser → Shell AST: produces (evidence: `parser/parser.go`)
- Build orchestration → Shell parser: parses sources (evidence: `builder/builder.go`)
- Build orchestration → Static analyser: checks scripts (evidence: `builder/builder.go`)
- Build orchestration → Module resolution: resolves modules
- Static analyser → Shell AST: validates (evidence: `analyser/analyser.go`)
- Build orchestration → Go generator: generates Go
- Go generator → Go instruction IR: creates instructions (evidence: `generator/generator.go`)
- Go instruction IR → Shell runtime: emits runtime calls (evidence: `ir/ir.go`)
- Build orchestration → Go toolchain: compiles generated code
- Go toolchain → Compiled binary: produces
- Compiled binary → Shell runtime: runs with
- Shell runtime → Flag parsing: uses flag parser
- Shell runtime → Environment loading: supports env files
- Shell runtime → Embedded assets: supports embedded assets
