# zsivadi/szakmai-gyakorlat architecture

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

- Interactive diagram: https://gitdiagram.com/zsivadi/szakmai-gyakorlat
- Repository: https://github.com/zsivadi/szakmai-gyakorlat

## Overview

#### Purpose and Entry Points
This is a .NET SQL-to-C# LINQ transpiler prototype. It accepts SQL, parses it into a SQL-oriented AST, converts that representation to a LINQ AST/code form, and exposes the flow through a command-line executable. The main runtime entry point is `SqlToLinq.Cli/Program.cs`; shared compiler logic is in `SqlToLinq.Core/`.

#### Solution Structure
The solution is split into three material projects:
- CLI host: `SqlToLinq.Cli/SqlToLinq.Cli.csproj`
- Compiler/transpiler core: `SqlToLinq.Core/SqlToLinq.Core.csproj`
- Verification suite: `SqlToLinq.Tests/SqlToLinq.Tests.csproj`

`SqlToLinq.slnx` composes these projects. This is a local .NET application/library architecture, not a web or service deployment.

#### Parsing Boundary: SQL Text to Parse Tree
ANTLR 4 is the parser boundary. `SqlToLinq.Core/SqlParser.g4` defines the supported SQL grammar and drives generated parser artifacts during the .NET build. Invalid parse input is routed through `SqlToLinq.Core/ThrowingErrorListener.cs`, making syntax failures explicit rather than silently recovered.

#### SQL Semantic Model Construction
`SqlToLinq.Core/SqlVisitor.cs` traverses the ANTLR parse tree and constructs the project’s internal SQL representation. This separates grammar-specific parser contexts from subsequent translation logic, allowing the converter to operate on a stable semantic/AST layer rather than directly on ANTLR types.

The resulting SQL AST is represented or coordinated through:
- `SqlToLinq.Core/SqlVisitor.cs`
- `SqlToLinq.Core/LinqAst.cs`
- `SqlToLinq.Core/AstVisualizer.cs`

`AstVisualizer.cs` is an observability boundary for inspecting intermediate structure during compiler development.

#### Translation and LINQ Representation
`SqlToLinq.Core/SqlToLinqConverter.cs` is the primary orchestration/translation stage: SQL input and/or its parsed representation are transformed into LINQ output. `SqlToLinq.Core/LinqAst.cs` models LINQ-oriented constructs used during generation, keeping SQL semantics and target-language expression construction distinct.

The essential control flow is:

SQL source → ANTLR grammar/parser → `SqlVisitor` SQL AST → `SqlToLinqConverter` / LINQ AST → generated LINQ expression or C# text.

#### Runtime and External Dependencies
The implementation targets C#/.NET and uses ANTLR 4 for language recognition. The intended target is LINQ, with Roslyn identified by the project documentation as the C# syntax/code-generation platform. There are no indicated network services, databases, queues, or deployed infrastructure in the production path.

#### Correctness Strategy
Tests validate both textual transpilation and behavioral equivalence. `SqlToLinq.Tests/TranspilerTests.cs` covers expected input/output mappings backed by `SqlToLinq.Tests/IOPairs.json`. `SqlToLinq.Tests/SemanticEquivalenceTests.cs` and `SqlToLinq.Tests/TestDbContext.cs` establish a database/LINQ execution boundary for comparing query meaning. Fuzz coverage is supplied by `SqlToLinq.Tests/FuzzTests.cs` and `SqlToLinq.Tests/RandomSqlGenerator.cs`, exercising parser and conversion robustness across generated SQL.

