# anjeleee/bnf-ast-converter architecture

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

- Interactive diagram: https://gitdiagram.com/anjeleee/bnf-ast-converter
- Repository: https://github.com/anjeleee/bnf-ast-converter

## Overview

BNFgen is an educational compiler syntax analyzer and tree visualizer. A user enters C++-subset source in the web UI; the client submits it through its API module to FastAPI, which invokes the parser. The parser tokenizes input, validates it with LL(1) parsing, and produces BNF derivations plus CST/AST results. The client then displays trees, grammar information, and metrics, with graph/chip and ASCII tree views. Backend and frontend calls are evidenced by the README and sampled source; internal parser stages follow documented capabilities where implementation detail was not excerpted.

Main entry points: [`frontend/js/app.js`](https://github.com/anjeleee/bnf-ast-converter/blob/main/frontend/js/app.js) (UI coordinator), [`backend/parser.py`](https://github.com/anjeleee/bnf-ast-converter/blob/main/backend/parser.py) (LL(1) parser), [`backend/main.py`](https://github.com/anjeleee/bnf-ast-converter/blob/main/backend/main.py) (FastAPI endpoints), [`frontend/index.html`](https://github.com/anjeleee/bnf-ast-converter/blob/main/frontend/index.html) (Source editor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web interface"]
  node_editor["Source editor<br/>[index.html]"]
  node_coordinator["UI coordinator<br/>[app.js]"]
  node_api_client["API client<br/>[api.js]"]
end

subgraph group_server["API service"]
  node_fastapi["FastAPI endpoints<br/>[main.py]"]
end

subgraph group_compiler["Compiler analysis"]
  node_lexer["Tokenizer<br/>[lexer.py]"]
  node_parser["LL&#40;1&#41; parser<br/>[parser.py]"]
  node_bnf["BNF derivations<br/>[parser.py]"]
  node_cst["Concrete syntax tree<br/>[parser.py]"]
  node_ast["Abstract syntax tree<br/>[parser.py]"]
end

subgraph group_visualization["Results and grammar"]
  node_grammar["Grammar presets<br/>[grammar.js]"]
  node_tree_utils["Tree utilities<br/>[treeUtils.js]"]
  node_tree_view["Tree and ASCII views<br/>[app.js]"]
  node_metrics["Tree metrics<br/>[treeUtils.js]"]
end

node_user(("User"))
node_browser(("Web browser"))

node_user -->|"enters source"| node_editor
node_editor -->|"handles input"| node_coordinator
node_coordinator -->|"requests parse"| node_api_client
node_api_client -->|"POSTs source"| node_fastapi
node_fastapi -->|"calls parse_code"| node_parser
node_parser -->|"tokenizes source"| node_lexer
node_parser -->|"generates derivations"| node_bnf
node_parser -->|"builds tree"| node_cst
node_parser -->|"synthesizes tree"| node_ast
node_fastapi -->|"returns JSON"| node_coordinator
node_coordinator -->|"loads rules"| node_grammar
node_coordinator -->|"uses tree helpers"| node_tree_utils
node_coordinator -->|"renders results"| node_tree_view
node_coordinator -->|"calculates metrics"| node_metrics
node_browser -.->|"displays interface"| node_coordinator

click node_editor "https://github.com/anjeleee/bnf-ast-converter/blob/main/frontend/index.html"
click node_coordinator "https://github.com/anjeleee/bnf-ast-converter/blob/main/frontend/js/app.js"
click node_api_client "https://github.com/anjeleee/bnf-ast-converter/blob/main/frontend/js/api.js"
click node_fastapi "https://github.com/anjeleee/bnf-ast-converter/blob/main/backend/main.py"
click node_lexer "https://github.com/anjeleee/bnf-ast-converter/blob/main/backend/lexer.py"
click node_parser "https://github.com/anjeleee/bnf-ast-converter/blob/main/backend/parser.py"
click node_bnf "https://github.com/anjeleee/bnf-ast-converter/blob/main/backend/parser.py"
click node_cst "https://github.com/anjeleee/bnf-ast-converter/blob/main/backend/parser.py"
click node_ast "https://github.com/anjeleee/bnf-ast-converter/blob/main/backend/parser.py"
click node_grammar "https://github.com/anjeleee/bnf-ast-converter/blob/main/frontend/js/grammar.js"
click node_tree_utils "https://github.com/anjeleee/bnf-ast-converter/blob/main/frontend/js/treeUtils.js"
click node_tree_view "https://github.com/anjeleee/bnf-ast-converter/blob/main/frontend/js/app.js"
click node_metrics "https://github.com/anjeleee/bnf-ast-converter/blob/main/frontend/js/treeUtils.js"

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_editor,node_coordinator,node_api_client,node_user,node_browser toneBlue
class node_fastapi toneAmber
class node_lexer,node_parser,node_bnf,node_cst,node_ast toneMint
class node_grammar,node_tree_utils,node_tree_view,node_metrics toneRose
```

## Components

### Web interface

- [Source editor](https://github.com/anjeleee/bnf-ast-converter/blob/main/frontend/index.html): `frontend/index.html`
- [UI coordinator](https://github.com/anjeleee/bnf-ast-converter/blob/main/frontend/js/app.js): `frontend/js/app.js`
- [API client](https://github.com/anjeleee/bnf-ast-converter/blob/main/frontend/js/api.js): `frontend/js/api.js`

### API service

- [FastAPI endpoints](https://github.com/anjeleee/bnf-ast-converter/blob/main/backend/main.py): `backend/main.py`

### Compiler analysis

- [Tokenizer](https://github.com/anjeleee/bnf-ast-converter/blob/main/backend/lexer.py): `backend/lexer.py`
- [LL(1) parser](https://github.com/anjeleee/bnf-ast-converter/blob/main/backend/parser.py): `backend/parser.py`
- [BNF derivations](https://github.com/anjeleee/bnf-ast-converter/blob/main/backend/parser.py): `backend/parser.py`
- [Concrete syntax tree](https://github.com/anjeleee/bnf-ast-converter/blob/main/backend/parser.py): `backend/parser.py`
- [Abstract syntax tree](https://github.com/anjeleee/bnf-ast-converter/blob/main/backend/parser.py): `backend/parser.py`

### Results and grammar

- [Grammar presets](https://github.com/anjeleee/bnf-ast-converter/blob/main/frontend/js/grammar.js): `frontend/js/grammar.js`
- [Tree utilities](https://github.com/anjeleee/bnf-ast-converter/blob/main/frontend/js/treeUtils.js): `frontend/js/treeUtils.js`
- [Tree and ASCII views](https://github.com/anjeleee/bnf-ast-converter/blob/main/frontend/js/app.js): `frontend/js/app.js`
- [Tree metrics](https://github.com/anjeleee/bnf-ast-converter/blob/main/frontend/js/treeUtils.js): `frontend/js/treeUtils.js`

### Other components

- **User**
- **Web browser**

## Connections

- User → Source editor: enters source (evidence: `README.md`)
- Source editor → UI coordinator: handles input (evidence: `frontend/js/app.js`)
- UI coordinator → API client: requests parse (evidence: `frontend/js/app.js`)
- API client → FastAPI endpoints: POSTs source (evidence: `frontend/js/api.js`)
- FastAPI endpoints → LL(1) parser: calls parse_code (evidence: `backend/main.py`)
- LL(1) parser → Tokenizer: tokenizes source (evidence: `backend/parser.py`)
- LL(1) parser → BNF derivations: generates derivations (evidence: `README.md`)
- LL(1) parser → Concrete syntax tree: builds tree (evidence: `README.md`)
- LL(1) parser → Abstract syntax tree: synthesizes tree (evidence: `README.md`)
- FastAPI endpoints → UI coordinator: returns JSON (evidence: `README.md`)
- UI coordinator → Grammar presets: loads rules (evidence: `frontend/js/app.js`)
- UI coordinator → Tree utilities: uses tree helpers (evidence: `frontend/js/app.js`)
- UI coordinator → Tree and ASCII views: renders results (evidence: `frontend/js/app.js`)
- UI coordinator → Tree metrics: calculates metrics (evidence: `frontend/js/app.js`)
- Web browser → UI coordinator: displays interface (evidence: `README.md`)
