# migu3873378373737/ng architecture

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

- Interactive diagram: https://gitdiagram.com/migu3873378373737/ng
- Repository: https://github.com/migu3873378373737/ng

## Overview

NG is a C11 language runtime and CLI. Its main workflow reads a .ng program, prepares an AST through the Dynamic V preparation path, then executes it with the native interpreter; the CLI also offers syntax checking, compilation to cache, and an interactive REPL. The README documents additional capabilities including package management, JSON/SQLite, formatting and diagnostics, HTTP, and language interoperability. Edges reflect the shown CLI calls, indexed source references, or explicit README statements; several library-internal connections remain unshown.

Main entry points: [`src/main.c`](https://github.com/migu3873378373737/ng/blob/main/src/main.c) (NG CLI), [`src/ng_dynamicv.c`](https://github.com/migu3873378373737/ng/blob/main/src/ng_dynamicv.c) (Dynamic V Preparation), [`src/interpreter.c`](https://github.com/migu3873378373737/ng/blob/main/src/interpreter.c) (Interpreter), [`src/ng_native_module.c`](https://github.com/migu3873378373737/ng/blob/main/src/ng_native_module.c) (Native Module Registry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_language["Language Front End"]
  node_lexer["Lexer<br/>[lexer.c]"]
  node_parser["Parser<br/>[parser.c]"]
  node_ast["AST<br/>[ast.c]"]
end

subgraph group_runtime["Execution Runtime"]
  node_interpreter["Interpreter<br/>[interpreter.c]"]
  node_values["Values and Scopes<br/>[value.c]"]
  node_runtime_core["Runtime Tables<br/>[runtime.c]"]
  node_native_modules["Native Module Registry<br/>[ng_native_module.c]"]
end

subgraph group_optimization["Dynamic V"]
  node_dynamicv["Dynamic V Preparation<br/>[ng_dynamicv.c]"]
  node_ir["Intermediate IR<br/>[ng_ir.c]"]
  node_optimizer["Lua Optimizer<br/>[ng_lua_optimizer.c]"]
  node_cache[("N3 AST Cache<br/>[ng_n3cache.c]")]
end

subgraph group_libraries["Native Capabilities"]
  node_json["JSON Module<br/>[ng_json.c]"]
  node_sqlite[("SQLite Module<br/>[ng_sqlite.c]")]
  node_printing["Formatting and Print<br/>[ng_print.c]"]
  node_http["HTTP Server<br/>[ng_http.c]"]
  node_http_client["HTTP Client<br/>[ng_http_client.c]"]
  node_interop["Language Interop<br/>[ng_interop.c]"]
  node_net_libs["Network and Lua Backend<br/>[ng_net_libs.c]"]
end

subgraph group_interfaces["CLI and Integrations"]
  node_cli["NG CLI<br/>[main.c]"]
  node_repl["Interactive REPL<br/>[repl.c]"]
  node_dependency["Package Manager<br/>[ng_dependency.c]"]
end

node_user(("Programmer"))

node_user -->|"runs commands"| node_cli
node_cli -->|"starts REPL"| node_repl
node_cli -->|"dispatches package commands"| node_dependency
node_cli -->|"prepares program"| node_dynamicv
node_cli -->|"runs AST"| node_interpreter
node_cli -->|"initializes modules"| node_native_modules
node_dynamicv -->|"uses lexer"| node_lexer
node_dynamicv -->|"uses parser"| node_parser
node_dynamicv -->|"loads or stores AST"| node_cache
node_dynamicv -->|"uses IR"| node_ir
node_dynamicv -->|"uses optimizer"| node_optimizer
node_parser -->|"consumes tokens"| node_lexer
node_parser -->|"builds AST"| node_ast
node_interpreter -->|"uses scopes"| node_runtime_core
node_interpreter -->|"evaluates values"| node_values
node_interpreter -->|"resolves modules"| node_native_modules
node_user -->|"uses JSON module"| node_json
node_user -->|"uses SQLite module"| node_sqlite
node_user -->|"uses formatting"| node_printing
node_user -.->|"uses HTTP"| node_http
node_user -.->|"uses HTTP client"| node_http_client
node_user -->|"uses interop module"| node_interop
node_cli -->|"selects Lua backend"| node_net_libs
node_dependency -->|"downloads packages"| node_http_client
node_native_modules -.->|"registers capabilities"| node_json
node_native_modules -.->|"registers capabilities"| node_sqlite

click node_cli "https://github.com/migu3873378373737/ng/blob/main/src/main.c"
click node_repl "https://github.com/migu3873378373737/ng/blob/main/src/repl.c"
click node_dependency "https://github.com/migu3873378373737/ng/blob/main/src/ng_dependency.c"
click node_lexer "https://github.com/migu3873378373737/ng/blob/main/src/lexer.c"
click node_parser "https://github.com/migu3873378373737/ng/blob/main/src/parser.c"
click node_ast "https://github.com/migu3873378373737/ng/blob/main/src/ast.c"
click node_interpreter "https://github.com/migu3873378373737/ng/blob/main/src/interpreter.c"
click node_values "https://github.com/migu3873378373737/ng/blob/main/src/value.c"
click node_runtime_core "https://github.com/migu3873378373737/ng/blob/main/src/runtime.c"
click node_dynamicv "https://github.com/migu3873378373737/ng/blob/main/src/ng_dynamicv.c"
click node_ir "https://github.com/migu3873378373737/ng/blob/main/src/ng_ir.c"
click node_optimizer "https://github.com/migu3873378373737/ng/blob/main/src/ng_lua_optimizer.c"
click node_cache "https://github.com/migu3873378373737/ng/blob/main/src/ng_n3cache.c"
click node_json "https://github.com/migu3873378373737/ng/blob/main/src/ng_json.c"
click node_sqlite "https://github.com/migu3873378373737/ng/blob/main/src/ng_sqlite.c"
click node_printing "https://github.com/migu3873378373737/ng/blob/main/src/ng_print.c"
click node_http "https://github.com/migu3873378373737/ng/blob/main/src/ng_http.c"
click node_http_client "https://github.com/migu3873378373737/ng/blob/main/src/ng_http_client.c"
click node_interop "https://github.com/migu3873378373737/ng/blob/main/src/ng_interop.c"
click node_net_libs "https://github.com/migu3873378373737/ng/blob/main/src/ng_net_libs.c"
click node_native_modules "https://github.com/migu3873378373737/ng/blob/main/src/ng_native_module.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_lexer,node_parser,node_ast toneBlue
class node_interpreter,node_values,node_runtime_core,node_native_modules toneAmber
class node_dynamicv,node_ir,node_optimizer,node_cache toneMint
class node_json,node_sqlite,node_printing,node_http,node_http_client,node_interop,node_net_libs toneRose
class node_cli,node_repl,node_dependency,node_user toneIndigo
```

## Components

### Language Front End

- [Lexer](https://github.com/migu3873378373737/ng/blob/main/src/lexer.c): `src/lexer.c`
- [Parser](https://github.com/migu3873378373737/ng/blob/main/src/parser.c): `src/parser.c`
- [AST](https://github.com/migu3873378373737/ng/blob/main/src/ast.c): `src/ast.c`

### Execution Runtime

- [Interpreter](https://github.com/migu3873378373737/ng/blob/main/src/interpreter.c): `src/interpreter.c`
- [Values and Scopes](https://github.com/migu3873378373737/ng/blob/main/src/value.c): `src/value.c`
- [Runtime Tables](https://github.com/migu3873378373737/ng/blob/main/src/runtime.c): `src/runtime.c`
- [Native Module Registry](https://github.com/migu3873378373737/ng/blob/main/src/ng_native_module.c): `src/ng_native_module.c`

### Dynamic V

- [Dynamic V Preparation](https://github.com/migu3873378373737/ng/blob/main/src/ng_dynamicv.c): `src/ng_dynamicv.c`
- [Intermediate IR](https://github.com/migu3873378373737/ng/blob/main/src/ng_ir.c): `src/ng_ir.c`
- [Lua Optimizer](https://github.com/migu3873378373737/ng/blob/main/src/ng_lua_optimizer.c): `src/ng_lua_optimizer.c`
- [N3 AST Cache](https://github.com/migu3873378373737/ng/blob/main/src/ng_n3cache.c): `src/ng_n3cache.c`

### Native Capabilities

- [JSON Module](https://github.com/migu3873378373737/ng/blob/main/src/ng_json.c): `src/ng_json.c`
- [SQLite Module](https://github.com/migu3873378373737/ng/blob/main/src/ng_sqlite.c): `src/ng_sqlite.c`
- [Formatting and Print](https://github.com/migu3873378373737/ng/blob/main/src/ng_print.c): `src/ng_print.c`
- [HTTP Server](https://github.com/migu3873378373737/ng/blob/main/src/ng_http.c): `src/ng_http.c`
- [HTTP Client](https://github.com/migu3873378373737/ng/blob/main/src/ng_http_client.c): `src/ng_http_client.c`
- [Language Interop](https://github.com/migu3873378373737/ng/blob/main/src/ng_interop.c): `src/ng_interop.c`
- [Network and Lua Backend](https://github.com/migu3873378373737/ng/blob/main/src/ng_net_libs.c): `src/ng_net_libs.c`

### CLI and Integrations

- [NG CLI](https://github.com/migu3873378373737/ng/blob/main/src/main.c): `src/main.c`
- [Interactive REPL](https://github.com/migu3873378373737/ng/blob/main/src/repl.c): `src/repl.c`
- [Package Manager](https://github.com/migu3873378373737/ng/blob/main/src/ng_dependency.c): `src/ng_dependency.c`

### Other components

- **Programmer**

## Connections

- Programmer → NG CLI: runs commands
- NG CLI → Interactive REPL: starts REPL (evidence: `src/main.c`)
- NG CLI → Package Manager: dispatches package commands (evidence: `src/main.c`)
- NG CLI → Dynamic V Preparation: prepares program (evidence: `src/main.c`)
- NG CLI → Interpreter: runs AST (evidence: `src/main.c`)
- NG CLI → Native Module Registry: initializes modules (evidence: `src/main.c`)
- Dynamic V Preparation → Lexer: uses lexer (evidence: `src/ng_dynamicv.c`)
- Dynamic V Preparation → Parser: uses parser (evidence: `src/ng_dynamicv.c`)
- Dynamic V Preparation → N3 AST Cache: loads or stores AST (evidence: `src/ng_dynamicv.c`)
- Dynamic V Preparation → Intermediate IR: uses IR (evidence: `src/ng_dynamicv.c`)
- Dynamic V Preparation → Lua Optimizer: uses optimizer (evidence: `src/ng_dynamicv.c`)
- Parser → Lexer: consumes tokens (evidence: `src/parser.c`)
- Parser → AST: builds AST (evidence: `src/parser.c`)
- Interpreter → Runtime Tables: uses scopes (evidence: `src/interpreter.c`)
- Interpreter → Values and Scopes: evaluates values (evidence: `src/interpreter.c`)
- Interpreter → Native Module Registry: resolves modules (evidence: `src/interpreter.c`)
- Programmer → JSON Module: uses JSON module
- Programmer → SQLite Module: uses SQLite module
- Programmer → Formatting and Print: uses formatting
- Programmer → HTTP Server: uses HTTP
- Programmer → HTTP Client: uses HTTP client
- Programmer → Language Interop: uses interop module
- NG CLI → Network and Lua Backend: selects Lua backend (evidence: `src/main.c`)
- Package Manager → HTTP Client: downloads packages (evidence: `src/ng_dependency.c`)
- Native Module Registry → JSON Module: registers capabilities
- Native Module Registry → SQLite Module: registers capabilities
