Skip to content

Introduce Core API Layer#78

Merged
mors119 merged 2 commits into
FrilLab:mainfrom
mors119:refactor/use-api-layer
Jun 19, 2026
Merged

Introduce Core API Layer#78
mors119 merged 2 commits into
FrilLab:mainfrom
mors119:refactor/use-api-layer

Conversation

@mors119

@mors119 mors119 commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

What

The CLI must use the Core API to use the Core function.

Why

To use Core in common, Tauri and the CLI made each function accessible using Core's API layer.

Closes #76
Closes #77

Checklist

Required

  • cargo check passes
  • cargo fmt --check passes
  • cargo clippy --workspace --all-targets -- -D warnings passes
  • cargo test passes

Functional Validation

  • I verified the behavior locally
  • I added or updated tests when necessary

Documentation

  • README or docs were updated if needed
  • New configuration or behavior is documented

Safety

  • Cleanup behavior was reviewed for safety
  • No destructive behavior was introduced without confirmation

Summary by CodeRabbit

  • Refactor
    • Reorganized core library architecture with new unified API module for scan, analysis, and cleanup operations.
    • Consolidated internal module visibility, making implementation details private while exposing a cleaner public interface.
    • Extracted formatting utilities into dedicated module.
    • Updated PR template for improved documentation standards.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a public api module (scan, analyze, clean facades) and a format module (format_size, format_modified) to dustfril-core. Makes analyzer, cleaner, and detector internal. Migrates all three CLI commands (scan, analyze, clean) to call through the new api and format entrypoints instead of the internal modules directly.

Changes

Core API Layer and CLI Migration

Layer / File(s) Summary
Core crate public module surface and format utilities
crates/dustfril-core/src/lib.rs, crates/dustfril-core/src/format/mod.rs, crates/dustfril-core/src/format/date.rs, crates/dustfril-core/src/format/size.rs
lib.rs adds pub mod api and pub mod format, demotes analyzer/cleaner/detector to private. format module declares date and size submodules; format_modified is moved to date.rs and removed from size.rs.
New api facades: scan, analyze, clean
crates/dustfril-core/src/api/mod.rs, crates/dustfril-core/src/api/scan.rs, crates/dustfril-core/src/api/analyze.rs, crates/dustfril-core/src/api/clean.rs
api/scan.rs dispatches to detector::scan_global or detector::scan_workspace based on a global flag. api/analyze.rs wraps analyzer::analyze. api/clean.rs adds build_plan (analyze + create_cleanup_plan) and execute (execute_cleanup). api/mod.rs re-exports all.
Detector and analyzer internal cleanup
crates/dustfril-core/src/detector/mod.rs, crates/dustfril-core/src/detector/scan.rs, crates/dustfril-core/src/analyzer/mod.rs, crates/dustfril-core/src/analyzer/tests.rs
detector/mod.rs switches to wildcard re-export; old combined scan(root) function is commented out. Analyzer removes format_modified/format_size re-exports. Tests updated to call crate::format::size::format_size.
CLI commands migrated to api and format
apps/dustfril-cli/src/commands/scan.rs, apps/dustfril-cli/src/commands/analyze.rs, apps/dustfril-cli/src/commands/clean.rs
All three commands replace dustfril_core::{detector, analyzer, cleaner} imports with {api, format}. Scan/analyze/clean execution flows now call api::scan, api::analyze, api::clean::build_plan, and api::clean::execute; all size and date formatting uses format::*.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as CLI Command
  participant api as dustfril_core::api
  participant detector as detector (internal)
  participant analyzer as analyzer (internal)
  participant cleaner as cleaner (internal)

  rect rgba(70, 130, 180, 0.5)
    note over CLI,detector: scan command
    CLI->>api: scan(root, global)
    api->>detector: scan_global() or scan_workspace(root)
    detector-->>api: ScanResult
    api-->>CLI: ScanResult
  end

  rect rgba(60, 179, 113, 0.5)
    note over CLI,analyzer: analyze command
    CLI->>api: scan(root, global)
    api->>detector: scan_global() or scan_workspace(root)
    detector-->>api: ScanResult
    CLI->>api: analyze(ScanResult)
    api->>analyzer: analyze(ScanResult)
    analyzer-->>api: AnalysisResult
    api-->>CLI: AnalysisResult
  end

  rect rgba(210, 105, 30, 0.5)
    note over CLI,cleaner: clean command
    CLI->>api: scan(root, global)
    api->>detector: scan_global() or scan_workspace(root)
    CLI->>api: clean::build_plan(ScanResult)
    api->>analyzer: analyze(ScanResult)
    api->>cleaner: create_cleanup_plan(AnalysisResult)
    cleaner-->>api: CleanupPlan
    CLI->>api: clean::execute(CleanupPlan)
    api->>cleaner: execute_cleanup(CleanupPlan)
    cleaner-->>api: CleanupResult
    api-->>CLI: CleanupResult
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • FrilLab/dustfril#34: Initial artifact discovery implementation that established the detector::scan-based CLI flow now being replaced by api::scan.
  • FrilLab/dustfril#39: Added the scan→analyze→report logic and formatting helpers in analyze.rs that this PR now reroutes through dustfril_core::api and dustfril_core::format.
  • FrilLab/dustfril#45: Added cleaner::execute_cleanup/create_cleanup_plan and the cleanup models that api::clean now wraps.

