# Best Practices

Some best practices we encourage on all integrations are:

* **Clear Documentation:**\
  Write clear, thorough comments. Good documentation:
  * Helps reviewers understand your logic and provide better feedback
  * Serves as a guide for future developers who may adapt your solutions
  * Explains *why* you made certain decisions, not just what they do
* **Module Organisation:**\
  For complex implementations it is recommended to:

  * Break large `module.rs` files into smaller, focused files
  * Place these files in a `modules` directory
  * Name files clearly with numerical prefixes indicating execution order (e.g., `01_parse_events.rs`, `02_process_data.rs`)
  * Use the same number for parallel modules that depend on the same previous module

  A good example of this done well is in the [uniswap-v4 implementation](https://github.com/propeller-heads/tycho-indexer/tree/main/protocols/substreams/ethereum-uniswap-v4/src/modules).
* **Substream Initial Block:**\
  Your package will work just fine setting the initial block in your manifest file to `1`, however it means anyone indexing your protocol has to wait for it to process an excessive number of unnecessary blocks before it reaches the first relevant block. This increases substream costs and causes long wait times for the protocol to reach the current block.

  A good rule of thumb is to identify the earliest deployed contract that you index and set this config to that block.
* **Performance Considerations:**
  * Minimize use of `.clone()`, especially in loops or on complex/nested data structures. Instead use references (`&`) when possible.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.propellerheads.xyz/tycho/for-dexs/protocol-integration/indexing/best-practices.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
