# sogocze/jails architecture

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

- Interactive diagram: https://gitdiagram.com/sogocze/jails
- Repository: https://github.com/sogocze/jails

## Overview

#### Purpose and Entry Points
Jails is an experimental Language Server Protocol (LSP) implementation for Jai. Its native server starts in `server/main.jai`; build orchestration and release/VS Code development modes are defined in `build.jai`. The optional editor client is a VS Code extension rooted at `vscode_extension/src/extension.ts`.

#### LSP Transport and Dispatch
`server/lsp_interface.jai` defines the LSP-facing interface and request/notification handling. `server/rpc.jai` implements the JSON-RPC transport boundary between an editor client and the native server. `server/main.jai` owns process startup and connects transport, workspace/program state, and language-feature handlers.

#### Workspace and Program Model
`server/program.jai` is the central workspace/program representation: it loads configured roots, resolves project structure, and supplies semantic context to requests. `server/memory_files.jai` maintains editor-open/in-memory document content, separating unsaved buffers from on-disk source. Project behavior is configured through root-level `jails.json`.

#### Parsing and Symbol Intelligence
Jails depends on the parser submodule at `modules/jai_parser` to parse Jai source and underpin symbol-aware features. Symbol extraction and lookup are concentrated in `server/symbols.jai`, serving requests over workspace and parsed-file state. The server also consumes `modules/jaison` for JSON handling and `modules/unicode_utils` for text/unicode support.

#### Interactive Editor Features
Feature-specific handlers are separated by LSP capability:
- completion: `server/completition.jai`
- definition navigation: `server/goto.jai`
- hover information: `server/hover.jai`
- call signatures: `server/signature_help.jai`

These handlers receive LSP positions/documents, consult program, parser, and symbol state, then return protocol-shaped responses through the LSP/RPC layer.

#### Compiler Diagnostics Boundary
`server/diagnostics.jai` invokes the external Jai compiler to produce editor diagnostics, rather than attempting to duplicate compiler validation. The server discovers Jai via platform commands or a supplied Jai-installation path; diagnostics use configured `build_root` and optional `intermediate_path`. `metaprogram/jails_diagnostics.jai` supports diagnostic-build integration, including a `JAILS_DIAGNOSTICS_BUILD` mode for custom build programs.

#### Editor Distribution and Runtime
The primary runtime is a compiled Jai executable. `build.jai` produces the server binary. The VS Code extension (`vscode_extension/src/extension.ts`, `vscode_extension/package.json`) launches/connects to that server and supplies Jai language registration via `vscode_extension/syntaxes/jai.tmLanguage.json`. Deployment therefore requires a compatible Jails binary and an accessible Jai compiler for compiler-backed diagnostics.

