Commit f2bb69d
feat(docs): add Mermaid diagrams for state update, evaluation, and memory flows (#41)
## Description
Added visual documentation for the WASM module's internal operations.
Three Mermaid diagrams illustrate how the evaluator processes flag
configurations, evaluates flags, and manages memory across the host-WASM
boundary.
### Diagrams Added
- **State Update Flow** (sequence diagram after `update_state` API docs)
- Validation modes (strict/permissive) with schema checking
- JSON parsing and flag storage lifecycle
- Error paths for UTF-8, validation, and parse failures
- **Flag Evaluation Flow** (flowchart after `evaluate` API docs)
- Complete evaluation paths: STATIC, DEFAULT, TARGETING_MATCH, DISABLED,
ERROR, FLAG_NOT_FOUND
- Context enrichment: `$flagd.flagKey`, `$flagd.timestamp`,
`targetingKey`
- JSON Logic targeting rule execution
- **Memory Management Flow** (sequence diagram in Memory Model section)
- alloc/dealloc lifecycle with pointer packing: `(ptr << 32) | len`
- Host vs WASM memory ownership boundaries
- Input, processing, and cleanup phases
These complement existing text documentation by showing data flow and
decision points visually.
## Related Issue
Closes #
## Type of Change
- [x] `docs`: Documentation only changes
- [ ] `feat`: New feature (minor version bump)
- [ ] `fix`: Bug fix (patch version bump)
- [ ] `chore`: Maintenance tasks, dependency updates
- [ ] `refactor`: Code refactoring without functional changes
- [ ] `test`: Adding or updating tests
- [ ] `ci`: CI/CD changes
- [ ] `perf`: Performance improvements
- [ ] `build`: Build system changes
- [ ] `style`: Code style/formatting changes
## PR Title Format
**IMPORTANT**: Since we use squash and merge, your PR title will become
the commit message. Please ensure your PR title follows the
[Conventional Commits](https://www.conventionalcommits.org/) format:
```
<type>(<optional-scope>): <description>
```
### Examples:
- `feat(operators): add new string comparison operator`
- `fix(wasm): correct memory allocation bug`
- `docs: update API examples in README`
- `chore(deps): update rust dependencies`
For breaking changes, use `!` after the type/scope or include `BREAKING
CHANGE:` in the PR description:
- `feat(api)!: redesign evaluation API`
## Testing
- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Manual testing performed
- [ ] All tests pass (`cargo test`)
- [ ] Code is formatted (`cargo fmt`)
- [ ] Clippy checks pass (`cargo clippy -- -D warnings`)
- [ ] WASM builds successfully (if applicable)
**N/A** - Documentation-only changes
## Breaking Changes
- [ ] This PR includes breaking changes
- [ ] Documentation has been updated to reflect breaking changes
- [ ] Migration guide included (if needed)
## Additional Notes
Diagrams verified against source code:
- `lib.rs::update_state_internal()` and `storage/mod.rs` → State Update
Flow
- `lib.rs::evaluate_internal()` and `evaluation.rs::evaluate_flag()` →
Flag Evaluation Flow
- `memory.rs` (wasm_alloc, wasm_dealloc, pack_ptr_len) → Memory
Management Flow
Total: 130 lines added, 3 diagrams, all using GitHub-compatible Mermaid
syntax.
<!-- START COPILOT ORIGINAL PROMPT -->
<details>
<summary>Original prompt</summary>
> ## Problem
>
> The README documentation currently lacks visual representations of the
state update and evaluation flows, which makes it harder for developers
to understand how the WASM module interacts with host applications and
how the internal evaluation process works.
>
> ## Solution
>
> Add three Mermaid diagrams to the README.md to illustrate:
>
> 1. **State Update Flow** - Shows the sequence of operations when
updating flag configuration state, including validation and storage
> 2. **Flag Evaluation Flow** - Shows the complete evaluation process
from flag retrieval through context enrichment to targeting rule
evaluation
> 3. **Memory Management Flow** - Shows the memory
allocation/deallocation lifecycle for WASM calls
>
> ## Implementation Details
>
> ### 1. State Update Flow Diagram
>
> Add after the `update_state` API documentation (around line 306),
showing:
> - Host allocates memory and writes config JSON
> - WASM parses JSON
> - Schema validation (with strict/permissive mode handling)
> - Storage of flag configuration
> - Memory cleanup
>
> ### 2. Flag Evaluation Flow Diagram
>
> Add after the `evaluate` API documentation (around line 380), showing:
> - Memory allocation for flag key and context
> - Flag retrieval from storage
> - Handling of DISABLED and STATIC flags
> - Context enrichment (adding `$flagd.flagKey`, `$flagd.timestamp`,
`targetingKey`)
> - JSON Logic evaluation of targeting rules
> - Variant resolution
> - Memory cleanup
>
> ### 3. Memory Management Flow Diagram
>
> Add in the "Memory Model & Safety" section (around line 693), showing:
> - Complete lifecycle from alloc to dealloc
> - Pointer packing/unpacking
> - Clear distinction between host and WASM responsibilities
>
> ## Acceptance Criteria
>
> - [ ] All three Mermaid diagrams are added to README.md
> - [ ] Diagrams are placed in logical locations within the existing
documentation structure
> - [ ] Diagrams accurately represent the actual code flow
> - [ ] Syntax is valid Mermaid that renders correctly on GitHub
> - [ ] Existing documentation formatting is preserved
>
> ## Additional Context
>
> This enhancement will improve developer experience by providing visual
documentation that complements the existing text-based API
documentation.
</details>
<!-- START COPILOT CODING AGENT SUFFIX -->
*This pull request was created as a result of the following prompt from
Copilot chat.*
> ## Problem
>
> The README documentation currently lacks visual representations of the
state update and evaluation flows, which makes it harder for developers
to understand how the WASM module interacts with host applications and
how the internal evaluation process works.
>
> ## Solution
>
> Add three Mermaid diagrams to the README.md to illustrate:
>
> 1. **State Update Flow** - Shows the sequence of operations when
updating flag configuration state, including validation and storage
> 2. **Flag Evaluation Flow** - Shows the complete evaluation process
from flag retrieval through context enrichment to targeting rule
evaluation
> 3. **Memory Management Flow** - Shows the memory
allocation/deallocation lifecycle for WASM calls
>
> ## Implementation Details
>
> ### 1. State Update Flow Diagram
>
> Add after the `update_state` API documentation (around line 306),
showing:
> - Host allocates memory and writes config JSON
> - WASM parses JSON
> - Schema validation (with strict/permissive mode handling)
> - Storage of flag configuration
> - Memory cleanup
>
> ### 2. Flag Evaluation Flow Diagram
>
> Add after the `evaluate` API documentation (around line 380), showing:
> - Memory allocation for flag key and context
> - Flag retrieval from storage
> - Handling of DISABLED and STATIC flags
> - Context enrichment (adding `$flagd.flagKey`, `$flagd.timestamp`,
`targetingKey`)
> - JSON Logic evaluation of targeting rules
> - Variant resolution
> - Memory cleanup
>
> ### 3. Memory Management Flow Diagram
>
> Add in the "Memory Model & Safety" section (around line 693), showing:
> - Complete lifecycle from alloc to dealloc
> - Pointer packing/unpacking
> - Clear distinction between host and WASM responsibilities
>
> ## Acceptance Criteria
>
> - [ ] All three Mermaid diagrams are added to README.md
> - [ ] Diagrams are placed in logical locations within the existing
documentation structure
> - [ ] Diagrams accurately represent the actual code flow
> - [ ] Syntax is valid Mermaid that renders correctly on GitHub
> - [ ] Existing documentation formatting is preserved
>
> ## Additional Context
>
> This enhancement will improve developer experience by providing visual
documentation that complements the existing text-based API
documentation.
<!-- START COPILOT CODING AGENT TIPS -->
---
💬 We'd love your input! Share your thoughts on Copilot coding agent in
our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: aepfli <9987394+aepfli@users.noreply.github.com>1 parent 628493b commit f2bb69d
1 file changed
Lines changed: 129 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
307 | 349 | | |
308 | 350 | | |
309 | 351 | | |
| |||
379 | 421 | | |
380 | 422 | | |
381 | 423 | | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
382 | 469 | | |
383 | 470 | | |
384 | 471 | | |
| |||
704 | 791 | | |
705 | 792 | | |
706 | 793 | | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
707 | 836 | | |
708 | 837 | | |
709 | 838 | | |
| |||
0 commit comments