# Architecture _This is intended as a high-level overview of the structure of Glint and its fundamental design. For background on the idea, see [this writeup][matklad]._ ## Overview Glint is fundamentally a tool for mapping Glimmer templates into a corresponding TypeScript AST with semantics appropriate for type checking those templates as though they were a normal TypeScript program.
The goal is _not_ to represent templates as a direct or naïve equivalent of their runtime semantics. Instead, it aims to produce a TS AST which is both _accurate_ and also _useful_. - _accurate_: Glint should never produce an incorrect diagnostic or âfixâ, and it should also correctly resolve symbols (components, helpers, etc.) - _useful_: Glint should produce diagnostics which actually make sense, and which should be actionable; and it should provide appropriate autocomplete, go-to-def, and refactoring for all the constructs which are part of a template Both of these constraints are obviousâwhat tool _doesnât_ aim to be both accurate and useful?âbut âusefulâ is the reason for many of the specific design choices in Glintâs internals. In particular, Glint uses representations which allow _preservation of parametricity_ and which support _error messages which match the userâs intuition_. - _preservation of parametricity_: this bit of formal jargon just means that we need to keep around the types of parameters, i.e. component, helper, and modifier argumentsâand in particular, we need to keep around _type parameters_ (generics) in ways that avoid collapsing into whatever the default TS falls back to is, usually `unknown`. - _error messages which match the userâs intuition_: when a user invokes a component or helper, we need to make sure the resulting error message is something that makes sense, so we need to capture enough information to handle things like (for just one of a number of possible examples) Glimmerâs notion of named and positional argumentsâa concept which has no _direct_ translation into TypeScript. Ultimately this transformation from a template AST to a TypeScript AST produces a TypeScript module (an extension of the base TypeScript module when there is one) which embeds in the templateâs position a set of function calls representing the kind of thing emitted by each operation in the template. This synthesized module is never persisted to disk.[^debug] Instead, it is presented to the TS compiler, either via a programmatically constructed compiler instance for command line runs or via a language server instance for code editor operations. The results from the TS check are then mapped back to the original template provide diagnostics in the correct location, and sometimes further massaged or rewritten to make them make sense in terms of templates rather than the TS representation of templates. [^debug]: It is possible to write to disk with a debug flag, but the statement holds for all normal operations. ## Code structure Glint is composed of the following major components: ### Template DSL **Role:** a set of TypeScript type definitions which Glint uses as the TypeScript representation of the constituent elements of a template: content, elements, components, expressions, `...attributes`, modifiers, and templates themselves (with or without backing class contexts). The DSL defines three broad things: - What it means to _emit_ some template content, i.e. what the semantics of emitting `
[matklad]: https://matklad.github.io/2021/02/06/ARCHITECTURE.md.html [^env]: Each environment is specific to a single context (âenvironmentâ) like Ember, GlimmerX, etc. Accordingly, they are likely to move _out_ of the Glint monorepo in the long-term, but will remain part of the Glint ecosystem and working model.