Main entry points: [`SqlToLinq.Core/SqlToLinqConverter.cs`](https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Core/SqlToLinqConverter.cs) (SQL-to-LINQ converter), [`SqlToLinq.Tests/FuzzTests.cs`](https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Tests/FuzzTests.cs) (Fuzz tests), [`SqlToLinq.Cli/Program.cs`](https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Cli/Program.cs) (CLI host), [`SqlToLinq.Tests/SemanticEquivalenceTests.cs`](https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Tests/SemanticEquivalenceTests.cs) (Semantic equivalence tests)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Transpiler runtime"]
  node_cli["CLI host<br/>.NET executable<br/>[Program.cs]"]
  node_core["Compiler core<br/>.NET library"]
  node_grammar["SQL grammar<br/>ANTLR grammar<br/>[SqlParser.g4]"]
  node_antlr["ANTLR parser<br/>generated parser"]
  node_error_listener["Throwing error listener<br/>parse errors"]
  node_sql_visitor["SQL visitor<br/>AST builder<br/>[SqlVisitor.cs]"]
  node_sql_ast["SQL AST<br/>semantic model"]
  node_visualizer["AST visualizer<br/>observability<br/>[AstVisualizer.cs]"]
  node_converter["SQL-to-LINQ converter<br/>translation orchestrator"]
  node_linq_ast["LINQ AST<br/>target model<br/>[LinqAst.cs]"]
  node_csharp_output["LINQ / C# output<br/>generated code"]
  node_roslyn{{"Roslyn<br/>code generation platform"}}
end

subgraph group_verification["Verification"]
  node_transpiler_tests["Transpiler tests<br/>mapping tests<br/>[TranspilerTests.cs]"]
  node_io_pairs["I/O fixtures<br/>test data<br/>[IOPairs.json]"]
  node_semantic_tests["Semantic equivalence tests<br/>behavioral tests"]
  node_test_db[("Test DbContext<br/>execution boundary<br/>[TestDbContext.cs]")]
  node_fuzz_tests["Fuzz tests<br/>robustness tests<br/>[FuzzTests.cs]"]
  node_random_sql["Random SQL generator<br/>fuzz input"]
end

node_cli -->|"uses"| node_core
node_grammar -->|"generates"| node_antlr
node_cli -->|"SQL input"| node_antlr
node_antlr -->|"syntax failures"| node_error_listener
node_antlr -->|"parse tree"| node_sql_visitor
node_sql_visitor -->|"builds"| node_sql_ast
node_sql_ast -.->|"inspect"| node_visualizer
node_sql_ast -->|"translate"| node_converter
node_converter -->|"builds"| node_linq_ast
node_linq_ast -->|"generates"| node_csharp_output
node_converter -.->|"C# generation"| node_roslyn
node_io_pairs -->|"fixtures"| node_transpiler_tests
node_transpiler_tests -.->|"validates output"| node_converter
node_semantic_tests -->|"executes queries"| node_test_db
node_semantic_tests -.->|"compares meaning"| node_converter
node_random_sql -->|"generated inputs"| node_fuzz_tests
node_fuzz_tests -.->|"exercises parsing"| node_antlr
node_fuzz_tests -.->|"exercises conversion"| node_converter

