# Contributing to Fugue
Thank you for your interest in contributing to Fugue! This document provides guidelines for contributing to the project.
## Community
- **Discord**: Join our [Discord server](https://discord.gg/QAcF7Nwr)
- **Issues & Bugs**: Open an [issue](https://github.com/alexnodeland/fugue/issues) with the `Bug Report` template.
- **Feature Requests**: Open an [issue](https://github.com/alexnodeland/fugue/issues) with the `Feature Request` template.
- **RFCs**: Open an [issue](https://github.com/alexnodeland/fugue/issues) with the `RFC` template.
- **Zotero**: Joing our [Zotero group](https://www.zotero.org/groups/6138134/fugue)
## Quick Start
```bash
git clone https://github.com/alexnodeland/fugue.git
cd fugue
cargo test --all-features
```
## Development Setup
### Prerequisites
- Rust 1.70+ (install via [rustup](https://rustup.rs/))
- Git
### Building and Testing
```bash
# Run all tests
make test
# Format code
make fmt
# Lint code
make lint
# Run benchmarks
make bench
# Generate coverage report
make coverage
# Run all checks
make all
```
Or use cargo directly:
```bash
cargo test --all-features
cargo fmt
cargo clippy -- -D warnings
```
## Contributing Guidelines
### Issues
- Use GitHub Issues for bug reports and feature requests
- Provide clear reproduction steps for bugs
- Include relevant code examples
### Pull Requests
- Fork the repository and create a short-lived feature branch from `main` (trunk-based development)
- **Rebase your branch** to the top of `main` before submitting PR
- Use **semantic commit messages** (e.g., `feat:`, `fix:`, `docs:`, `refactor:`)
- Add tests for new functionality
- **Ensure all CI checks pass** before requesting review
- PRs are **squash merged** to maintain linear history
- Update documentation as needed
### Versioning
- We follow [Semantic Versioning](https://semver.org/) (SemVer)
- Breaking changes increment major version
- New features increment minor version
- Bug fixes increment patch version
### Code Style
- Follow Rust standard formatting (`cargo fmt`)
- Address all clippy warnings (`cargo clippy -- -D warnings`)
- Add documentation for public APIs
- Include examples in documentation
## Project Structure
```mermaid
graph LR
A["๐ป Fugue<br/>Monadic Probabilistic Programming"] --> B["๐ฆ Core Module"]
A --> C["๐ฌ Inference Module"]
A --> D["โ๏ธ Runtime Module"]
A --> E["๐๏ธ Macros Module"]
A --> F["โ ๏ธ Error Module"]
B --> B1["๐ Address System<br/>addr!(), scoped_addr!()"]
B --> B2["๐ Distributions<br/>10 type-safe distributions"]
B --> B3["๐งฉ Model<T><br/>Monadic composition"]
B --> B4["๐ข Numerical<br/>Stable algorithms"]
B2 --> B2A["bool: Bernoulli"]
B2 --> B2B["u64: Poisson, Binomial"]
B2 --> B2C["usize: Categorical"]
B2 --> B2D["f64: Normal, Beta, Gamma, etc."]
C --> C1["๐ MCMC<br/>Adaptive Metropolis-Hastings"]
C --> C2["๐ฏ SMC<br/>Particle filtering"]
C --> C3["๐ VI<br/>Mean-field approximation"]
C --> C4["๐ฒ ABC<br/>Likelihood-free inference"]
C --> C5["๐ Diagnostics<br/>R-hat, ESS, validation"]
D --> D1["๐ญ Handler System<br/>Effect interpreters"]
D --> D2["๐ Trace System<br/>Execution history"]
D --> D3["๐พ Memory Optimization<br/>Pooling & COW"]
D1 --> D1A["PriorHandler"]
D1 --> D1B["ReplayHandler"]
D1 --> D1C["ScoreGivenTrace"]
D1 --> D1D["Safe variants"]
E --> E1["prob!<br/>Do-notation"]
E --> E2["plate!<br/>Vectorization"]
F --> F1["FugueError<br/>Rich error context"]
G["๐ Documentation"] --> G1["User Guide<br/>20+ pages"]
G --> G2["API Reference<br/>Complete rustdoc"]
G --> G3["14 Examples<br/>Real-world scenarios"]
H["๐งช Testing"] --> H1["82+ Unit Tests"]
H --> H2["9+ Integration Tests"]
H --> H3["158+ Doctests"]
H --> H4["Property-based Tests"]
I["โก Benchmarks"] --> I1["MCMC Performance<br/>Adaptation & diagnostics"]
I --> I2["Memory Optimization<br/>Pooling & COW traces"]
style A fill:#e1f5fe
style B fill:#f3e5f5
style C fill:#e8f5e8
style D fill:#fff3e0
style E fill:#fce4ec
style F fill:#ffebee
style G fill:#f1f8e9
style H fill:#e3f2fd
style I fill:#fff8e1
```
### Directory Structure
```text
fugue/
โโโ src/
โ โโโ core/ # Core probabilistic programming abstractions
โ โ โโโ address.rs # Hierarchical addressing system
โ โ โโโ distribution.rs # Type-safe distributions (10 built-in)
โ โ โโโ model.rs # Monadic Model<T> abstraction
โ โ โโโ numerical.rs # Numerically stable algorithms
โ โโโ inference/ # Inference algorithms
โ โ โโโ mh.rs # MCMC (Adaptive Metropolis-Hastings)
โ โ โโโ smc.rs # Sequential Monte Carlo
โ โ โโโ vi.rs # Variational Inference
โ โ โโโ abc.rs # Approximate Bayesian Computation
โ โ โโโ diagnostics.rs # R-hat, ESS, validation
โ โโโ runtime/ # Execution engine
โ โ โโโ handler.rs # Effect handler system
โ โ โโโ interpreters.rs # Built-in handlers
โ โ โโโ trace.rs # Execution history recording
โ โ โโโ memory.rs # Memory optimization (pooling, COW)
โ โโโ macros/ # Ergonomic macros
โ โ โโโ mod.rs # prob!, plate!, addr! macros
โ โโโ error.rs # Comprehensive error handling
โโโ examples/ # 14 complete examples
โ โโโ bayesian_coin_flip.rs
โ โโโ linear_regression.rs
โ โโโ mixture_models.rs
โ โโโ hierarchical_models.rs
โ โโโ ...
โโโ benches/ # Performance benchmarks
โ โโโ mcmc_benchmarks.rs # MCMC adaptation & diagnostics
โ โโโ memory_benchmarks.rs # Memory pooling & COW traces
โโโ tests/ # Integration tests
โโโ docs/ # User guide & documentation
โ โโโ src/ # mdBook source
โ โโโ api/ # API documentation
โโโ target/ # Build artifacts
```
## Questions?
Open an issue or start a discussion on GitHub. We're happy to help!