# amber-lang/amber architecture

> Architecture diagram of the GitHub repository amber-lang/amber, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amber-lang/amber
- Repository: https://github.com/amber-lang/amber

## Overview

##### Main Components

a) Compiler Pipeline:
- Parser (based on grammar.ebnf)
- Translator (src/translate/)
- Postprocessor (src/compiler/postprocessor.rs)

b) Module System:
- Core Modules (src/modules/)
- Expression handling
- Control flow (conditions, loops)
- Functions
- Variables
- Commands
- Types

c) Standard Library (src/std/):
- Array operations
- Date handling
- Environment utilities
- File system operations
- HTTP capabilities
- Math functions
- Text processing

##### Component Relationships

**[Source Code] → [Parser] → [AST] → [Translator] → [Bash Code] → [Postprocessor] → [Final Bash Script]**

- Blue rectangles: Core components (Parser, Translator, Postprocessor)
- Green rectangles: Module system components
- Yellow rectangles: Standard library modules
- Purple diamonds: Decision points/validation steps
- Gray rectangles: External interfaces (Bash runtime)

##### Specific Implementation Details

Key architectural elements:

a) Module System Architecture:
**[Module Manager]**
- ↓
**[Core Modules] → [Expression Engine] → [Type System]**
- ↓
**[Standard Library]**

b) Compilation Pipeline:
**[Source] → [Lexical Analysis] → [Syntax Tree] → [Type Checking] → [Code Generation]**

##### Integration Points

Integration points:
- Bash runtime interaction
- Standard library linkage
- External command execution
- File system interactions

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Pipeline
        Source[Source Code]
        AST[Abstract Syntax Tree]
        BashCode[Bash Code]
        FinalScript[Final Bash Script]
        
        Parser["Parser"]:::core
        Translator["Translator"]:::core
        Postprocessor["Postprocessor"]:::core
        
        Source --> Parser
        Parser --> AST
        AST --> Translator
        Translator --> BashCode
        BashCode --> Postprocessor
        Postprocessor --> FinalScript
    end
    
    subgraph Utilities
        MetadataSystem["Metadata System"]:::util
        FunctionCache["Function Cache"]:::util
        ImportCache["Import Cache"]:::util
        
        MetadataSystem <--> Pipeline
        FunctionCache <--> Pipeline
        ImportCache <--> Pipeline
    end
    
    subgraph "Core Modules"
        ModuleManager["Module Manager"]:::module
        
        ExpressionHandler["Expression Handler"]:::module
        ControlFlow["Control Flow"]:::module
        Functions["Functions"]:::module
        Variables["Variables"]:::module
        Commands["Commands"]:::module
        Types["Types"]:::module
        BuiltinModules["Built-in Modules"]:::module
        
        ModuleManager --> ExpressionHandler
        ModuleManager --> ControlFlow
        ModuleManager --> Functions
        ModuleManager --> Variables
        ModuleManager --> Commands
        ModuleManager --> Types
        ModuleManager --> BuiltinModules
    end
    
    subgraph "Standard Library"
        ArrayOps["Array Operations"]:::stdlib
        DateHandling["Date Handling"]:::stdlib
        EnvUtils["Environment Utilities"]:::stdlib
        FSOperations["File System Operations"]:::stdlib
        HTTPCaps["HTTP Capabilities"]:::stdlib
        MathFuncs["Math Functions"]:::stdlib
        TextProc["Text Processing"]:::stdlib
    end
    
    ModuleManager --> Pipeline
    
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef module fill:#2ecc71,stroke:#27ae60,color:white
    classDef stdlib fill:#f1c40f,stroke:#f39c12,color:black
    classDef util fill:#9b59b6,stroke:#8e44ad,color:white
    
    click Parser "https://github.com/amber-lang/amber/blob/main/grammar.ebnf"
    click Translator "https://github.com/amber-lang/amber/tree/main/src/translate/"
    click Postprocessor "https://github.com/amber-lang/amber/blob/main/src/compiler/postprocessor.rs"
    click ModuleManager "https://github.com/amber-lang/amber/tree/main/src/modules/"
    click ExpressionHandler "https://github.com/amber-lang/amber/tree/main/src/modules/expression/"
    click ControlFlow "https://github.com/amber-lang/amber/tree/main/src/modules/condition/"
    click Functions "https://github.com/amber-lang/amber/tree/main/src/modules/function/"
    click Variables "https://github.com/amber-lang/amber/tree/main/src/modules/variable/"
    click Commands "https://github.com/amber-lang/amber/tree/main/src/modules/command/"
    click Types "https://github.com/amber-lang/amber/blob/main/src/modules/types.rs"
    click ArrayOps "https://github.com/amber-lang/amber/blob/main/src/std/array.ab"
    click DateHandling "https://github.com/amber-lang/amber/blob/main/src/std/date.ab"
    click EnvUtils "https://github.com/amber-lang/amber/blob/main/src/std/env.ab"
    click FSOperations "https://github.com/amber-lang/amber/blob/main/src/std/fs.ab"
    click HTTPCaps "https://github.com/amber-lang/amber/blob/main/src/std/http.ab"
    click MathFuncs "https://github.com/amber-lang/amber/blob/main/src/std/math.ab"
    click TextProc "https://github.com/amber-lang/amber/blob/main/src/std/text.ab"
    click MetadataSystem "https://github.com/amber-lang/amber/tree/main/src/utils/metadata/"
    click FunctionCache "https://github.com/amber-lang/amber/blob/main/src/utils/function_cache.rs"
    click ImportCache "https://github.com/amber-lang/amber/blob/main/src/utils/import_cache.rs"
    click BuiltinModules "https://github.com/amber-lang/amber/tree/main/src/modules/builtin/"
```
