# piratelang/pirate architecture

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

- Interactive diagram: https://gitdiagram.com/piratelang/pirate
- Repository: https://github.com/piratelang/pirate

## Overview

Pirate is a toy programming language with a command-line shell. Its principal workflow starts with a source file, lexes it into tokens, parses tokens into a scope, and interprets that scope to produce values; the parser also serializes its scope. The tree documents standard terminal and string functions, shell project/module commands, and shared file, environment, and logging services. Lexer implementation files are absent from the supplied tree, so its node has no source path. Some internal runtime and shell-command wiring is consequently not shown.

Main entry points: [`Shell/Application.cs`](https://github.com/piratelang/pirate/blob/master/Shell/Application.cs) (Shell application), [`Pirate.Parser/Parser.cs`](https://github.com/piratelang/pirate/blob/master/Pirate.Parser/Parser.cs) (Parser), [`Pirate.Common/ObjectSerializer.cs`](https://github.com/piratelang/pirate/blob/master/Pirate.Common/ObjectSerializer.cs) (Object serializer), [`Pirate.Interpreter/Interpreter.cs`](https://github.com/piratelang/pirate/blob/master/Pirate.Interpreter/Interpreter.cs) (Interpreter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_language["Language pipeline"]
  node_lexer["Lexer"]
  node_tokenmap["Token types<br/>[TokenTypeMapper.cs]"]
  node_parser["Parser<br/>[Parser.cs]"]
  node_parseforms["Statement parsers<br/>[Parsers]"]
  node_scope["Parsed scope<br/>[Scope.cs]"]
end

subgraph group_execution["Interpreter runtime"]
  node_interpreter["Interpreter<br/>[Interpreter.cs]"]
  node_visitors["Node interpreters<br/>[Interpreters]"]
  node_runtime["Runtime state<br/>[Runtime.cs]"]
  node_values["Runtime values<br/>[Values]"]
  node_standard["Standard library"]
  node_terminal["Terminal functions<br/>[Terminal]"]
  node_strings["String functions<br/>[String]"]
end

subgraph group_shell["Shell and projects"]
  node_shellapp["Shell application<br/>[Application.cs]"]
  node_commands["Shell commands"]
  node_run["Run command<br/>[RunCommand.cs]"]
  node_project["Project files"]
  node_modules["Module list"]
end

subgraph group_common["Shared services"]
  node_serializer["Object serializer"]
  node_fileio["File handlers"]
  node_environment["Environment config"]
  node_logger["Logger<br/>[Logger.cs]"]
end

node_user(("Language user"))
node_source["Pirate source"]
node_filesystem[("Local files")]

node_user -->|"invokes"| node_shellapp
node_user -->|"writes"| node_source
node_source -->|"lexes"| node_lexer
node_lexer -.->|"maps tokens"| node_tokenmap
node_lexer -->|"provides tokens"| node_parser
node_parser -->|"dispatches parsers"| node_parseforms
node_parser -->|"adds nodes"| node_scope
node_parser -->|"serializes scope"| node_serializer
node_shellapp -->|"routes commands"| node_run
node_run -.->|"runs pipeline"| node_parser
node_shellapp -->|"runs interpreter"| node_interpreter
node_interpreter -->|"visits nodes"| node_visitors
node_visitors -->|"produces values"| node_values
node_interpreter -.->|"uses runtime"| node_runtime
node_standard -->|"registers functions"| node_terminal
node_standard -->|"registers functions"| node_strings
node_shellapp -.->|"handles projects"| node_project
node_shellapp -.->|"manages modules"| node_modules
node_serializer -->|"reads and writes"| node_fileio
node_fileio -->|"accesses files"| node_filesystem
node_serializer -->|"gets location"| node_environment
node_serializer -->|"logs operations"| node_logger
node_logger -->|"appends logs"| node_fileio

click node_shellapp "https://github.com/piratelang/pirate/blob/master/Shell/Application.cs"
click node_commands "https://github.com/piratelang/pirate/tree/master/Shell/Commands"
click node_run "https://github.com/piratelang/pirate/blob/master/Shell/Commands/RunCommand.cs"
click node_project "https://github.com/piratelang/pirate/blob/master/Shell.Project/ProjectFileHandler.cs"
click node_modules "https://github.com/piratelang/pirate/blob/master/Shell.ModuleList/ModuleListRepository.cs"
click node_tokenmap "https://github.com/piratelang/pirate/blob/master/Pirate.Lexer.TokenType/TokenTypeMapper.cs"
click node_parser "https://github.com/piratelang/pirate/blob/master/Pirate.Parser/Parser.cs"
click node_parseforms "https://github.com/piratelang/pirate/tree/master/Pirate.Parser/Parsers"
click node_scope "https://github.com/piratelang/pirate/blob/master/Pirate.Parser/Scope.cs"
click node_interpreter "https://github.com/piratelang/pirate/blob/master/Pirate.Interpreter/Interpreter.cs"
click node_visitors "https://github.com/piratelang/pirate/tree/master/Pirate.Interpreter/Interpreters"
click node_runtime "https://github.com/piratelang/pirate/blob/master/Pirate.Interpreter.Runtime/Runtime.cs"
click node_values "https://github.com/piratelang/pirate/tree/master/Pirate.Interpreter/Values"
click node_standard "https://github.com/piratelang/pirate/blob/master/Pirate.Interpreter.StandarLibrary/StandardLibraryProvider.cs"
click node_terminal "https://github.com/piratelang/pirate/tree/master/Pirate.Interpreter.StandarLibrary/Standard/Terminal"
click node_strings "https://github.com/piratelang/pirate/tree/master/Pirate.Interpreter.StandarLibrary/Standard/String"
click node_serializer "https://github.com/piratelang/pirate/blob/master/Pirate.Common/ObjectSerializer.cs"
click node_fileio "https://github.com/piratelang/pirate/tree/master/Pirate.Common.FileHandler"
click node_environment "https://github.com/piratelang/pirate/blob/master/Pirate.Common/EnvironmentVariables.cs"
click node_logger "https://github.com/piratelang/pirate/blob/master/Pirate.Common.Logger/Logger.cs"

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_tokenmap,node_parser,node_parseforms,node_scope,node_user toneBlue
class node_interpreter,node_visitors,node_runtime,node_values,node_standard,node_terminal,node_strings,node_filesystem toneAmber
class node_shellapp,node_commands,node_run,node_project,node_modules toneMint
class node_serializer,node_fileio,node_environment,node_logger toneRose
class node_source toneIndigo
```

## Components

### Language pipeline

- **Lexer**
- [Token types](https://github.com/piratelang/pirate/blob/master/Pirate.Lexer.TokenType/TokenTypeMapper.cs): `Pirate.Lexer.TokenType/TokenTypeMapper.cs`
- [Parser](https://github.com/piratelang/pirate/blob/master/Pirate.Parser/Parser.cs): `Pirate.Parser/Parser.cs`
- [Statement parsers](https://github.com/piratelang/pirate/tree/master/Pirate.Parser/Parsers): `Pirate.Parser/Parsers`
- [Parsed scope](https://github.com/piratelang/pirate/blob/master/Pirate.Parser/Scope.cs): `Pirate.Parser/Scope.cs`

### Interpreter runtime

- [Interpreter](https://github.com/piratelang/pirate/blob/master/Pirate.Interpreter/Interpreter.cs): `Pirate.Interpreter/Interpreter.cs`
- [Node interpreters](https://github.com/piratelang/pirate/tree/master/Pirate.Interpreter/Interpreters): `Pirate.Interpreter/Interpreters`
- [Runtime state](https://github.com/piratelang/pirate/blob/master/Pirate.Interpreter.Runtime/Runtime.cs): `Pirate.Interpreter.Runtime/Runtime.cs`
- [Runtime values](https://github.com/piratelang/pirate/tree/master/Pirate.Interpreter/Values): `Pirate.Interpreter/Values`
- [Standard library](https://github.com/piratelang/pirate/blob/master/Pirate.Interpreter.StandarLibrary/StandardLibraryProvider.cs): `Pirate.Interpreter.StandarLibrary/StandardLibraryProvider.cs`
- [Terminal functions](https://github.com/piratelang/pirate/tree/master/Pirate.Interpreter.StandarLibrary/Standard/Terminal): `Pirate.Interpreter.StandarLibrary/Standard/Terminal`
- [String functions](https://github.com/piratelang/pirate/tree/master/Pirate.Interpreter.StandarLibrary/Standard/String): `Pirate.Interpreter.StandarLibrary/Standard/String`

### Shell and projects

- [Shell application](https://github.com/piratelang/pirate/blob/master/Shell/Application.cs): `Shell/Application.cs`
- [Shell commands](https://github.com/piratelang/pirate/tree/master/Shell/Commands): `Shell/Commands`
- [Run command](https://github.com/piratelang/pirate/blob/master/Shell/Commands/RunCommand.cs): `Shell/Commands/RunCommand.cs`
- [Project files](https://github.com/piratelang/pirate/blob/master/Shell.Project/ProjectFileHandler.cs): `Shell.Project/ProjectFileHandler.cs`
- [Module list](https://github.com/piratelang/pirate/blob/master/Shell.ModuleList/ModuleListRepository.cs): `Shell.ModuleList/ModuleListRepository.cs`

### Shared services

- [Object serializer](https://github.com/piratelang/pirate/blob/master/Pirate.Common/ObjectSerializer.cs): `Pirate.Common/ObjectSerializer.cs`
- [File handlers](https://github.com/piratelang/pirate/tree/master/Pirate.Common.FileHandler): `Pirate.Common.FileHandler`
- [Environment config](https://github.com/piratelang/pirate/blob/master/Pirate.Common/EnvironmentVariables.cs): `Pirate.Common/EnvironmentVariables.cs`
- [Logger](https://github.com/piratelang/pirate/blob/master/Pirate.Common.Logger/Logger.cs): `Pirate.Common.Logger/Logger.cs`

### Other components

- **Language user**
- **Pirate source**
- **Local files**

## Connections

- Language user → Shell application: invokes (evidence: `README.md`)
- Language user → Pirate source: writes (evidence: `README.md`)
- Pirate source → Lexer: lexes (evidence: `README.md`)
- Lexer → Token types: maps tokens
- Lexer → Parser: provides tokens (evidence: `README.md`)
- Parser → Statement parsers: dispatches parsers (evidence: `Pirate.Parser/Parser.cs`)
- Parser → Parsed scope: adds nodes (evidence: `Pirate.Parser/Parser.cs`)
- Parser → Object serializer: serializes scope (evidence: `Pirate.Parser/Parser.cs`)
- Shell application → Run command: routes commands (evidence: `Shell/Application.cs`)
- Run command → Parser: runs pipeline
- Shell application → Interpreter: runs interpreter (evidence: `Shell/Program.cs`)
- Interpreter → Node interpreters: visits nodes (evidence: `README.md`)
- Node interpreters → Runtime values: produces values (evidence: `README.md`)
- Interpreter → Runtime state: uses runtime (evidence: `Pirate.Interpreter.Runtime/Runtime.cs`)
- Standard library → Terminal functions: registers functions (evidence: `Pirate.Interpreter.StandarLibrary/StandardLibraryProvider.cs`)
- Standard library → String functions: registers functions (evidence: `Pirate.Interpreter.StandarLibrary/StandardLibraryProvider.cs`)
- Shell application → Project files: handles projects
- Shell application → Module list: manages modules
- Object serializer → File handlers: reads and writes (evidence: `Pirate.Common/ObjectSerializer.cs`)
- File handlers → Local files: accesses files (evidence: `Pirate.Common.FileHandler/FileReadHandler.cs`)
- Object serializer → Environment config: gets location (evidence: `Pirate.Common/ObjectSerializer.cs`)
- Object serializer → Logger: logs operations (evidence: `Pirate.Common/ObjectSerializer.cs`)
- Logger → File handlers: appends logs (evidence: `Pirate.Common.Logger/Logger.cs`)
