Local Development Setup¶
This guide walks you through setting up a local development environment for R Commerce.
Prerequisites¶
- Rust 1.70+ (install from rustup.rs)
- PostgreSQL 13+
- Redis 6+ (optional, for caching)
- Git
Quick Start¶
1. Clone the Repository¶
2. Set Up Database¶
Option A: PostgreSQL (Recommended)¶
# macOS
brew install postgresql@15
brew services start postgresql@15
# Create database
psql -U postgres -c "CREATE DATABASE rcommerce_dev;"
psql -U postgres -c "CREATE USER rcommerce_dev WITH PASSWORD 'devpass';"
psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE rcommerce_dev TO rcommerce_dev;"
3. Configure Environment¶
# Copy example configuration
cp config.example.toml config.development.toml
# Edit the configuration file
# Update database connection settings as needed
4. Build and Run¶
# Build the project
cargo build --release
# Run database migrations
cargo run --bin rcommerce -- db migrate
# Start the server
cargo run --bin rcommerce -- server
The API will be available at http://localhost:8080.
5. Verify Installation¶
Development Configuration¶
Database Configuration¶
PostgreSQL:
[database]
db_type = "Postgres"
host = "localhost"
port = 5432
database = "rcommerce_dev"
username = "rcommerce_dev"
password = "devpass"
Optional: Redis Caching¶
# Install Redis
brew install redis # macOS
brew services start redis
# Enable in config.toml
[cache]
cache_type = "Redis"
redis_url = "redis://localhost:6379"
Running Tests¶
# Run all tests
cargo test --workspace
# Run tests for specific crate
cargo test -p rcommerce-core
# Run with output visible
cargo test -- --nocapture
Development Tools¶
Hot Reload¶
# Install cargo-watch
cargo install cargo-watch
# Watch for changes and rebuild
cargo watch -x 'run --bin rcommerce -- server'
Code Quality¶
IDE Setup¶
VS Code¶
Recommended extensions: - rust-analyzer - Rust language support - Even Better TOML - TOML file support - CodeLLDB - Debugging support
IntelliJ / RustRover¶
- Install the Rust plugin
- Import the project as a Cargo project
- Set up run configurations for
cargo runandcargo test
Troubleshooting¶
Build Failures¶
Error: ld: library not found for -lpq
Error: sqlx compile-time checks failing
Database Connection Issues¶
PostgreSQL connection refused
# Check PostgreSQL is running
brew services list | grep postgresql
# Restart PostgreSQL
brew services restart postgresql@15
Port Already in Use¶
# Find process using port 8080
lsof -i :8080
# Kill the process or change port in config.toml
[server]
port = 8081
Next Steps¶
- CLI Reference - Learn the CLI commands
- Testing Guide - Write and run tests
- Contributing Guide - Contribute to the project