Poem

🐇 Hop hop, the modules align,
api and format now shine!
Detector and cleaner go private inside,
While facades give the CLI a smoother ride.
The rabbit refactored with glee —
One tidy crate for all to see! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Introduce Core API Layer' clearly and concisely describes the main objective of the changeset, which is establishing a new Core API layer for unified access to core functionality.
Linked Issues check ✅ Passed The PR fully addresses both linked issues: it establishes the Core API layer infrastructure (#76) with api/analyze, api/clean, and api/scan modules, and refactors CLI commands to use api::scan, api::analyze, and api::clean::execute instead of direct detector/analyzer/cleaner calls (#77).
Out of Scope Changes check ✅ Passed All changes are directly scoped to the Core API layer introduction and CLI refactoring. Updates to the pull request template and test file modifications support the primary objectives with no unrelated changes detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
crates/dustfril-core/src/detector/scan.rs (1)

55-61: ⚡ Quick win

Remove the commented-out scan implementation.

Keeping retired API code as comments makes the active contract less clear and increases maintenance noise. Please delete this block instead of preserving it inline.

Proposed cleanup
-// pub fn scan(root: &Path) -> ScanResult {
-//     let mut result = scan_workspace(root);
-//
-//     result.artifacts.extend(scan_global().artifacts);
-//
-//     result
-// }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/dustfril-core/src/detector/scan.rs` around lines 55 - 61, The
commented-out `scan` function implementation should be completely removed from
the file rather than kept as inline comments. Delete the entire commented block
that includes the function signature for `scan` accepting a root Path parameter
and returning ScanResult, along with its implementation body. This cleanup will
improve code clarity and reduce maintenance noise by removing retired API code
from the active codebase.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@crates/dustfril-core/src/detector/scan.rs`:
- Around line 55-61: The commented-out `scan` function implementation should be
completely removed from the file rather than kept as inline comments. Delete the
entire commented block that includes the function signature for `scan` accepting
a root Path parameter and returning ScanResult, along with its implementation
body. This cleanup will improve code clarity and reduce maintenance noise by
removing retired API code from the active codebase.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 549148c2-7bcd-4d69-b832-073a1107984f

📥 Commits

Reviewing files that changed from the base of the PR and between 9bab3de and c149e26.

📒 Files selected for processing (16)
  • .github/PULL_REQUEST_TEMPLATE.md
  • apps/dustfril-cli/src/commands/analyze.rs
  • apps/dustfril-cli/src/commands/clean.rs
  • apps/dustfril-cli/src/commands/scan.rs
  • crates/dustfril-core/src/analyzer/mod.rs
  • crates/dustfril-core/src/analyzer/tests.rs
  • crates/dustfril-core/src/api/analyze.rs
  • crates/dustfril-core/src/api/clean.rs
  • crates/dustfril-core/src/api/mod.rs
  • crates/dustfril-core/src/api/scan.rs
  • crates/dustfril-core/src/detector/mod.rs
  • crates/dustfril-core/src/detector/scan.rs
  • crates/dustfril-core/src/format/date.rs
  • crates/dustfril-core/src/format/mod.rs
  • crates/dustfril-core/src/format/size.rs
  • crates/dustfril-core/src/lib.rs
💤 Files with no reviewable changes (2)
  • crates/dustfril-core/src/analyzer/mod.rs
  • crates/dustfril-core/src/format/size.rs

@mors119 mors119 merged commit f5274b3 into FrilLab:main Jun 19, 2026
2 checks passed
@mors119 mors119 deleted the refactor/use-api-layer branch June 19, 2026 07:00
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.

[TASK] Remove direct detector/analyzer/cleaner usage from CLI [TASK] Introduce Core API Layer (Tauri-ready)

1 participant