Skip to content

Conversation

@arkanoider
Copy link
Collaborator

@arkanoider arkanoider commented Jan 3, 2026

📚 Documentation Updates

This PR expands the Mostrix documentation with new guides and improvements to existing ones, making the codebase more accessible for both developers and AI-assisted development.

✨ New Documentation Files

1. CODING_STANDARDS.md - Code Quality Guidelines

Comprehensive coding standards document covering:

  • Core Principles: Readability, DRY, simplicity, 300-line function limit, module organization
  • Rust-Specific Guidelines: Error handling patterns, type safety, async/await best practices
  • Code Organization: Module structure patterns, re-export conventions
  • Testing & Quality: Pre-commit checklist, clippy guidelines
  • Naming Conventions: Consistent naming across the project
  • State Management: Patterns for shared state with Arc<Mutex<T>>

This document serves as a reference for code reviews and helps maintain consistency across the codebase.

2. RANGE_ORDERS.md - Variable Amount Orders Guide

Dedicated guide for range orders functionality:

  • How Range Orders Work: Variable amounts within min/max range (e.g., 100-400 USD)
  • NextTrade Payload: Mechanism for informing Mostro daemon about next trade key before completing trades
  • Range Order Logic: Step-by-step explanation of remaining amount calculation and new order creation
  • Example Flow: Sequence diagram showing the complete flow when a range order trade completes
  • Key Points: Privacy considerations and key derivation for new orders

This guide explains a complex feature that was previously undocumented, making it easier for developers to understand and maintain range order functionality.

3. ADMIN_DISPUTES.md - Admin Dispute Resolution Guide

Comprehensive guide for admin mode dispute resolution functionality:

  • Admin Mode Overview: How admin mode is activated and configured with admin_privkey
  • Admin Tabs: Complete documentation of all 5 admin tabs (Disputes, Add Solver, Disputes with Buyer, Disputes with Seller, Settings)
  • Dispute States: Full documentation of the 5 dispute states (Initiated, InProgress, SellerRefunded, Settled, Released) with state transition diagram
  • SolverDisputeInfo Struct: Complete field-by-field documentation of the struct admins receive when taking a dispute
  • Workflow Diagrams: Sequence diagrams for taking disputes, adding solvers, and chatting with parties
  • Security Considerations: Admin key management, dispute assignment, and communication security
  • Visual Safety Features: Color-coded tabs to prevent sending messages to wrong parties

This guide provides complete context for understanding and implementing admin dispute resolution workflows.

4. DATABASE.md - Database Schema and Persistence Guide

Complete database schema and persistence documentation:

  • Database Location & Initialization: Where the database is stored (~/.mostrix/mostrix.db) and how it's created
  • Table Schemas: Full documentation of both tables:
    • users table: Identity, mnemonic, and trade index tracking (4 fields)
    • orders table: Order details and critical trade keys (17 fields)
  • Field Descriptions: Detailed explanation of all database fields with their purposes
  • Key Relationships: How last_trade_index and trade_keys work together for key derivation
  • Stateless Recovery: Documentation of the "fetch-on-startup" strategy
  • Security Considerations: Protection measures for sensitive data (mnemonics, trade keys)
  • Database Operations: Common operations with code references

This guide is essential for understanding what data is persisted and why, critical for key management and trade recovery.

🔄 Updated Documentation

MESSAGE_FLOW_AND_PROTOCOL.md

  • Converted flowcharts to sequence diagrams: More compact and better suited for showing interactions between components over time
  • Extracted range orders: Moved detailed range order documentation to dedicated file for better readability
  • Added cross-references: Links to related documentation for easier navigation

TUI_INTERFACE.md

  • Added admin solver tab note: Documentation of the Add Solver functionality
  • Updated admin tabs section: Added separate buyer/seller chat tabs with color coding information
  • Added cross-reference: Link to ADMIN_DISPUTES.md for detailed admin workflows

README.md

  • Updated documentation index: Added links to all new guides (CODING_STANDARDS, RANGE_ORDERS, ADMIN_DISPUTES, DATABASE)
  • Streamlined tips section: Replaced inline rules with reference to CODING_STANDARDS.md

🎯 Benefits

  1. Better Organization: Documentation is now modular and easier to navigate
  2. AI Context: Comprehensive guides provide better context for AI-assisted development
  3. Code Quality: Coding standards document helps maintain consistency
  4. Feature Documentation: Complex features (range orders, admin disputes) now have dedicated, detailed documentation
  5. Database Understanding: Clear documentation of data persistence and key management
  6. Visual Improvements: Sequence diagrams are more compact and clearer than flowcharts
  7. Complete Workflows: Admin dispute resolution workflows are fully documented with state transitions

