# atproto_codegen
> **Alpha.** Pre-1.0 and evolving alongside
> [at-record](https://tangled.org/@mokkenstorm.dev/at-record); expect breaking
> changes between 0.x releases.
Generate Gleam types and JSON codecs from [atproto lexicon](https://atproto.com/specs/lexicon)
files: records and objects with string/integer/number/boolean/array/ref/
cid-link/bytes/blob/unknown fields. Unsupported defs (e.g. `union`) are
reported and skipped, never emitted wrong.
## Usage
```sh
gleam run -m atproto_codegen -- <lexicons_dir> <out_dir> <out_module> <nsid_prefix>[,<nsid_prefix>...]
# e.g.
gleam run -m atproto_codegen -- ./lexicons ./src/my_app/gen my_app/gen com.example.myapp.,com.atproto.
```
- `lexicons_dir` is walked recursively for `*.json` lexicon files. Vendor any
external lexicons you reference (e.g. `com.atproto.repo.strongRef`) into it.
- `out_module` is the module prefix the generated code imports itself under;
it must match where `out_dir` sits in your `src/`.
- `nsid_prefixes` are stripped from NSIDs when deriving module paths, so
`com.example.myapp.shelf.entry` emits `<out_dir>/shelf/entry.gleam`.
Generated `blob` fields use `atproto/blob` from the
[`atproto_client`](../atproto_client) package, so projects consuming generated
code with blobs need that dependency.
## Lexicon coverage
`record` and `object` defs. Refs resolve across lexicons (a bare NSID ref
points at that lexicon's `main` def). `knownValues` string sets map to plain
`String`; `unknown` round-trips through a `Dynamic` passthrough.