Development Guide
This guide covers development practices, contribution guidelines, and technical details for contributing to Shortas.
We welcome contributions from the community! This guide will help you get started with development.
Prerequisites
- Rust 1.75+ (stable channel)
- Docker & Docker Compose
- Make
- Git
Development Setup
# Clone the repository
git clone https://github.com/FlyingCow/shortas.git
cd shortas
# Complete development setup (installs dependencies, starts infrastructure, builds services, runs tests)
make dev-setup
# Start all services
make dev-start
ποΈ Project Structure
The Shortas project is a monorepo containing several Rust microservices and supporting infrastructure.
.
βββ docs/ # Project documentation (Jekyll)
βββ redirect/ # Core URL redirection services
β βββ click-router/ # Main redirect service
β βββ click-tracker/ # Click processing service
β βββ click-aggregator/ # Analytics aggregation
β βββ click-router-api/ # Route management API
β βββ click-aggregator-api/ # Analytics API
βββ salvo/ # Salvo web framework (dependency/fork)
βββ infra/ # Infrastructure setup (Docker, Terraform, AWS)
βββ data/ # Static data (GeoIP, UA parser)
βββ docker-compose.yml # Complete system deployment for local dev
βββ makefile # Enhanced build and development system
Service-Specific Structures
Each Rust service (click-router
, click-tracker
, etc.) generally follows a similar internal structure:
<service-name>/
βββ Cargo.toml # Rust package manifest
βββ src/ # Source code
β βββ adapters/ # Service integrations (DB, Cache, MQ)
β βββ core/ # Core business logic
β βββ model/ # Data models (structs, enums)
β βββ settings.rs # Configuration loading
β βββ main.rs # Application entry point
βββ config/ # Configuration files (default.toml, development.toml, etc.)
βββ Dockerfile # Docker build instructions
βββ makefile # Service-specific make commands
π οΈ Building the Project
Shortas uses cargo
for Rust builds and make
for an integrated build system.
Building All Services
From the project root:
# Development build (debug mode)
make build
# Release build (optimized for performance)
make build-release
# Build all Docker images
make build-docker
Building a Specific Service
You can build individual services:
make build-click-router
make build-click-router-api
# etc.
π§ͺ Testing
Comprehensive testing is crucial for Shortas.
Running All Tests
From the project root:
make test
Running Tests for a Specific Service
make test-click-router
make test-click-tracker
# etc.
Test Coverage
Generate test coverage reports:
make test-coverage
This typically uses cargo tarpaulin
and generates an HTML report.
π Code Quality
Maintain high code quality with formatting and linting.
Formatting
make format # Formats all Rust code using rustfmt
Linting
make lint # Runs clippy for linting
Security Audit
Check for known vulnerabilities in dependencies:
cargo audit
π€ Contributing Guidelines
We welcome contributions! Please follow these guidelines to ensure a smooth collaboration.
1. Fork the Repository
Fork the Shortas GitHub repository to your own GitHub account.
2. Clone Your Fork
git clone https://github.com/YOUR_USERNAME/shortas.git
cd shortas
3. Create a Feature Branch
Always work on a new branch for your features or bug fixes:
git checkout -b feature/your-feature-name
# or
git checkout -b bugfix/issue-description
4. Make Your Changes
- Implement your feature or fix the bug.
- Ensure your code adheres to the existing code style.
- Add or update tests to cover your changes.
- Update documentation (code comments, READMEs,
docs/
files) as necessary.
5. Run Tests and Checks
Before committing, ensure all tests pass and code quality checks are clean:
make check # Runs lint, test, and build
6. Commit Your Changes
Write clear and concise commit messages.
git commit -m "feat: Add a new amazing feature"
# or
git commit -m "fix: Resolve issue with X"
7. Push to Your Fork
git push origin feature/your-feature-name
8. Open a Pull Request
- Go to the original Shortas repository on GitHub.
- You should see a prompt to open a new Pull Request from your branch.
- Provide a detailed description of your changes, why they are needed, and any relevant issue numbers.
- Ensure your PR passes all CI checks.
π Debugging
Local Debugging
- Enable Debug Logging: Set the
RUST_LOG
environment variable.RUST_LOG=debug make dev-start # Or for a specific module: RUST_LOG=click_router::core::flow_router=debug make dev-start
- IDE Integration: Use Rustβs debugging tools with your IDE (e.g., VS Code with
rust-analyzer
).
Docker Debugging
- Access Container Shell:
docker exec -it <container-id-or-name> /bin/bash
- View Container Logs:
docker logs <container-id-or-name> # Or using make: make logs-router
Thank you for contributing to Shortas! Your efforts help make this project better.