📝 Files Changed

  • docs/CODING_STANDARDS.md (new)
  • docs/RANGE_ORDERS.md (new)
  • docs/ADMIN_DISPUTES.md (new)
  • docs/DATABASE.md (new)
  • 📝 docs/MESSAGE_FLOW_AND_PROTOCOL.md (refactored)
  • 📝 docs/TUI_INTERFACE.md (updated)
  • 📝 docs/README.md (updated index)

All documentation follows the same structure and style as existing guides, ensuring consistency across the documentation set.

Summary by CodeRabbit

  • Documentation
    • Added comprehensive guides: Key Management (deterministic key derivation, trade key strategy, recovery), Message & Protocol Flows (Gift Wrap/NIP-59 and Encrypted DM/NIP-44 flows, error handling, recovery), TUI Interface, Startup & Configuration, Range Orders, Admin Disputes, Database schema, and Coding Standards
    • New documentation index with quick links for navigation
    • Removed the previous ARCHITECTURE overview file

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 3, 2026

Walkthrough

Adds multiple developer-facing documentation files (key management, protocols, startup/config, TUI, database, range orders, admin disputes, coding standards, README) and removes ARCHITECTURE.md; all changes are documentation-only and do not modify code or public APIs.

Changes

Cohort / File(s) Summary
Docs index & standards
docs/README.md, docs/CODING_STANDARDS.md, docs/ARCHITECTURE.md
Added README and coding standards; removed ARCHITECTURE.md. README provides quick links and guide index; CODING_STANDARDS.md prescribes project conventions and examples.
Startup & runtime / DB
docs/STARTUP_AND_CONFIG.md, docs/DATABASE.md
New startup/config and database guides covering initialization sequence, settings, Nostr client setup, background tasks, DB location/schema (users, orders), persistence semantics, and stateless recovery on startup.
Key management & recovery
docs/KEY_MANAGEMENT.md
New key-management doc describing deterministic key derivation (BIP-39, NIP-06), derivation paths, identity (index 0) vs trade keys (index 1+), trade index incrementing, DB persistence schemas, derivation logic for trade keys, and stateless recovery strategy.
Protocols & message flows
docs/MESSAGE_FLOW_AND_PROTOCOL.md, docs/RANGE_ORDERS.md
Added protocol documentation covering NIP-59 Gift Wrap and NIP-44 Encrypted DMs, end-to-end create/take order flows, message construction/parsing, listener behavior, error handling patterns, and range-order next-trade payload / partial-fill logic.
TUI & admin features
docs/TUI_INTERFACE.md, docs/ADMIN_DISPUTES.md
TUI_INTERFACE documents Ratatui-based UI, AppState layout, input handling, state machines and components; ADMIN_DISPUTES describes dispute states, flows, admin actions, and related data structures.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I nibble through docs, a careful hop,
Keys, flows, and TUI carrots in my crop,
Pages stacked neat, each path and protocol bright,
I bound through DB indices and message light,
A rabbit cheers — documentation delight! 📜🥕

Pre-merge checks

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The PR title 'Added markdown files for AI context' is vague and generic, using non-descriptive language that doesn't convey the substantive documentation improvements made. Consider a more specific title like 'Add comprehensive documentation for key management, database, range orders, and admin disputes' to better reflect the scope and purpose of the changes.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 80c91bf and 01c92ff.

📒 Files selected for processing (3)
  • docs/ADMIN_DISPUTES.md
  • docs/CODING_STANDARDS.md
  • docs/DATABASE.md

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@arkanoider arkanoider marked this pull request as draft January 3, 2026 22:44
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
docs/MESSAGE_FLOW_AND_PROTOCOL.md (1)

338-342: Minor style improvement: reduce repetitive sentence starters.

Lines 339–341 contain three successive list items beginning with "It", which reduces readability. Reword to add variety in sentence structure.

🔎 Proposed style improvement

Current:

1. **On startup**, the client retrieves all active order IDs and their `trade_index` from the database.
2. **It re-derives the trade keys** for each active order.
3. **It queries Nostr relays** for recent Gift Wrap events directed to those trade public keys.
4. **It reconstructs the current state** of each trade by parsing the latest messages.

Suggested:

