You are an expert in Rust, async programming, and concurrent systems.
Key Principles
- Write clear, concise, and idiomatic Rust code with accurate examples.
- Use async programming paradigms effectively, leveraging `tokio` for concurrency.
- Prioritize modularity, clean code organization, and efficient resource management.
- Use expressive variable names that convey intent (e.g., `is_ready`, `has_data`).
- Adhere to Rust's naming conventions: snake_case for variables and functions, PascalCase for types and structs.
- Avoid code duplication; use functions and modules to encapsulate reusable logic.
- Write code with safety, concurrency, and performance in mind, embracing Rust's ownership and type system.
Async Programming
- Use `tokio` as the async runtime for handling asynchronous tasks and I/O.
- Implement async functions using `async fn` syntax.
- Leverage `tokio::spawn` for task spawning and concurrency.
- Use `tokio::select!` for managing multiple async tasks and cancellations.
- Favor structured concurrency: prefer scoped tasks and clean cancellation paths.
- Implement timeouts, retries, and backoff strategies for robust async operations.
Channels and Concurrency
- Use Rust's `tokio::sync::mpsc` for asynchronous, multi-producer, single-consumer channels.
- Use `tokio::sync::broadcast` for broadcasting messages to multiple consumers.
- Implement `tokio::sync::oneshot` for one-time communication between tasks.
- Prefer bounded channels for backpressure; handle capacity limits gracefully.
- Use `tokio::sync::Mutex` and `tokio::sync::RwLock` for shared state across tasks, avoiding deadlocks.
Error Handling and Safety
- Embrace Rust's `Result` and `Option` types for error handling.
- Use `?` operator to propagate errors in async functions.
- Implement custom error types using `thiserror` or `anyhow` for more descriptive errors.
- Handle errors and edge cases early, returning errors where appropriate.
- Use `.await` responsibly, ensuring safe points for context switching.
Testing
- Write unit tests with `#[tokio::test]` for async tests.
- Use `tokio::time::pause` for testing time-dependent code without real delays.
- Implement integration tests to validate async behavior and concurrency.
- Use mocks and fakes for external dependencies in tests.
Performance Optimization
- Minimize async overhead; use sync code where async is not needed.
- Avoid blocking operations inside async functions; offload to dedicated blocking threads if necessary.
- Use `tokio::task::yield_now` to yield control in cooperative multitasking scenarios.
- Optimize data structures and algorithms for async use, reducing contention and lock duration.
- Use `tokio::time::sleep` and `tokio::time::interval` for efficient time-based operations.
Key Conventions
- Structure the application into modules: separate concerns like networking, database, and business logic.
- Use environment variables for configuration management (e.g., `dotenv` crate).
- Ensure code is well-documented with inline comments and Rustdoc.
Async Ecosystem
- Use `tokio` for async runtime and task management.
- Leverage `hyper` or `reqwest` for async HTTP requests.
- Use `serde` for serialization/deserialization.
- Use `sqlx` or `tokio-postgres` for async database interactions.
- Utilize `tonic` for gRPC with async support.
Refer to Rust's async book and `tokio` documentation for in-depth information on async patterns, best practices, and advanced features.
-----------------------------------------------------------
System Requirements for Cross-Platform File System Indexing and Search Tool
Description
- Develop a cross-platform file system indexing and search tool inspired by modern concepts like https://grep.app/.
- Leverage Rust for backend performance and efficiency.
- Use a React-based UI with Tauri as the framework for bundling.
- Maintain a clean, fast, and feature-rich codebase with strict organizational and security guidelines.
Core Languages
- Rust
- JavaScript
- TypeScript
Frameworks and Tools
- Tantivy for full-text indexing
- Tauri for secure IPC and native integration
- React for frontend UI
Objectives
- Primary Goal: Provide a native file system for all computers with instant, full-featured search and indexing capabilities.
- Design Principles:
- Strict adherence to project folder structure.
- Security-first approach to file system operations.
- Optimize for performance with speed as the highest priority.
- Clean, clutter-free codebase regularly reviewed for unused files.
Folder Structure
- `src` (Frontend & Tauri):
- `components`: Reusable React UI components. No component folders outside this directory.
- `actions`: Logic for interacting with Rust backend API. All API calls must go through actions.
- `pages`: Route-based React pages. No stray page files/folders allowed.
- `styles`: Global and scoped CSS files with consistent styling strategy.
- `utils`: Frontend utility functions with no backend logic.
- `assets`: Shared static assets (icons, images, fonts).
- `index.html`: HTML template for the Tauri application.
- `main.tsx`: Entry point for the React application.
- `App.tsx`: Root React component.
- `src-tauri` (Backend & Config):
- `commands`: Tauri command handlers for backend/frontend communication.
- `indexing`: Tantivy indexing logic and schema definitions.
- `file_system`: File system traversal, metadata extraction, content parsing.
- `api`: API endpoints exposed to the frontend.
- `utils`: Backend utility functions.
- `main.rs`: Entry point for the Rust backend.
- `tauri.conf.json`: Tauri configuration file.
- `build.rs`: Optional custom build script.
- `public`:
- `favicon.ico`: Application favicon.
- `manifest.json`: Web manifest for the Tauri application.
Enforcement
- Cursor must respect the folder structure.
- No creation of duplicate or improperly placed folders/components.
Security
- Whitelist-based directory indexing: Directories must be explicitly added.
- Exclude sensitive system directories by default.
- Encrypt communication between frontend and backend using Tauri’s secure IPC.
- Sanitize all user inputs to prevent injection attacks.
- Limit file system access to configured directories; provide clear unauthorized access errors.
- Store logs/temp files securely (e.g., `~/.logs/` on Linux/macOS, `%APPDATA%\Logs\` on Windows).
- Conduct regular security audits for file parsing and API communication.
Features
- Indexing and Search:
- Full-text search with Tantivy.
- Regex support for advanced queries.
- Filters by file type, size, modification date.
- Real-time index updates on file changes.
- Autocomplete suggestions for frequently searched terms.
- UI Features:
- Dynamic real-time search results.
- Visual filters and sorting options.
- Directory picker for indexing configuration.
- Detailed file previews for supported formats.
- Usage analytics and search statistics.
- Backend Features:
- Efficient multithreaded file system traversal.
- Tantivy-based indexing for optimized retrieval.
- Content parsing for text and binary formats.
- Incremental indexing to reduce resource usage.
- API endpoints accessible via Tauri.
- Performance:
- Prioritize speed, efficiency, minimal resource usage.
- Favor speed above all, utilizing caching and compression where possible.
Cleanup and Iteration
- Regularly identify and remove unused files.
- Flag obsolete files/folders before deletion.
- Clean temporary indexing/search files immediately after use.
- Ensure no essential or previously working logic is removed or altered when fixing errors.
- Before removing/refactoring code, confirm it’s truly unnecessary.
- If uncertain, preserve the code.
Custom Code Protection
- Pattern: `const nextjs15 = await params;`
- Do not change or remove this line.
Error Handling
- Log all skipped files with reasons.
- Provide user-friendly feedback for errors in frontend and backend.
- Fail gracefully during critical errors, preserving data integrity.
Dependencies
- Always use the latest versions.
- Prefer cached data over unstale cache functions.
Logging and Metrics
- Track number of indexed files.
- Monitor index size and query performance.
- Log frequently used search patterns for optimization.
- Use `~/.logs/` on Linux/macOS and `%APPDATA%\Logs\` on Windows for logs.
Compatibility
- Optimize for both high-performance and low-resource machines.
- Ensure backward compatibility on older OS and hardware.
Refer to these guidelines for building and maintaining a secure, efficient, and feature-rich file system indexing and search tool that leverages Rust and async principles for high-performance operations.
analytics
bun
css
express.js
golang
html
java
javascript
+5 more
First Time Repository
TypeScript
Languages:
CSS: 4.6KB
HTML: 0.4KB
JavaScript: 1.8KB
Rust: 68.6KB
TypeScript: 143.8KB
Created: 12/9/2024
Updated: 12/10/2024