Main entry points: [`server/lsp_interface.jai`](https://github.com/sogocze/jails/blob/main/server/lsp_interface.jai) (LSP dispatch), [`server/symbols.jai`](https://github.com/sogocze/jails/blob/main/server/symbols.jai) (Symbol intelligence), [`server/program.jai`](https://github.com/sogocze/jails/blob/main/server/program.jai) (Workspace program), [`server/diagnostics.jai`](https://github.com/sogocze/jails/blob/main/server/diagnostics.jai) (Diagnostics handler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Build &amp; Distribution"]
  node_build_script["Build orchestration<br/>Jai build<br/>[build.jai]"]
  node_server_binary{{"Jails server binary<br/>native executable"}}
end

subgraph group_server["Native LSP Server"]
  node_main["Server startup<br/>Jai entry point<br/>[main.jai]"]
  node_rpc["JSON-RPC transport<br/>transport boundary<br/>[rpc.jai]"]
  node_lsp_interface["LSP dispatch<br/>LSP interface<br/>[lsp_interface.jai]"]
  node_program["Workspace program<br/>workspace model<br/>[program.jai]"]
  node_memory_files[("Open document buffers<br/>in-memory files<br/>[memory_files.jai]")]
  node_jails_config["Project configuration<br/>workspace config<br/>[jails.json]"]
end

subgraph group_language["Language Intelligence"]
  node_parser["Jai parser<br/>parser submodule"]
  node_symbols["Symbol intelligence<br/>symbol index and lookup<br/>[symbols.jai]"]
  node_completion["Completion<br/>LSP feature handler<br/>[completition.jai]"]
  node_definition["Definition navigation<br/>LSP feature handler<br/>[goto.jai]"]
  node_hover["Hover information<br/>LSP feature handler<br/>[hover.jai]"]
  node_signature["Call signatures<br/>LSP feature handler<br/>[signature_help.jai]"]
end

subgraph group_diagnostics["Compiler Diagnostics"]
  node_diagnostics["Diagnostics handler<br/>compiler diagnostics<br/>[diagnostics.jai]"]
  node_diagnostics_meta["Diagnostics build support<br/>Jai metaprogram"]
  node_jai_compiler{{"Jai compiler<br/>external compiler"}}
end

subgraph group_editor["VS Code Client"]
  node_extension["VS Code extension<br/>editor client<br/>[extension.ts]"]
  node_extension_manifest["Extension manifest<br/>VS Code package<br/>[package.json]"]
  node_grammar["Jai language grammar<br/>TextMate grammar"]
end

node_build_script -->|"builds"| node_server_binary
node_extension_manifest -->|"declares"| node_extension
node_grammar -->|"language registration"| node_extension
node_extension -->|"launches/connects"| node_server_binary
node_server_binary -->|"runs"| node_main
node_main -->|"owns"| node_rpc
node_rpc -->|"JSON-RPC messages"| node_lsp_interface
node_lsp_interface -->|"request context"| node_program
node_program -->|"loads"| node_jails_config
node_program -->|"uses open buffers"| node_memory_files
node_program -->|"parses source"| node_parser
node_symbols -->|"workspace state"| node_program
node_symbols -->|"parsed source"| node_parser
node_lsp_interface -->|"completion requests"| node_completion
node_lsp_interface -->|"definition requests"| node_definition
node_lsp_interface -->|"hover requests"| node_hover
node_lsp_interface -->|"signature requests"| node_signature
node_completion -->|"symbol lookup"| node_symbols
node_definition -->|"symbol lookup"| node_symbols
node_hover -->|"symbol lookup"| node_symbols
node_signature -->|"symbol lookup"| node_symbols
node_lsp_interface -->|"diagnostic requests"| node_diagnostics
node_diagnostics -->|"invokes"| node_jai_compiler
node_diagnostics_meta -.->|"custom build integration"| node_diagnostics

click node_build_script "https://github.com/sogocze/jails/blob/main/build.jai"
click node_main "https://github.com/sogocze/jails/blob/main/server/main.jai"
click node_rpc "https://github.com/sogocze/jails/blob/main/server/rpc.jai"
click node_lsp_interface "https://github.com/sogocze/jails/blob/main/server/lsp_interface.jai"
click node_program "https://github.com/sogocze/jails/blob/main/server/program.jai"
click node_memory_files "https://github.com/sogocze/jails/blob/main/server/memory_files.jai"
click node_jails_config "https://github.com/sogocze/jails/blob/main/jails.json"
click node_parser "https://github.com/sogocze/jails/tree/main/modules/jai_parser"
click node_symbols "https://github.com/sogocze/jails/blob/main/server/symbols.jai"
click node_completion "https://github.com/sogocze/jails/blob/main/server/completition.jai"
click node_definition "https://github.com/sogocze/jails/blob/main/server/goto.jai"
click node_hover "https://github.com/sogocze/jails/blob/main/server/hover.jai"
click node_signature "https://github.com/sogocze/jails/blob/main/server/signature_help.jai"
click node_diagnostics "https://github.com/sogocze/jails/blob/main/server/diagnostics.jai"
click node_diagnostics_meta "https://github.com/sogocze/jails/blob/main/metaprogram/jails_diagnostics.jai"
click node_extension "https://github.com/sogocze/jails/blob/main/vscode_extension/src/extension.ts"
click node_extension_manifest "https://github.com/sogocze/jails/blob/main/vscode_extension/package.json"
click node_grammar "https://github.com/sogocze/jails/blob/main/vscode_extension/syntaxes/jai.tmLanguage.json"

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_build_script,node_server_binary toneBlue
class node_main,node_rpc,node_lsp_interface,node_program,node_memory_files,node_jails_config toneAmber
class node_parser,node_symbols,node_completion,node_definition,node_hover,node_signature toneMint
class node_diagnostics,node_diagnostics_meta,node_jai_compiler toneRose
class node_extension,node_extension_manifest,node_grammar toneIndigo
```

## Components

### Build & Distribution

- [Build orchestration](https://github.com/sogocze/jails/blob/main/build.jai): Jai build · Builds the native server and supports release and VS Code development modes. · `build.jai`
- **Jails server binary**: native executable

### Native LSP Server

- [Server startup](https://github.com/sogocze/jails/blob/main/server/main.jai): Jai entry point · Wires transport, workspace state, and feature handlers. · `server/main.jai`
- [JSON-RPC transport](https://github.com/sogocze/jails/blob/main/server/rpc.jai): transport boundary · Connects editor messages to the native server. · `server/rpc.jai`
- [LSP dispatch](https://github.com/sogocze/jails/blob/main/server/lsp_interface.jai): LSP interface · Handles LSP requests and notifications. · `server/lsp_interface.jai`
- [Workspace program](https://github.com/sogocze/jails/blob/main/server/program.jai): workspace model · Loads roots, resolves projects, and supplies semantic context. · `server/program.jai`
- [Open document buffers](https://github.com/sogocze/jails/blob/main/server/memory_files.jai): in-memory files · Keeps unsaved editor content separate from disk source. · `server/memory_files.jai`
- [Project configuration](https://github.com/sogocze/jails/blob/main/jails.json): workspace config · `jails.json`

### Language Intelligence

- [Jai parser](https://github.com/sogocze/jails/tree/main/modules/jai_parser): parser submodule · Parses Jai source for symbol-aware features. · `modules/jai_parser`
- [Symbol intelligence](https://github.com/sogocze/jails/blob/main/server/symbols.jai): symbol index and lookup · `server/symbols.jai`
- [Completion](https://github.com/sogocze/jails/blob/main/server/completition.jai): LSP feature handler · `server/completition.jai`
- [Definition navigation](https://github.com/sogocze/jails/blob/main/server/goto.jai): LSP feature handler · `server/goto.jai`
- [Hover information](https://github.com/sogocze/jails/blob/main/server/hover.jai): LSP feature handler · `server/hover.jai`
- [Call signatures](https://github.com/sogocze/jails/blob/main/server/signature_help.jai): LSP feature handler · `server/signature_help.jai`

### Compiler Diagnostics

- [Diagnostics handler](https://github.com/sogocze/jails/blob/main/server/diagnostics.jai): compiler diagnostics · Invokes Jai rather than duplicating compiler validation. · `server/diagnostics.jai`
- [Diagnostics build support](https://github.com/sogocze/jails/blob/main/metaprogram/jails_diagnostics.jai): Jai metaprogram · Supports custom build programs and JAILS_DIAGNOSTICS_BUILD mode. · `metaprogram/jails_diagnostics.jai`
- **Jai compiler**: external compiler · Discovered through platform commands or a supplied installation path.

### VS Code Client

- [VS Code extension](https://github.com/sogocze/jails/blob/main/vscode_extension/src/extension.ts): editor client · Launches or connects to the Jails server. · `vscode_extension/src/extension.ts`
- [Extension manifest](https://github.com/sogocze/jails/blob/main/vscode_extension/package.json): VS Code package · `vscode_extension/package.json`
- [Jai language grammar](https://github.com/sogocze/jails/blob/main/vscode_extension/syntaxes/jai.tmLanguage.json): TextMate grammar · `vscode_extension/syntaxes/jai.tmLanguage.json`

## Connections

- Build orchestration → Jails server binary: builds
- Extension manifest → VS Code extension: declares
- Jai language grammar → VS Code extension: language registration
- VS Code extension → Jails server binary: launches/connects
- Jails server binary → Server startup: runs
- Server startup → JSON-RPC transport: owns
- JSON-RPC transport → LSP dispatch: JSON-RPC messages
- LSP dispatch → Workspace program: request context
- Workspace program → Project configuration: loads
- Workspace program → Open document buffers: uses open buffers
- Workspace program → Jai parser: parses source
- Symbol intelligence → Workspace program: workspace state
- Symbol intelligence → Jai parser: parsed source
- LSP dispatch → Completion: completion requests
- LSP dispatch → Definition navigation: definition requests
- LSP dispatch → Hover information: hover requests
- LSP dispatch → Call signatures: signature requests
- Completion → Symbol intelligence: symbol lookup
- Definition navigation → Symbol intelligence: symbol lookup
- Hover information → Symbol intelligence: symbol lookup
- Call signatures → Symbol intelligence: symbol lookup
- LSP dispatch → Diagnostics handler: diagnostic requests
- Diagnostics handler → Jai compiler: invokes
- Diagnostics build support → Diagnostics handler: custom build integration
