|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +ODict is a fast, portable dictionary file format. XML source files (.odxml) compile to compact binary dictionaries (.odict) using CBOR serialization and Brotli compression. The project is a Rust workspace monorepo with language bindings for Node.js and Python. |
| 8 | + |
| 9 | +## Build & Development Commands |
| 10 | + |
| 11 | +This project uses `mise` as the monorepo task runner. All tasks are defined in `mise.toml` and per-crate `mise.toml` files. |
| 12 | + |
| 13 | +### Core Commands |
| 14 | + |
| 15 | +| Command | Purpose | |
| 16 | +|---------|---------| |
| 17 | +| `mise build` | Build the CLI binary | |
| 18 | +| `mise build:all` | Build all packages (CLI, lib, node, python) | |
| 19 | +| `mise test` | Run core Rust tests (lib + cli + internal) | |
| 20 | +| `mise test:all` | Run all tests including language bindings | |
| 21 | +| `mise lint` | Lint all Rust code (clippy + per-crate lints) | |
| 22 | +| `mise fix` | Auto-fix clippy warnings | |
| 23 | +| `mise format` | Format all Rust code (`cargo fmt --all`) | |
| 24 | +| `mise snapshot` | Accept insta snapshot updates (`cargo insta accept`) | |
| 25 | +| `mise bench` | Run criterion benchmarks | |
| 26 | +| `mise setup` | Install all dependencies | |
| 27 | + |
| 28 | +### Running a Single Test |
| 29 | + |
| 30 | +```bash |
| 31 | +# By test name |
| 32 | +cargo nextest run -p odict --all-features <test_name> |
| 33 | + |
| 34 | +# By crate |
| 35 | +cargo nextest run -p odict-cli --all-features |
| 36 | +``` |
| 37 | + |
| 38 | +### Language Binding Development |
| 39 | + |
| 40 | +**Node** (`crates/node/`): Uses napi-rs, yarn 4, AVA for tests, oxlint + prettier for linting. |
| 41 | +```bash |
| 42 | +cd crates/node && mise test # runs yarn test (AVA) |
| 43 | +cd crates/node && mise build # builds native extension |
| 44 | +``` |
| 45 | + |
| 46 | +**Python** (`crates/python/`): Uses PyO3 + maturin, pytest + syrupy for snapshot tests, ruff for linting. |
| 47 | +```bash |
| 48 | +cd crates/python && mise test # runs pytest |
| 49 | +cd crates/python && mise build # builds wheel via maturin |
| 50 | +``` |
| 51 | + |
| 52 | +## Architecture |
| 53 | + |
| 54 | +### Workspace Crates |
| 55 | + |
| 56 | +``` |
| 57 | +crates/ |
| 58 | +├── lib/ → `odict` - Core library (cdylib + staticlib + rlib) |
| 59 | +│ All dictionary logic: compile, lookup, search, merge, serialize |
| 60 | +├── cli/ → `odict-cli` - CLI binary (clap-based) |
| 61 | +│ Subcommands: alias, compile, download, dump, index, info, |
| 62 | +│ lexicon, lookup, merge, new, search, serve, tokenize |
| 63 | +├── internal/ → `internal` - Shared internal utilities (not published) |
| 64 | +├── node/ → Node.js NAPI bindings |
| 65 | +└── python/ → Python PyO3 bindings |
| 66 | +``` |
| 67 | + |
| 68 | +### Feature Flags (lib crate) |
| 69 | + |
| 70 | +The lib has extensive feature flags controlling optional functionality: |
| 71 | + |
| 72 | +- **default**: `sql`, `config` |
| 73 | +- **search**: Full-text search via tantivy |
| 74 | +- **http**: Remote dictionary fetching via reqwest |
| 75 | +- **html/markdown**: Markup rendering in definitions |
| 76 | +- **alias**: Named dictionary shortcuts |
| 77 | +- **tokenize**: Text tokenization (with per-language sub-features: `tokenize-chinese`, `tokenize-japanese`, `tokenize-thai`, etc.) |
| 78 | + |
| 79 | +The CLI enables: `sql`, `search`, `http`, `alias`, `html`, `tokenize`. |
| 80 | + |
| 81 | +### Key Patterns |
| 82 | + |
| 83 | +- **Error handling**: `thiserror` derive macros with a central `Error` enum per crate; `Result<T> = Result<T, Error>` alias |
| 84 | +- **Serialization**: `rkyv` for zero-copy deserialization of dictionary data, `serde` for config/interchange formats |
| 85 | +- **Testing**: `cargo-nextest` runner, `insta` for snapshot assertions, test dictionaries loaded via `LazyLock` from `examples/` directory |
| 86 | +- **XML Schema**: Dictionary format defined in `odict.xsd` |
| 87 | + |
| 88 | +### Data Flow |
| 89 | + |
| 90 | +XML source (.odxml) → `quick-xml` parser → internal AST → `rkyv` serialization → Brotli compression → .odict binary |
| 91 | + |
| 92 | +Lookup: .odict binary → Brotli decompression → `rkyv` zero-copy access → results |
| 93 | + |
| 94 | +## CI/CD |
| 95 | + |
| 96 | +- **ci.yml**: Builds and tests on Linux/macOS/Windows |
| 97 | +- **node.yml**: Builds native extensions for 14+ platforms, publishes to npm |
| 98 | +- **python.yml**: Builds wheels for multiple architectures, publishes to PyPI |
| 99 | +- **release-please.yml**: Automated version bumping and release PRs (lib+cli linked, node/python separate) |
| 100 | + |
| 101 | +## Release Configuration |
| 102 | + |
| 103 | +Release profiles use `lto = true`, `codegen-units = 1`, `strip = true`, `opt-level = 3` for maximum optimization. Distribution builds (`profile.dist`) use `lto = "thin"` for faster CI builds. |
| 104 | + |
| 105 | +Cross-compilation targets are configured in `.cargo/config.toml` (Windows static CRT, ARM linker settings). |
0 commit comments