# sebbekarlsson/fjb architecture

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

- Interactive diagram: https://gitdiagram.com/sebbekarlsson/fjb
- Repository: https://github.com/sebbekarlsson/fjb

## Overview

FJB is a native JavaScript bundler: a user supplies an entry file and output path, and the CLI drives compilation to produce a bundled file. The runtime includes lexical and syntactic analysis, AST transformation and emission, module handling, JSX/TypeScript support, plugins, and watch mode. The README documents these capabilities; sampled source confirms parser and visitor responsibilities and import-hook behavior. Several subsystem implementations were not sampled, so their internal connections are omitted rather than inferred.

Main entry points: [`src/parser.c`](https://github.com/sebbekarlsson/fjb/blob/master/src/parser.c) (Parser), [`src/visitor.c`](https://github.com/sebbekarlsson/fjb/blob/master/src/visitor.c) (AST visitor), [`src/fjb.c`](https://github.com/sebbekarlsson/fjb/blob/master/src/fjb.c) (Compiler coordinator), [`src/cmd.c`](https://github.com/sebbekarlsson/fjb/blob/master/src/cmd.c) (CLI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI and runtime"]
  node_cli["CLI<br/>[cmd.c]"]
  node_bundle["Bundle entry<br/>[bundle.c]"]
  node_compiler["Compiler coordinator<br/>[fjb.c]"]
end

subgraph group_language["Language processing"]
  node_lexer["Lexer<br/>[lexer.c]"]
  node_parser["Parser<br/>[parser.c]"]
  node_ast["AST model<br/>[AST.c]"]
  node_visitor["AST visitor<br/>[visitor.c]"]
  node_emitter["Code emitter<br/>[emit.c]"]
  node_jsx["JSX support<br/>[parse_jsx.c]"]
  node_typescript["TypeScript support<br/>[parse_typescript.c]"]
  node_evaluation["Evaluation<br/>[eval.c]"]
end

subgraph group_modules["Modules and extensions"]
  node_resolver["Import resolution<br/>[resolve.c]"]
  node_imported["Imported modules<br/>[imported.c]"]
  node_scss["SCSS import hook<br/>[before_import.c]"]
  node_hook_registry["Hook registry<br/>[register.c]"]
  node_source_hook["Source hook<br/>[source.c]"]
  node_plugins["Plugin system<br/>[plugin.c]"]
end

subgraph group_support["Runtime support"]
  node_watch["Watch mode<br/>[watch.c]"]
  node_environment["Compiler environment<br/>[env.c]"]
  node_io["File I/O<br/>[io.c]"]
  node_gc["AST memory<br/>[gc.c]"]
  node_lists["List utilities<br/>[list.c]"]
  node_tokens["Token model<br/>[token.c]"]
end

node_user(("Developer"))
node_output["Bundled output"]

node_user -->|"invokes"| node_cli
node_cli -->|"starts bundling"| node_bundle
node_bundle -.->|"delegates"| node_compiler
node_compiler -.->|"writes bundle"| node_output
node_lexer -->|"provides tokens"| node_parser
node_parser -->|"constructs"| node_ast
node_visitor -->|"uses"| node_emitter
node_visitor -->|"evaluates nodes"| node_evaluation
node_parser -->|"uses parser"| node_jsx
node_parser -->|"uses parser"| node_typescript
node_visitor -->|"resolves imports"| node_resolver
node_visitor -->|"tracks imports"| node_imported
node_visitor -->|"runs hooks"| node_hook_registry
node_scss -->|"sets transformed source"| node_source_hook
node_hook_registry -->|"registers hooks"| node_plugins
node_watch -.->|"rebuilds"| node_compiler
node_compiler -.->|"uses state"| node_environment
node_parser -->|"marks AST"| node_gc
node_parser -->|"consumes tokens"| node_tokens

click node_cli "https://github.com/sebbekarlsson/fjb/blob/master/src/cmd.c"
click node_bundle "https://github.com/sebbekarlsson/fjb/blob/master/src/bundle.c"
click node_compiler "https://github.com/sebbekarlsson/fjb/blob/master/src/fjb.c"
click node_lexer "https://github.com/sebbekarlsson/fjb/blob/master/src/lexer.c"
click node_parser "https://github.com/sebbekarlsson/fjb/blob/master/src/parser.c"
click node_ast "https://github.com/sebbekarlsson/fjb/blob/master/src/AST.c"
click node_visitor "https://github.com/sebbekarlsson/fjb/blob/master/src/visitor.c"
click node_emitter "https://github.com/sebbekarlsson/fjb/blob/master/src/emit.c"
click node_jsx "https://github.com/sebbekarlsson/fjb/blob/master/src/parse_jsx.c"
click node_typescript "https://github.com/sebbekarlsson/fjb/blob/master/src/parse_typescript.c"
click node_evaluation "https://github.com/sebbekarlsson/fjb/blob/master/src/eval.c"
click node_resolver "https://github.com/sebbekarlsson/fjb/blob/master/src/resolve.c"
click node_imported "https://github.com/sebbekarlsson/fjb/blob/master/src/imported.c"
click node_scss "https://github.com/sebbekarlsson/fjb/blob/master/src/hooks/before_import.c"
click node_hook_registry "https://github.com/sebbekarlsson/fjb/blob/master/src/hooks/register.c"
click node_source_hook "https://github.com/sebbekarlsson/fjb/blob/master/src/hooks/source.c"
click node_plugins "https://github.com/sebbekarlsson/fjb/blob/master/src/plugin.c"
click node_watch "https://github.com/sebbekarlsson/fjb/blob/master/src/watch.c"
click node_environment "https://github.com/sebbekarlsson/fjb/blob/master/src/env.c"
click node_io "https://github.com/sebbekarlsson/fjb/blob/master/src/io.c"
click node_gc "https://github.com/sebbekarlsson/fjb/blob/master/src/gc.c"
click node_lists "https://github.com/sebbekarlsson/fjb/blob/master/src/list.c"
click node_tokens "https://github.com/sebbekarlsson/fjb/blob/master/src/token.c"

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_cli,node_bundle,node_compiler toneBlue
class node_lexer,node_parser,node_ast,node_visitor,node_emitter,node_jsx,node_typescript,node_evaluation toneAmber
class node_resolver,node_imported,node_scss,node_hook_registry,node_source_hook,node_plugins toneMint
class node_watch,node_environment,node_io,node_gc,node_lists,node_tokens toneRose
class node_user,node_output toneIndigo
```

## Components

### CLI and runtime

- [CLI](https://github.com/sebbekarlsson/fjb/blob/master/src/cmd.c): `src/cmd.c`
- [Bundle entry](https://github.com/sebbekarlsson/fjb/blob/master/src/bundle.c): `src/bundle.c`
- [Compiler coordinator](https://github.com/sebbekarlsson/fjb/blob/master/src/fjb.c): `src/fjb.c`

### Language processing

- [Lexer](https://github.com/sebbekarlsson/fjb/blob/master/src/lexer.c): `src/lexer.c`
- [Parser](https://github.com/sebbekarlsson/fjb/blob/master/src/parser.c): `src/parser.c`
- [AST model](https://github.com/sebbekarlsson/fjb/blob/master/src/AST.c): `src/AST.c`
- [AST visitor](https://github.com/sebbekarlsson/fjb/blob/master/src/visitor.c): `src/visitor.c`
- [Code emitter](https://github.com/sebbekarlsson/fjb/blob/master/src/emit.c): `src/emit.c`
- [JSX support](https://github.com/sebbekarlsson/fjb/blob/master/src/parse_jsx.c): `src/parse_jsx.c`
- [TypeScript support](https://github.com/sebbekarlsson/fjb/blob/master/src/parse_typescript.c): `src/parse_typescript.c`
- [Evaluation](https://github.com/sebbekarlsson/fjb/blob/master/src/eval.c): `src/eval.c`

### Modules and extensions

- [Import resolution](https://github.com/sebbekarlsson/fjb/blob/master/src/resolve.c): `src/resolve.c`
- [Imported modules](https://github.com/sebbekarlsson/fjb/blob/master/src/imported.c): `src/imported.c`
- [SCSS import hook](https://github.com/sebbekarlsson/fjb/blob/master/src/hooks/before_import.c): `src/hooks/before_import.c`
- [Hook registry](https://github.com/sebbekarlsson/fjb/blob/master/src/hooks/register.c): `src/hooks/register.c`
- [Source hook](https://github.com/sebbekarlsson/fjb/blob/master/src/hooks/source.c): `src/hooks/source.c`
- [Plugin system](https://github.com/sebbekarlsson/fjb/blob/master/src/plugin.c): `src/plugin.c`

### Runtime support

- [Watch mode](https://github.com/sebbekarlsson/fjb/blob/master/src/watch.c): `src/watch.c`
- [Compiler environment](https://github.com/sebbekarlsson/fjb/blob/master/src/env.c): `src/env.c`
- [File I/O](https://github.com/sebbekarlsson/fjb/blob/master/src/io.c): `src/io.c`
- [AST memory](https://github.com/sebbekarlsson/fjb/blob/master/src/gc.c): `src/gc.c`
- [List utilities](https://github.com/sebbekarlsson/fjb/blob/master/src/list.c): `src/list.c`
- [Token model](https://github.com/sebbekarlsson/fjb/blob/master/src/token.c): `src/token.c`

### Other components

- **Developer**
- **Bundled output**

## Connections

- Developer → CLI: invokes (evidence: `README.md`)
- CLI → Bundle entry: starts bundling
- Bundle entry → Compiler coordinator: delegates
- Compiler coordinator → Bundled output: writes bundle
- Lexer → Parser: provides tokens (evidence: `src/parser.c`)
- Parser → AST model: constructs (evidence: `src/parser.c`)
- AST visitor → Code emitter: uses (evidence: `src/visitor.c`)
- AST visitor → Evaluation: evaluates nodes (evidence: `src/visitor.c`)
- Parser → JSX support: uses parser (evidence: `src/parser.c`)
- Parser → TypeScript support: uses parser (evidence: `src/parser.c`)
- AST visitor → Import resolution: resolves imports (evidence: `src/visitor.c`)
- AST visitor → Imported modules: tracks imports (evidence: `src/visitor.c`)
- AST visitor → Hook registry: runs hooks (evidence: `src/visitor.c`)
- SCSS import hook → Source hook: sets transformed source (evidence: `src/hooks/before_import.c`)
- Hook registry → Plugin system: registers hooks (evidence: `src/hooks/register.c`)
- Watch mode → Compiler coordinator: rebuilds
- Compiler coordinator → Compiler environment: uses state
- Parser → AST memory: marks AST (evidence: `src/parser.c`)
- Parser → Token model: consumes tokens (evidence: `src/parser.c`)
