Skip to content

Conversation

@okjodom
Copy link
Contributor

@okjodom okjodom commented Aug 20, 2025

Reorganize fmcd from monolithic binary into single crate that publishes
both library and binary, following FMCD_LIBBIN.md design.

Changes:

  • Move business logic to src/core/ (multimint, operations, services)
  • Move API handlers to src/api/ (REST routes, WebSocket handlers)
  • Create FmcdCore as central business logic interface
  • Add library entry point at src/lib.rs, binary at src/bin/main.rs
  • Simplify AppState to delegate to FmcdCore, removing duplication
  • Add 'api' feature flag to make web dependencies optional
  • Refactor handlers as thin wrappers around core methods

This enables fmcd to be used as a Rust library while preserving all
existing API functionality. Core business logic is now separate from
HTTP concerns, improving testability and maintainability.

  Reorganize fmcd from monolithic binary into single crate that publishes
  both library and binary, following FMCD_LIBBIN.md design.

  Changes:
  - Move business logic to src/core/ (multimint, operations, services)
  - Move API handlers to src/api/ (REST routes, WebSocket handlers)
  - Create FmcdCore as central business logic interface
  - Add library entry point at src/lib.rs, binary at src/bin/main.rs
  - Simplify AppState to delegate to FmcdCore, removing duplication
  - Add 'api' feature flag to make web dependencies optional
  - Refactor handlers as thin wrappers around core methods

  This enables fmcd to be used as a Rust library while preserving all
  existing API functionality. Core business logic is now separate from
  HTTP concerns, improving testability and maintainability.
Copilot AI review requested due to automatic review settings August 20, 2025 14:45
Copy link

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

Refactors fmcd from a monolithic binary into a dual library/binary crate to enable use as a Rust library while preserving all existing API functionality.

  • Moves business logic to src/core/ module (multimint, operations, services)
  • Creates FmcdCore as the central business logic interface with AppState delegating to it
  • Introduces feature flag system with optional API dependencies

Reviewed Changes

Copilot reviewed 28 out of 55 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/core/mod.rs New core business logic module with FmcdCore struct and Lightning operations
src/lib.rs Updated library entry point with feature-gated API modules
src/state.rs Simplified AppState to delegate to FmcdCore with backward compatibility methods
src/types.rs New common types module for library and API sharing
Cargo.toml Added feature flags making API dependencies optional
tests/integration/api_test.rs Updated to use accessor methods instead of direct field access
src/api/ Various API handlers updated to use new state accessor methods

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

BalanceMonitor, BalanceMonitorConfig, DepositMonitor, DepositMonitorConfig,
PaymentLifecycleConfig, PaymentLifecycleManager,
};
use crate::error::{AppError, ErrorCategory};
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

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

[nitpick] The core module imports from error module which may contain API-specific error types. Consider creating core-specific error types to maintain clean separation between core business logic and API concerns.

Copilot uses AI. Check for mistakes.

#[cfg(feature = "api")]
pub use api::rest as router;
// Only export types when API feature is enabled since they depend on API types
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

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

The types module is only exported when the API feature is enabled, but it contains core types like FmcdResult that should be available to library consumers even without the API feature. Consider splitting types into core and API-specific modules.

Suggested change
// Only export types when API feature is enabled since they depend on API types
pub use core_types::*;
#[cfg(feature = "api")]
pub use api::rest as router;

Copilot uses AI. Check for mistakes.

Ok(())
}
}
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

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

The core module file is very large (859 lines) and contains multiple responsibilities including FmcdCore struct, Lightning operations, and various request/response types. Consider splitting this into separate modules for better maintainability.

Copilot uses AI. Check for mistakes.
event_bus_capacity: usize,
enable_debug_logging: bool,
_event_bus_capacity: usize,
_enable_debug_logging: bool,
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

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

The parameters are prefixed with underscore but not used in the implementation. Consider removing these unused parameters or implementing the custom configuration functionality in FmcdCore.

Copilot uses AI. Check for mistakes.
}

/// Join a federation with an invite code
pub async fn join_federation(&mut self, invite_code: InviteCode) -> Result<FederationId> {
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

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

[nitpick] The join_federation method takes &mut self but other methods take &self. This inconsistency could be confusing for API consumers. Consider if mutable access is necessary or if the method can be made immutable.

Suggested change
pub async fn join_federation(&mut self, invite_code: InviteCode) -> Result<FederationId> {
pub async fn join_federation(&self, invite_code: InviteCode) -> Result<FederationId> {

Copilot uses AI. Check for mistakes.
use crate::events::EventBus;
use crate::observability::correlation::RequestContext;
use crate::webhooks::{WebhookConfig, WebhookNotifier};

Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

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

[nitpick] The core module depends on the webhooks module which may contain API-specific functionality. Consider whether webhooks belong in the core business logic or should be handled at the API layer.

Suggested change

Copilot uses AI. Check for mistakes.
@okjodom okjodom merged commit 708058f into main Aug 20, 2025
6 checks passed
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.

1 participant