Skip to content

Conversation

@ajmcquilkin
Copy link
Collaborator

This PR refactors the IPC command handlers by introducing a layered architecture to improve code organization, maintainability, and testability.

The responsibility of a command is solely to manage Tauri dependency injection and delegate all work to the domain. A domain handles the business logic required with fulfilling a command. A primitive is a struct that defines part of the contract between the Rust and TypeScript layers of the application.

In the long-term, primitives will have TypeScript types generated for use in TypeScript, which will replace the legacy generation flow which currently generates types for all protobuf types. Long-term this also opens up the possibility of removing the specta type generation from the meshtastic-rust SDK as it's always been somewhat buggy.

Changes

New Architecture:

  • API Contracts (src-tauri/src/api/contracts/) - Type-safe request/response types for all commands across connections, graph, mesh, and radio modules
  • API Primitives (src-tauri/src/api/primitives/) - Shared primitive types and data structures used across the API surface
  • Domain Layer (src-tauri/src/domains/) - Extracted business logic from IPC handlers into dedicated domain modules containing the core functionality

Refactored Modules:

  • ipc/commands/connections.rs - Significantly reduced from 340+ lines by delegating to domain layer
  • ipc/commands/graph.rs - Streamlined command handlers
  • ipc/commands/mesh.rs - Simplified to focus on IPC concerns only
  • ipc/commands/radio.rs - Extracted radio logic into domain module

Frontend Updates:

  • Updated TypeScript API clients to align with new contract definitions

Benefits:

  • Separation of Concerns - IPC handlers are now thin wrappers that delegate to domain logic
  • Testability - Domain logic can be tested independently of the IPC layer
  • Type Safety - Explicit request/response contracts improve type safety across the stack
  • Maintainability - Business logic is centralized and easier to modify

@ajmcquilkin ajmcquilkin requested a review from Copilot October 29, 2025 07:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the Tauri IPC (Inter-Process Communication) layer by introducing a structured API contract pattern. The changes separate concerns by creating dedicated request/response types and moving business logic from IPC command handlers into domain layer handlers.

Key changes:

  • Introduced structured request/response contracts for all IPC commands with type-safe definitions
  • Created a domain layer (domains/ modules) that contains the actual business logic
  • Updated IPC command handlers to simply delegate to domain handlers
  • Modified TypeScript API calls to wrap parameters in a request object and unwrap responses

Reviewed Changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/api/mesh.ts Updated to wrap parameters in request objects for mesh operations
src/api/graph.ts Updated to wrap parameters in request objects and unwrap graph responses
src/api/connection.ts Updated to wrap parameters in request objects and unwrap connection responses
src-tauri/src/lib.rs Added new api and domains module declarations
src-tauri/src/ipc/commands/radio.rs Refactored to delegate to domain handlers with new request/response types
src-tauri/src/ipc/commands/mesh.rs Refactored to delegate to domain handlers with new request/response types
src-tauri/src/ipc/commands/graph.rs Refactored to delegate to domain handlers with new request/response types
src-tauri/src/ipc/commands/connections.rs Refactored to delegate to domain handlers with new request/response types
src-tauri/src/graph/ds/graph.rs Removed extraneous blank line
src-tauri/src/domains/radio.rs New file containing radio-related business logic handlers
src-tauri/src/domains/mesh.rs New file containing mesh-related business logic handlers
src-tauri/src/domains/graph.rs New file containing graph-related business logic handlers
src-tauri/src/domains/connections.rs New file containing connection-related business logic handlers
src-tauri/src/domains/mod.rs Module declarations for domain layer
src-tauri/src/api/primitives/radio.rs Type definitions for radio primitives
src-tauri/src/api/primitives/mesh.rs Type definitions for mesh primitives
src-tauri/src/api/primitives/graph.rs Type definitions for graph primitives
src-tauri/src/api/primitives/connections.rs Type definitions for connection primitives
src-tauri/src/api/primitives/mod.rs Module declarations for API primitives
src-tauri/src/api/contracts/radio.rs Request/response contract definitions for radio operations
src-tauri/src/api/contracts/mesh.rs Request/response contract definitions for mesh operations
src-tauri/src/api/contracts/graph.rs Request/response contract definitions for graph operations
src-tauri/src/api/contracts/connections.rs Request/response contract definitions for connection operations
src-tauri/src/api/contracts/mod.rs Module declarations for API contracts
src-tauri/src/api/mod.rs Module declarations for API layer

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

ajmcquilkin and others added 3 commits October 29, 2025 01:53
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@ajmcquilkin ajmcquilkin merged commit 2a3817a into main Nov 2, 2025
19 checks passed
@ajmcquilkin ajmcquilkin deleted the ajmcquilkin/refactor-command-logic branch November 2, 2025 05:16
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