# divyanshu0902/scriptc architecture

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

- Interactive diagram: https://gitdiagram.com/divyanshu0902/scriptc
- Repository: https://github.com/divyanshu0902/scriptc

## Overview

scriptc is a TypeScript/JavaScript compiler that turns checked programs and their imported packages into native executables or WebAssembly, with a native runtime for supported Node APIs. The principal workflow is: invoke the CLI, load and resolve the TypeScript program, lower it into the compiler IR, generate target code, then link a standalone result. Coverage reporting, diagnostics, FFI, and runtime integrations are meaningful product branches. Some links are documented only at product level or represented by unsampled directories, so those edges are dashed rather than asserted as inspected calls.

Main entry points: [`packages/compiler/src/frontend/pipeline.ts`](https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/frontend/pipeline.ts) (Frontend Pipeline), [`packages/compiler/src/frontend/lowering/lowerer.ts`](https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/frontend/lowering/lowerer.ts) (Frontend Lowering), [`packages/compiler/src/backend/native-codegen.ts`](https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/backend/native-codegen.ts) (Backend Orchestration), [`packages/runtime/src`](https://github.com/divyanshu0902/scriptc/tree/main/packages/runtime/src) (Native Runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI and Frontend"]
  node_cli["CLI Commands<br/>[main.ts]"]
  node_frontend["Frontend Pipeline<br/>[pipeline.ts]"]
  node_ts7["TypeScript Services<br/>[adapter.ts]"]
  node_resolution["Program Resolution<br/>[resolve.ts]"]
end

subgraph group_middle["Lowering and IR"]
  node_lowering["Frontend Lowering<br/>[lowerer.ts]"]
  node_array_lowering["Array Pipelines<br/>[array-pipelines.ts]"]
  node_collection_lowering["Collection Ingestion"]
  node_ir["Compiler IR<br/>[ir.ts]"]
end

subgraph group_output["Code Generation"]
  node_optimization["LLVM Optimizations"]
  node_backend["Backend Orchestration<br/>[native-codegen.ts]"]
  node_native_codegen["LLVM Code Generator<br/>[main.cpp]"]
  node_linking["Native Linking<br/>[linker.ts]"]
end

subgraph group_runtime["Runtime and Integrations"]
  node_runtime["Native Runtime"]
  node_node_api["Node API Bridge<br/>[scr_node_bridge.cc]"]
  node_workers["Worker Runtime<br/>[scr_worker.c]"]
end

subgraph group_capabilities["Product Capabilities"]
  node_diagnostics["Diagnostics<br/>[diagnostic.ts]"]
  node_coverage["Coverage Reports<br/>[report.ts]"]
  node_wasm["WebAssembly Support<br/>[wasm-modules.ts]"]
  node_ffi["Native FFI<br/>[ffi-manifest.ts]"]
end

node_user(("Developer"))

node_user -->|"runs commands"| node_cli
node_cli -->|"invokes compiler"| node_frontend
node_frontend -->|"loads program services"| node_ts7
node_frontend -->|"resolves imports"| node_resolution
node_frontend -->|"reports issues"| node_diagnostics
node_frontend -.->|"lowers program"| node_lowering
node_lowering -->|"uses transforms"| node_array_lowering
node_lowering -->|"ingests collections"| node_collection_lowering
node_lowering -->|"builds IR"| node_ir
node_ir -.->|"feeds backend"| node_optimization
node_optimization -.->|"provides LLVM emission"| node_backend
node_backend -.->|"requests code generation"| node_native_codegen
node_backend -.->|"prepares native link"| node_linking
node_linking -.->|"includes runtime"| node_runtime
node_runtime -->|"bridges Node APIs"| node_node_api
node_runtime -.->|"runs worker threads"| node_workers
node_user -->|"checks compatibility"| node_coverage
node_frontend -.->|"analyzes program"| node_coverage
node_backend -.->|"emits WebAssembly"| node_wasm
node_frontend -.->|"supports native FFI"| node_ffi

click node_cli "https://github.com/divyanshu0902/scriptc/blob/main/packages/cli/src/main.ts"
click node_frontend "https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/frontend/pipeline.ts"
click node_ts7 "https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/frontend/ts7/adapter.ts"
click node_resolution "https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/frontend/resolve.ts"
click node_diagnostics "https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/diagnostics/diagnostic.ts"
click node_lowering "https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/frontend/lowering/lowerer.ts"
click node_array_lowering "https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/frontend/lowering/containers/array-pipelines.ts"
click node_collection_lowering "https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/frontend/lowering/collection-ingestion.ts"
click node_ir "https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/ir/ir.ts"
click node_optimization "https://github.com/divyanshu0902/scriptc/tree/main/packages/compiler/src/backend/llvm"
click node_backend "https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/backend/native-codegen.ts"
click node_native_codegen "https://github.com/divyanshu0902/scriptc/blob/main/native/llvm-codegen/src/main.cpp"
click node_linking "https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/backend/linker.ts"
click node_runtime "https://github.com/divyanshu0902/scriptc/tree/main/packages/runtime/src"
click node_node_api "https://github.com/divyanshu0902/scriptc/blob/main/packages/libnode-common/bridge/scr_node_bridge.cc"
click node_workers "https://github.com/divyanshu0902/scriptc/blob/main/packages/runtime/src/scr_worker.c"
click node_coverage "https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/coverage/report.ts"
click node_wasm "https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/backend/llvm/wasm-modules.ts"
click node_ffi "https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/ffi/ffi-manifest.ts"

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_frontend,node_ts7,node_resolution toneBlue
class node_lowering,node_array_lowering,node_collection_lowering,node_ir toneAmber
class node_optimization,node_backend,node_native_codegen,node_linking toneMint
class node_runtime,node_node_api,node_workers toneRose
class node_diagnostics,node_coverage,node_wasm,node_ffi,node_user toneIndigo
```

## Components

### CLI and Frontend

- [CLI Commands](https://github.com/divyanshu0902/scriptc/blob/main/packages/cli/src/main.ts): `packages/cli/src/main.ts`
- [Frontend Pipeline](https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/frontend/pipeline.ts): `packages/compiler/src/frontend/pipeline.ts`
- [TypeScript Services](https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/frontend/ts7/adapter.ts): `packages/compiler/src/frontend/ts7/adapter.ts`
- [Program Resolution](https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/frontend/resolve.ts): `packages/compiler/src/frontend/resolve.ts`

### Lowering and IR

- [Frontend Lowering](https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/frontend/lowering/lowerer.ts): `packages/compiler/src/frontend/lowering/lowerer.ts`
- [Array Pipelines](https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/frontend/lowering/containers/array-pipelines.ts): `packages/compiler/src/frontend/lowering/containers/array-pipelines.ts`
- [Collection Ingestion](https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/frontend/lowering/collection-ingestion.ts): `packages/compiler/src/frontend/lowering/collection-ingestion.ts`
- [Compiler IR](https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/ir/ir.ts): `packages/compiler/src/ir/ir.ts`

### Code Generation

- [LLVM Optimizations](https://github.com/divyanshu0902/scriptc/tree/main/packages/compiler/src/backend/llvm): `packages/compiler/src/backend/llvm`
- [Backend Orchestration](https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/backend/native-codegen.ts): `packages/compiler/src/backend/native-codegen.ts`
- [LLVM Code Generator](https://github.com/divyanshu0902/scriptc/blob/main/native/llvm-codegen/src/main.cpp): `native/llvm-codegen/src/main.cpp`
- [Native Linking](https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/backend/linker.ts): `packages/compiler/src/backend/linker.ts`

### Runtime and Integrations

- [Native Runtime](https://github.com/divyanshu0902/scriptc/tree/main/packages/runtime/src): `packages/runtime/src`
- [Node API Bridge](https://github.com/divyanshu0902/scriptc/blob/main/packages/libnode-common/bridge/scr_node_bridge.cc): `packages/libnode-common/bridge/scr_node_bridge.cc`
- [Worker Runtime](https://github.com/divyanshu0902/scriptc/blob/main/packages/runtime/src/scr_worker.c): `packages/runtime/src/scr_worker.c`

### Product Capabilities

- [Diagnostics](https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/diagnostics/diagnostic.ts): `packages/compiler/src/diagnostics/diagnostic.ts`
- [Coverage Reports](https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/coverage/report.ts): `packages/compiler/src/coverage/report.ts`
- [WebAssembly Support](https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/backend/llvm/wasm-modules.ts): `packages/compiler/src/backend/llvm/wasm-modules.ts`
- [Native FFI](https://github.com/divyanshu0902/scriptc/blob/main/packages/compiler/src/ffi/ffi-manifest.ts): `packages/compiler/src/ffi/ffi-manifest.ts`

### Other components

- **Developer**

## Connections

- Developer → CLI Commands: runs commands (evidence: `README.md`)
- CLI Commands → Frontend Pipeline: invokes compiler (evidence: `packages/cli/src/main.ts`)
- Frontend Pipeline → TypeScript Services: loads program services (evidence: `packages/compiler/src/frontend/pipeline.ts`)
- Frontend Pipeline → Program Resolution: resolves imports (evidence: `packages/compiler/src/frontend/pipeline.ts`)
- Frontend Pipeline → Diagnostics: reports issues (evidence: `packages/compiler/src/frontend/pipeline.ts`)
- Frontend Pipeline → Frontend Lowering: lowers program (evidence: `packages/compiler/src/frontend/pipeline.ts`)
- Frontend Lowering → Array Pipelines: uses transforms (evidence: `packages/compiler/src/frontend/lowering/containers/array-pipelines.ts`)
- Frontend Lowering → Collection Ingestion: ingests collections (evidence: `packages/compiler/src/frontend/lowering/collection-ingestion.ts`)
- Frontend Lowering → Compiler IR: builds IR (evidence: `packages/compiler/src/frontend/lowering/array-values.ts`)
- Compiler IR → LLVM Optimizations: feeds backend (evidence: `packages/compiler/src/backend/llvm/local-union-storage.ts`)
- LLVM Optimizations → Backend Orchestration: provides LLVM emission
- Backend Orchestration → LLVM Code Generator: requests code generation
- Backend Orchestration → Native Linking: prepares native link
- Native Linking → Native Runtime: includes runtime
- Native Runtime → Node API Bridge: bridges Node APIs (evidence: `README.md`)
- Native Runtime → Worker Runtime: runs worker threads (evidence: `packages/runtime/src/scr_worker.c`)
- Developer → Coverage Reports: checks compatibility (evidence: `README.md`)
- Frontend Pipeline → Coverage Reports: analyzes program
- Backend Orchestration → WebAssembly Support: emits WebAssembly
- Frontend Pipeline → Native FFI: supports native FFI
