> For the complete documentation index, see [llms.txt](https://dzhelezov.gitbook.io/hydra/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dzhelezov.gitbook.io/hydra/master/packages/hydra-cli/src/templates/scaffold.md).

# Sample Hydra Project

This is a sample project generated by `hydra-cli scaffold`. Experiment by modifying `schema.graphql` and the mappings in the `mappings` folder.

## Prerequisites

* Node v14x
* Docker

## Bootstrap

```bash
npm install

# make sure dependencies are deduped, this is important
npm dedupe

# generate TypeScript definitions for substrate types
npm run typegen

# Analyze schema.graphql and generate model/server files
npm run codegen

# Start postgres instance
docker-compose up -d

# Apply migrations related to processor's state keeping tables
npm run processor:migrate

# Analyze database state and create migration to match generated models
npm run db:create-migration

# Apply pending migrations
npm run db:migrate

# Now you can start processing chain data
npm run processor:start

# The above command will block
# Open separate terminal and launch graphql server to query the processed data
npm run query-node:start
```

## Project structure

Hydra tools expect a certain directory layout explained here.

* `generated` - model/server definitions generated by `codegen`. Do not alter the contents of this directory.
* `server-extension` - a place for custom data models and resolvers defined via `.model.ts`, `.resolver.ts` files.
* `chain` - data type definitions for chain events and extrinsics generated by `typegen`,

  overridable via `manifest.yml`.
* `mappings` - mapping definitions, overridable via `manifest.yml`.
* `.env` - hydra tools are heavily driven by environment variables defined here.

## Self-hosted indexer

It is recommeded to use already set up indexer if available, as new indexer typically requires some time to catch up with interesting events.

Have a look at `./indexer/docker-compose.yml` for example of how you can set up a self-hosted version.
