# midnightntwrk/compact architecture

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

- Interactive diagram: https://gitdiagram.com/midnightntwrk/compact
- Repository: https://github.com/midnightntwrk/compact

## Overview

##### Project type and purpose
- From the README (“Compact is the Midnight network’s smart contract language”) and the lack of application folders (no “frontend” or “backend”), we know this is a language-tool project—a compiler or toolchain specifically for writing and deploying smart contracts on the Midnight network.

##### File structure
- The entire tree consists of repository metadata and documentation (.github templates, LICENSE, CONTRIBUTING.md, etc.)
- No direct “src/” folder is shown, but we can infer that source code for the compiler lives in a sibling directory such as “src/” or “lib/” alongside tests and examples.
- CI is set up under .github/workflows (e.g. checkmarx.yaml), indicating automated security checks and build pipelines.

##### README for additional insights
- The README is minimal (project name and community guidelines).

##### Elements
- Front-end components (blue)
- Middle-end / optimizer (yellow)
- Back-end / codegen (green)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Front-end Layer
    subgraph "Front-end Pipeline"
        direction TB
        CLI["CLI / REPL Interface"]:::frontend
        Lexer["Lexer"]:::frontend
        Parser["Parser"]:::frontend
        AST["AST Builder"]:::frontend
        Semantic["Semantic Analyzer"]:::frontend
    end

    %% Middle-end Layer
    subgraph "Middle-end / Optimizer"
        direction TB
        IR["Intermediate Representation (IR)"]:::middle
        Optimizer["Optimizer"]:::middle
        subgraph "Optimizer Components"
            ConstFold["Constant Folding"]:::middle
            GasAnalysis["Gas Analysis"]:::middle
            Inlining["Inlining"]:::middle
        end
    end

    %% Back-end Layer
    subgraph "Back-end / Code Generation"
        direction TB
        CodeGen["Code Generator"]:::backend
        Artifact["Compiled Artifact / Bytecode"]:::backend
    end

    %% Shared Libraries and Deployment
    subgraph "Shared Resources"
        direction TB
        StdLib["Standard Library / Builtins"]:::shared
    end

    Deployment["Deployment Module"]:::external
    Node["Midnight Node / Runtime"]:::external

    %% Test and CI/CD
    subgraph "Quality & CI/CD"
        direction TB
        Tests["Test Harness / Sandbox VM"]:::external
        CICD["CI/CD Pipelines"]:::external
        Security["Security Scanning (Checkmarx)"]:::external
    end

    %% Documentation
    subgraph "Repository Documentation"
        direction TB
        README["Project Documentation & Overview"]:::docs
        CONTRIB["Contribution & Community Guidelines"]:::docs
        COC["Code of Conduct"]:::docs
        Issues["Issue Templates"]:::docs
        PRTemplate["Pull Request Template"]:::docs
        CHANGELOG["Release Changelog"]:::docs
        SECURITY["Security Policy Overview"]:::docs
        LICENSE["Licensing Information"]:::docs
    end

    %% Data Flow
    CLI --> Lexer --> Parser --> AST --> Semantic --> IR --> Optimizer --> CodeGen --> Artifact
    Artifact --> StdLib
    Artifact --> Deployment --> Node
    Tests -->|exercises| CLI
    Tests -->|deploys to| Node
    CICD -->|runs build & tests| CLI
    CICD -->|triggers| Security

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#21618C,color:#1B4F72;
    classDef middle fill:#FCF3CF,stroke:#B7950B,color:#7D6608;
    classDef backend fill:#ABEBC6,stroke:#239B56,color:#196F3D;
    classDef shared fill:#F5CBA7,stroke:#B9770E,color:#92400E;
    classDef external fill:#D7DBDD,stroke:#626567,color:#1C2833,stroke-dasharray: 5 5;
    classDef docs fill:#E8DAEF,stroke:#7D3C98,color:#512E5F;

    %% Click Events
    click CICD "https://github.com/midnightntwrk/compact/tree/main/.github/workflows/"
    click Security "https://github.com/midnightntwrk/compact/blob/main/.github/workflows/checkmarx.yaml"
    click CONTRIB "https://github.com/midnightntwrk/compact/blob/main/CONTRIBUTING.md"
    click COC "https://github.com/midnightntwrk/compact/blob/main/CODE_OF_CONDUCT.md"
    click Issues "https://github.com/midnightntwrk/compact/blob/main/.github/ISSUE_TEMPLATE/bug-report.md"
    click Issues "https://github.com/midnightntwrk/compact/blob/main/.github/ISSUE_TEMPLATE/feature-request.md"
    click Issues "https://github.com/midnightntwrk/compact/blob/main/.github/ISSUE_TEMPLATE/documentation-improvement.md"
    click PRTemplate "https://github.com/midnightntwrk/compact/blob/main/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md"
    click README "https://github.com/midnightntwrk/compact/blob/main/README.md"
    click CHANGELOG "https://github.com/midnightntwrk/compact/blob/main/CHANGELOG.md"
    click SECURITY "https://github.com/midnightntwrk/compact/blob/main/SECURITY.md"
    click LICENSE "https://github.com/midnightntwrk/compact/tree/main/LICENSE"
```
