2025-03-17 21:28:08 +01:00
# OxiCloud Development Guide
## Build Commands
```bash
2025-03-19 00:44:27 +01:00
# Core development workflow
2025-03-17 21:28:08 +01:00
cargo build # Build the project
cargo run # Run the project locally (server at http://127.0.0.1:8085)
2025-03-19 00:44:27 +01:00
cargo check # Quick check for compilation errors without building
# Testing commands
2025-03-17 21:28:08 +01:00
cargo test # Run all tests
cargo test -- --nocapture # Run tests with output displayed
cargo test <test_name> # Run a specific test (e.g., cargo test file_service)
2025-03-19 00:44:27 +01:00
cargo test domain::entities::file::tests::test_create_file # Run a specific test function
RUST_LOG = debug cargo test # Run tests with debug-level logging
RUST_LOG = trace cargo test # Run tests with trace-level logging
# Code quality tools
2025-03-17 21:28:08 +01:00
cargo clippy # Run linter to catch common mistakes
cargo clippy --fix # Fix auto-fixable linting issues
cargo fmt --check # Check code formatting without changing files
cargo fmt # Format code according to Rust conventions
2025-03-19 00:44:27 +01:00
# Debugging
2025-03-17 21:28:08 +01:00
RUST_LOG = debug cargo run # Run with detailed logging for debugging
2025-03-19 00:44:27 +01:00
RUST_BACKTRACE = 1 cargo run # Run with full backtrace for better error diagnostics
2025-03-17 21:28:08 +01:00
```
## Code Style Guidelines
2025-03-19 00:44:27 +01:00
- **Architecture**: Follow Clean Architecture with clear layer separation (domain → application → infrastructure → interfaces)
2025-03-20 09:22:31 +01:00
- **Naming**: Use `snake_case` for files, modules, functions, variables; `PascalCase` for types/structs/enums; getters without `get_` prefix
2025-03-17 21:28:08 +01:00
- **Modules**: Use mod.rs files for explicit exports with visibility modifiers (pub, pub(crate))
2025-03-20 09:22:31 +01:00
- **Error Handling**: Use Result<T, E> with thiserror for custom error types; propagate errors with ? operator; include context in error messages
- **Documentation**: Document public APIs with /// doc comments, explain "why" not "what"; both English and Spanish comments are acceptable
2025-03-17 21:28:08 +01:00
- **Imports**: Group imports: 1) std, 2) external crates, 3) internal modules (with blank lines between)
2025-03-20 09:22:31 +01:00
- **Async**: Use async-trait for repository interfaces; handle futures with .await and tokio runtime; implement timeouts for I/O operations
- **Testing**: Write unit tests in the same file as implementation (bottom of file, in a tests module with #[cfg(test)])
- **Dependencies**: Use axum for web API, tower-http for middleware, serde for serialization; share dependencies with Arc
- **Logging**: Use tracing with appropriate levels (debug, info, warn, error) and structured contexts for detailed diagnostics
- **Repository Pattern**: Define interfaces in domain layer, implement in infrastructure layer; use traits with dynamic dispatch (Box<dyn Trait>)
2025-03-17 21:28:08 +01:00
- **I18n**: Store translations in JSON files under static/locales/, use i18n service for text lookups
2025-03-20 09:22:31 +01:00
- **Type Safety**: Prefer strong typing with domain-specific types over primitive types; validate at construction time
2025-03-19 00:44:27 +01:00
- **Error Messages**: Provide clear, actionable error messages that help diagnose the issue
2025-03-20 09:22:31 +01:00
- **Immutability**: Prefer immutable data structures; use with_* methods to return modified copies rather than mutating in place
- **Performance**: Implement caching with proper invalidation; use parallel processing for large file operations; optimize based on file sizes
2025-03-17 21:28:08 +01:00
## Project Structure
2025-03-19 00:44:27 +01:00
OxiCloud is a NextCloud-like file storage system built in Rust with a focus on performance and security. It provides a clean REST API and web interface for file management using a layered architecture approach:
- **Domain Layer**: Core business logic and entities (src/domain/)
- **Application Layer**: Use cases and application services (src/application/)
- **Infrastructure Layer**: External systems and implementations (src/infrastructure/)
- **Interfaces Layer**: API and web controllers (src/interfaces/)
The roadmap in TODO-LIST.md outlines planned features including enhanced folder support, file previews, user authentication, sharing, and a sync client.