# Architecture

MoonSpell is split into four layers.

1. `encoding.mbt`: byte decoding for UTF-8, ISO-8859-1, ISO-8859-2 and ISO-8859-15, plus affix-file encoding detection.
2. `aff.mbt` / `dic.mbt`: structured parsing of Hunspell directives, affixes, compounds and dictionary entries. `Dictionary` includes a hash index for exact lookup.
3. `engine.mbt`: spelling checks, case handling, affix chains, compound searches, break handling, conversions, KEEPCASE/FORBIDDENWORD and force-uppercase rules.
4. `suggest.mbt` / `analysis.mbt`: REP/MAP/PHONE/`ph:`/NGRAM suggestions, morphology analysis, explanation and JSON serialization.

The CLI in `cmd/main` is a thin adapter over the public library. `cmd/bench` measures load and query behavior, and `examples/basic` is the smallest runnable integration example.