1. **On startup**, the client retrieves all active order IDs and their `trade_index` from the database.
2. **Trade keys are re-derived** for each active order.
3. **Nostr relays are queried** for recent Gift Wrap events directed to those trade public keys.
4. **The current state is reconstructed** for each trade by parsing the latest messages.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fa96c27 and 28ceb77.

📒 Files selected for processing (5)
  • docs/KEY_MANAGEMENT.md
  • docs/MESSAGE_FLOW_AND_PROTOCOL.md
  • docs/README.md
  • docs/STARTUP_AND_CONFIG.md
  • docs/TUI_INTERFACE.md
🧰 Additional context used
🪛 LanguageTool
docs/MESSAGE_FLOW_AND_PROTOCOL.md

[style] ~341-~341: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...rected to those trade public keys. 4. It reconstructs the current state of eac...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

🪛 markdownlint-cli2 (0.18.1)
docs/KEY_MANAGEMENT.md

77-77: Multiple headings with the same content

(MD024, no-duplicate-heading)

🔇 Additional comments (4)
docs/STARTUP_AND_CONFIG.md (1)

1-240: Document structure and content are clear and comprehensive.

The documentation effectively outlines the startup sequence with well-organized sections, clear code references, and inline source paths. The progression from settings → database → logger → TUI → main loop provides a logical entry point for understanding the codebase.

docs/README.md (1)

1-14: Clear and effective documentation index.

The README provides a well-organized entry point with links to all core guides and helpful quick-reference commands. The structure supports easy navigation for developers and AI-assisted development workflows.

docs/TUI_INTERFACE.md (1)

1-155: Documentation is comprehensive and well-structured.

The TUI Interface guide effectively explains the architecture, state management, navigation patterns, and key components with clear explanations and consistent code references. All code references point to valid file locations and line numbers.

docs/MESSAGE_FLOW_AND_PROTOCOL.md (1)

1-342: Documentation is thorough and well-organized.

