# Contributing to OpenCrates
We're excited you want to contribute! This guide will help you get your development environment set up and walk you through the contribution workflow.
## Quick Start: Local Development
### Prerequisites
- [Rust](https://www.rust-lang.org/tools/install) (latest stable)
- [Node.js](https://nodejs.org/) (v20 or later) for documentation tooling
- [Docker](https://www.docker.com/products/docker-desktop/) (for PostgreSQL)
### 1. Set up the Backend
First, install `cargo-watch` for live-reloading:
```bash
cargo install cargo-watch
```
To run the backend services (like the API server), you'll need a running PostgreSQL instance. Use Docker to launch one:
```bash
docker run --name opencrates-db -e POSTGRES_PASSWORD=pg -p 5432:5432 -d postgres:16
```
Set the `DATABASE_URL` environment variable:
```bash
export DATABASE_URL=postgres://postgres:pg@localhost:5432/postgres
```
Now, run the server with hot-reloading:
```bash
cargo watch -x 'run --bin opencrates-server --features full'
```
The server will restart automatically whenever you save a file.
### 2. Run Tests
To run the full test suite:
```bash
cargo test --all-features --all-targets
```
### 3. Work with Documentation
The documentation site is built with `mdBook`. To preview it locally:
1. **Install tools**:
```bash
cargo install mdbook mdbook-mermaid mdbook-widdershins --locked
npm install -g widdershins
```
2. **Generate content and serve**:
```bash
./scripts/gen_openapi_md.sh && mdbook serve docs -n 127.0.0.1 -p 3003 --open
```
This will generate the API reference, open the handbook in your browser, and auto-reload on changes.
## Contribution Workflow
1. **Fork the repository** and create a new branch from `main`.
2. **Make your changes**. Ensure your code adheres to the project's style and conventions.
3. **Run `cargo clippy`** to check for lints.
4. **Run `cargo test`** to ensure all tests pass.
5. **Submit a pull request** with a clear description of your changes.
The CI pipeline will automatically run all checks. All checks must pass for the PR to be merged.