click node_cli "https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Cli/Program.cs"
click node_core "https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Core/SqlToLinq.Core.csproj"
click node_grammar "https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Core/SqlParser.g4"
click node_error_listener "https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Core/ThrowingErrorListener.cs"
click node_sql_visitor "https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Core/SqlVisitor.cs"
click node_visualizer "https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Core/AstVisualizer.cs"
click node_converter "https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Core/SqlToLinqConverter.cs"
click node_linq_ast "https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Core/LinqAst.cs"
click node_transpiler_tests "https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Tests/TranspilerTests.cs"
click node_io_pairs "https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Tests/IOPairs.json"
click node_semantic_tests "https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Tests/SemanticEquivalenceTests.cs"
click node_test_db "https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Tests/TestDbContext.cs"
click node_fuzz_tests "https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Tests/FuzzTests.cs"
click node_random_sql "https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Tests/RandomSqlGenerator.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_cli,node_core,node_grammar,node_antlr,node_error_listener,node_sql_visitor,node_sql_ast,node_visualizer,node_converter,node_linq_ast,node_csharp_output,node_roslyn toneBlue
class node_transpiler_tests,node_io_pairs,node_semantic_tests,node_test_db,node_fuzz_tests,node_random_sql toneAmber
```

## Components

### Transpiler runtime

CLI and compiler pipeline.

- [CLI host](https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Cli/Program.cs): .NET executable · Accepts SQL and exposes transpilation. · `SqlToLinq.Cli/Program.cs`
- [Compiler core](https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Core/SqlToLinq.Core.csproj): .NET library · Shared parsing and translation implementation. · `SqlToLinq.Core/SqlToLinq.Core.csproj`
- [SQL grammar](https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Core/SqlParser.g4): ANTLR grammar · Defines supported SQL syntax and generated parser input. · `SqlToLinq.Core/SqlParser.g4`
- **ANTLR parser**: generated parser · Produces parse trees from SQL text.
- [Throwing error listener](https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Core/ThrowingErrorListener.cs): parse errors · Turns invalid SQL syntax into explicit failures. · `SqlToLinq.Core/ThrowingErrorListener.cs`
- [SQL visitor](https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Core/SqlVisitor.cs): AST builder · Converts ANTLR contexts into the internal SQL representation. · `SqlToLinq.Core/SqlVisitor.cs`
- **SQL AST**: semantic model · Grammar-independent SQL representation.
- [AST visualizer](https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Core/AstVisualizer.cs): observability · Inspects intermediate compiler structure. · `SqlToLinq.Core/AstVisualizer.cs`
- [SQL-to-LINQ converter](https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Core/SqlToLinqConverter.cs): translation orchestrator · Transforms SQL semantics into LINQ-oriented output. · `SqlToLinq.Core/SqlToLinqConverter.cs`
- [LINQ AST](https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Core/LinqAst.cs): target model · Models LINQ-oriented constructs for generation. · `SqlToLinq.Core/LinqAst.cs`
- **LINQ / C# output**: generated code · Generated LINQ expression or C# text.
- **Roslyn**: code generation platform · Intended C# syntax and code-generation platform.

### Verification

Textual, semantic, and fuzz validation.

- [Transpiler tests](https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Tests/TranspilerTests.cs): mapping tests · Checks expected SQL-to-LINQ output mappings. · `SqlToLinq.Tests/TranspilerTests.cs`
- [I/O fixtures](https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Tests/IOPairs.json): test data · Expected transpilation input/output pairs. · `SqlToLinq.Tests/IOPairs.json`
- [Semantic equivalence tests](https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Tests/SemanticEquivalenceTests.cs): behavioral tests · Compares query meaning through database and LINQ execution. · `SqlToLinq.Tests/SemanticEquivalenceTests.cs`
- [Test DbContext](https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Tests/TestDbContext.cs): execution boundary · Database/LINQ execution context for semantic checks. · `SqlToLinq.Tests/TestDbContext.cs`
- [Fuzz tests](https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Tests/FuzzTests.cs): robustness tests · Exercises parser and converter with generated SQL. · `SqlToLinq.Tests/FuzzTests.cs`
- [Random SQL generator](https://github.com/zsivadi/szakmai-gyakorlat/blob/main/SqlToLinq.Tests/RandomSqlGenerator.cs): fuzz input · Generates SQL inputs for robustness coverage. · `SqlToLinq.Tests/RandomSqlGenerator.cs`

## Connections

- CLI host → Compiler core: uses
- SQL grammar → ANTLR parser: generates
- CLI host → ANTLR parser: SQL input
- ANTLR parser → Throwing error listener: syntax failures
- ANTLR parser → SQL visitor: parse tree
- SQL visitor → SQL AST: builds
- SQL AST → AST visualizer: inspect
- SQL AST → SQL-to-LINQ converter: translate
- SQL-to-LINQ converter → LINQ AST: builds
- LINQ AST → LINQ / C# output: generates
- SQL-to-LINQ converter → Roslyn: C# generation
- I/O fixtures → Transpiler tests: fixtures
- Transpiler tests → SQL-to-LINQ converter: validates output
- Semantic equivalence tests → Test DbContext: executes queries
- Semantic equivalence tests → SQL-to-LINQ converter: compares meaning
- Random SQL generator → Fuzz tests: generated inputs
- Fuzz tests → ANTLR parser: exercises parsing
- Fuzz tests → SQL-to-LINQ converter: exercises conversion