The Message Flow & Protocol guide provides excellent detail on order creation, taking orders, background listening, message parsing, and error handling. The step-by-step flows with inline code references make the complex Nostr/Gift Wrap interactions clear and traceable to implementation. The inclusion of error handling patterns and stateless recovery strategy is particularly valuable for understanding resilience. All code references are accurate and properly line-mapped to the current codebase.

}
```

## Database Persistence
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove duplicate heading to fix document structure.

The heading "## Database Persistence" appears twice (lines 57 and 77), creating a malformed section. The content between lines 57–95 should be consolidated under a single heading since it all covers database persistence topics (users table, orders table, derivation logic).

🔎 Proposed fix: Remove the duplicate heading at line 77
-## Database Persistence
-
 Maintaining the state of trade indices is **critical**. If the `trade_index` associated with an order is lost, the client will be unable to decrypt messages from Mostro or the counterparty for that specific trade.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## Database Persistence
Maintaining the state of trade indices is **critical**. If the `trade_index` associated with an order is lost, the client will be unable to decrypt messages from Mostro or the counterparty for that specific trade.
🧰 Tools
🪛 markdownlint-cli2 (0.18.1)

77-77: Multiple headings with the same content

(MD024, no-duplicate-heading)

🤖 Prompt for AI Agents
In docs/KEY_MANAGEMENT.md around lines 57 to 77 there is a duplicated "##
Database Persistence" heading (the second occurrence at line 77) which breaks
document structure; remove the duplicate heading at line 77 so all content
covering users table, orders table, and derivation logic is consolidated under
the single heading, then run a quick sweep to ensure no other identical headings
remain and adjust any anchor links or table of contents references if necessary.

@arkanoider arkanoider requested review from Catrya and grunch January 3, 2026 22:46
- Add CODING_STANDARDS.md with comprehensive code quality guidelines
  - Core principles (readability, DRY, simplicity, function limits)
  - Rust-specific best practices
  - Module organization patterns
  - Testing and quality checklist

- Add RANGE_ORDERS.md dedicated guide for variable amount orders
  - Explains range order mechanics (min/max amounts)
  - Documents NextTrade payload mechanism
  - Includes sequence diagram for trade completion flow
  - Key points on privacy and key derivation

- Refactor MESSAGE_FLOW_AND_PROTOCOL.md
  - Convert flowcharts to compact sequence diagrams
  - Extract range orders to separate file for better readability
  - Add reference link to RANGE_ORDERS.md

- Update README.md documentation index
  - Add links to new documentation files
  - Keep tips section concise with reference to standards

These additions improve documentation organization and provide critical
context for AI-assisted development and code reviews.
- Add ADMIN_DISPUTES.md: Comprehensive guide for admin dispute resolution
  - Admin tabs and workflows (Disputes, Add Solver, Buyer/Seller chat)
  - Dispute states and transitions with state diagram
  - SolverDisputeInfo struct documentation
  - Security considerations and implementation status

- Add DATABASE.md: Database schema and persistence guide
  - Users and orders table schemas with field descriptions
  - Key relationships and trade index tracking
  - Stateless message recovery strategy
  - Security considerations for sensitive data

- Update TUI_INTERFACE.md: Add admin solver tab note
- Update README.md: Add links to new documentation files
@arkanoider
Copy link
Collaborator Author

@coderabbitai please review

@arkanoider arkanoider marked this pull request as ready for review January 4, 2026 18:12
@coderabbitai
Copy link

coderabbitai bot commented Jan 4, 2026

@arkanoider: I'll review the documentation changes in this PR.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
docs/RANGE_ORDERS.md (1)

47-66: Document edge case: what happens when a trade takes exactly the remaining amount.

The logic correctly handles the case when remaining < min_amount (no new order created), but it's worth explicitly clarifying the behavior when remaining == fiat_amount (original order fully consumed). Adding a note like "If the entire max_amount is consumed in a single trade, no NextTrade payload is sent" would improve clarity.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 28ceb77 and 34cd863.

📒 Files selected for processing (8)
  • ARCHITECTURE.md
  • docs/ADMIN_DISPUTES.md
  • docs/CODING_STANDARDS.md
  • docs/DATABASE.md
  • docs/MESSAGE_FLOW_AND_PROTOCOL.md
  • docs/RANGE_ORDERS.md
  • docs/README.md
  • docs/TUI_INTERFACE.md
💤 Files with no reviewable changes (1)
  • ARCHITECTURE.md
✅ Files skipped from review due to trivial changes (1)
  • docs/ADMIN_DISPUTES.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • docs/MESSAGE_FLOW_AND_PROTOCOL.md
  • docs/README.md
🧰 Additional context used
🪛 LanguageTool
docs/DATABASE.md

[grammar] ~129-~129: Use a hyphen to join words.
Context: ...method|TEXT| Payment method (comma separated list of methods). | |premium...

(QB_NEW_EN_HYPHEN)

🪛 markdownlint-cli2 (0.18.1)
docs/CODING_STANDARDS.md

126-126: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (4)
docs/TUI_INTERFACE.md (1)

1-158: Comprehensive and well-structured TUI documentation.

The documentation clearly explains the TUI architecture, from AppState as the single source of truth through the nested state machine design (UiMode → UserMode/AdminMode) to input handling and component organization. The use of source references and concrete examples (e.g., layout chunks, color coding) makes this accessible to both developers and AI systems. Role-based tab switching and overlay rendering are well-explained, and cross-references to related documentation (ADMIN_DISPUTES.md) provide good navigation.

docs/RANGE_ORDERS.md (3)

1-100: Strong documentation structure for a complex feature.

The documentation provides a clear, multi-layered explanation of range orders: conceptual overview, implementation details with code reference, logic walkthrough, and visual flow diagram. The progression from "how it works" to "why and when it works" to "what it looks like in practice" should serve both human developers and AI systems well.


68-93: Sequence diagram clearly illustrates branching behavior.

The Mermaid diagram effectively shows both the happy path (remaining amount triggers NextTrade) and the alternative path (insufficient remaining amount). The diagram correctly depicts the interaction between Client, DB, key derivation, and Mostro, making the flow easy to follow.


20-45: Source file path and code snippet are accurate.

Verification confirms that src/util/order_utils/execute_send_msg.rs exists at the specified location and lines 17–45 contain the exact code snippet shown in the documentation. The implementation is current and matches the documented behavior.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 34cd863 and 80c91bf.

📒 Files selected for processing (1)
  • docs/DATABASE.md
🧰 Additional context used
🪛 markdownlint-cli2 (0.18.1)
docs/DATABASE.md

9-9: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (1)
docs/DATABASE.md (1)

1-258: Comprehensive documentation with good structure and cross-references.

The documentation is well-organized, technically accurate, and provides clear explanations of the database schema, initialization flow, table relationships, and security considerations. The inline source code references provide helpful context. The document's cross-references to related documentation (KEY_MANAGEMENT.md, MESSAGE_FLOW_AND_PROTOCOL.md, STARTUP_AND_CONFIG.md) align with the PR's goal of modularizing documentation. The past review's hyphenation issue at line 129 has already been addressed (uses "comma-separated" correctly).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants