# hanneskimara/cddlc architecture

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

- Interactive diagram: https://gitdiagram.com/hanneskimara/cddlc
- Repository: https://github.com/hanneskimara/cddlc

## Overview

##### Project Type and Purpose
- This is a compiler‐style toolchain in Go for the IETF’s CDDL (Concise Data Definition Language).
- It provides both a Go library (parser, AST, code generators, runtime validators) and a CLI tool (`cddlc`) to generate Go code and REPL support from CDDL specs.

##### File Structure
- Top-Level CLI:
- cmd/cddlc/main.go
- cmd/cddlc/commands/{init,generate,repl}.go
- Compiler Phases:
- Lexer: lexer/lexer.go, lexer_test.go
- Parser: parser/parser.go, parser/diagnostic.go
- AST: ast/*.go + ast/astutils
- Transforms/Codegen: transforms/codegen/generator.go + language-specific (golang) generators
- Supporting Services:
- Config: config/config.go
- Environment: environment/environment.go (+ tests)
- Errors: errors/errors.go
- Runtime Validators: runtime/validators/*.go
- Helpers:
- Token definitions: token/token.go, token/position.go
- Examples & Testdata: examples/, testdata/
- Build & Release: Makefile, .goreleaser.yaml, GitHub actions

##### Insights from README
- Purpose: parse CDDL and generate Go types/validators for CBOR/JSON.
- Dual interface: library and the `cddlc` command.
- Feature coverage table indicates which CDDL constructs are parsed vs. code-generated.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "CLI Frontend"
        Main["Main (cddlc)"]
        Commands["Commands (init/generate/repl)"]
    end
    class Main,Commands cli
    click Main "https://github.com/hanneskimara/cddlc/blob/main/cmd/cddlc/main.go"
    click Commands "https://github.com/hanneskimara/cddlc/tree/main/cmd/cddlc/commands/"

    Config["Config Manager"]
    class Config cli
    click Config "https://github.com/hanneskimara/cddlc/blob/main/config/config.go"

    Env["Environment Manager"]
    class Env cli
    click Env "https://github.com/hanneskimara/cddlc/blob/main/environment/environment.go"

    Config --> Main
    Env --> Main

    Main -->|readsCDDL| Lexer
    Lexer["Lexer Service"]
    class Lexer compiler
    click Lexer "https://github.com/hanneskimara/cddlc/blob/main/lexer/lexer.go"

    Lexer --> Parser
    Parser["Parser Service"]
    class Parser compiler
    click Parser "https://github.com/hanneskimara/cddlc/blob/main/parser/parser.go"

    Parser --> AST
    AST["AST Module"]
    class AST compiler
    click AST "https://github.com/hanneskimara/cddlc/tree/main/ast/"

    Parser --> ErrorFlow
    ErrorFlow["Error & Diagnostic Flow"]
    class ErrorFlow error
    click ErrorFlow "https://github.com/hanneskimara/cddlc/blob/main/errors/errors.go"

    ErrorFlow --> Main

    AST --> Transform
    Transform["Transform & Codegen Module"]
    class Transform codegen

    Transform --> CodegenCore
    CodegenCore["Codegen Generator"]
    class CodegenCore codegen
    click CodegenCore "https://github.com/hanneskimara/cddlc/blob/main/transforms/codegen/generator.go"

    CodegenCore --> CodegenLang
    CodegenLang["Golang Generators"]
    class CodegenLang codegen
    click CodegenLang "https://github.com/hanneskimara/cddlc/tree/main/transforms/codegen/golang/"

    CodegenLang --> Disk[(Disk I/O/Generated Files)]

    Disk -->|"imports"| Runtime
    Runtime["Runtime Validators"]
    class Runtime runtime
    click Runtime "https://github.com/hanneskimara/cddlc/blob/main/runtime/validators/validators.go"

    classDef compiler fill:#cce5ff,stroke:#004085,color:#004085
    classDef codegen fill:#d4edda,stroke:#155724,color:#155724
    classDef runtime fill:#fff3cd,stroke:#856404,color:#856404
    classDef cli fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    classDef error fill:#f8d7da,stroke:#721c24,color:#721c24
```
