Skip to content

Commit 89ed0ef

Browse files
sameh-faroukclaude
andcommitted
docs: update all project documentation
- README.md: Node v16→v20, src/types described as auto-generated, added Makefile targets and docs/typeChanges.md to project layout, restored architecture diagram - docs/readme.md: added links to typeChanges.md and release_process.md - docs/development.md: added sections for type generation workflow, GraphQL schema modification, and DB reset; restored log screenshots - docs/production.md: documented all env vars for indexer and processor, added architecture overview, improved resync section - docs/release_process.md: documented make version-bump, fixed chart paths (indexer/chart.yaml→indexer/chart/Chart.yaml), added CI auto-publish note - indexer/readme.md: documented START_HEIGHT, reformatted container list as table - indexer/development.md: fixed title (types.json→typesBundle.json), clarified typesBundle is frozen with link to typeChanges.md - indexer/chart/README.md: fixed typo (missing space in helm command) - processor-chart/README.md: fixed wrong path (cd tfchain/graphql/processor-chart→cd processor-chart) - scripts/readme.md: fixed typo (Sripts→Scripts), fixed wrong script name (restart-db.sh→reset-db.sh), added missing scripts (seed-versions.sh, merge-versions.js, init-db.sh) Refs: #119, #120 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 87bda91 commit 89ed0ef

10 files changed

Lines changed: 232 additions & 103 deletions

File tree

README.md

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,45 @@
1-
# Tfchain graphql
1+
# TFChain GraphQL
22

3-
[Subsquid](https://docs.subsquid.io) is used to index and provide a graphql interface on top of tfchain.
3+
[Subsquid](https://docs.subsquid.io) is used to index and provide a GraphQL interface on top of TFChain.
44

55
## Concept
66

77
The substrate events are processed in a multi-step pipeline:
88

9-
Tfchain => Squid Indexer => Indexer GraphQL gateway => Squid Processor => Database => Query Node GraphQL endpoint
9+
TFChain => Squid Indexer => Indexer GraphQL gateway => Squid Processor => Database => Query Node GraphQL endpoint
1010

1111
![Bird eye overview](https://gblobscdn.gitbook.com/assets%2F-MdI-MAyz-csivC8mmdb%2Fsync%2Fe587479ff22ad79886861487b2734b6556302d10.png?alt=media)
1212

1313
## Prerequisites
1414

15-
* Node v16x
15+
* Node v20+
1616
* Docker
17-
* Docker-compose
17+
* Docker Compose
1818

1919
## Running
2020

21-
see [docs](./docs/readme.md)
21+
See [docs](./docs/readme.md)
2222

2323
## Project layout
2424

25-
- `indexer` - docker-compose setup for the indexer
26-
- `db` - Processor db migration files
27-
- `scripts` - Scripts for generating initial state and development scripts
28-
- `src` - Source
29-
- `mappings` - Mapper functions for the indexer data
30-
- `model` - Generated models from the `schema.graphql` file
31-
- `types` - Type files that require manual edit if the schema changes / or chain types change
32-
- `processor.ts` - Processor entrypoint
33-
- `typegen` - Where the declaration files are generated from (used for development)
34-
- `tfchainVersions.jsonl` - Generated tfchain runtime versions and their data
35-
- `typegen.json` - Typegen config
36-
- `typesBundle.json` - Typegen bundle config
37-
- `schema.graphql` - The graphql schema file, changes to this file will results in changes to the models (`src/models`)
25+
- `indexer/` - Docker Compose setup for the indexer (archive)
26+
- `db/` - Processor database migration files
27+
- `scripts/` - Utility scripts (see [scripts/readme.md](./scripts/readme.md))
28+
- `src/` - Processor source code
29+
- `mappings/` - Event handler functions that map chain events to database entities
30+
- `model/` - Generated TypeORM models from `schema.graphql`
31+
- `types/` - Auto-generated type definitions (do not edit manually — run `make typegen`)
32+
- `processor.ts` - Processor entrypoint: event subscription and dispatch
33+
- `typegen/` - Type generation infrastructure
34+
- `tfchainVersions.jsonl` - Append-only log of runtime metadata from all TFChain networks
35+
- `typegen.json` - Typegen config: which events to generate types for
36+
- `typesBundle.json` - Frozen pre-V14 type mappings (do not edit for new runtime versions)
37+
- `docs/` - Documentation
38+
- [typeChanges.md](./docs/typeChanges.md) - How to handle type changes on chain (adding new runtime versions, resync guidance)
39+
- [development.md](./docs/development.md) - Local development setup
40+
- [production.md](./docs/production.md) - Production deployment
41+
- [release_process.md](./docs/release_process.md) - Release workflow
42+
- `schema.graphql` - GraphQL schema — changes here regenerate `src/model/` via `yarn codegen`
43+
- `Makefile` - Common tasks: `typegen`, `typegen-add`, `typegen-seed`, `version-bump`
44+
- `processor-chart/` - Helm chart for processor + query node deployment
45+
- `indexer/chart/` - Helm chart for indexer stack deployment

docs/development.md

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Developing on tfchain graphql
1+
# Developing on TFChain GraphQL
22

3-
Install:
3+
## Install
44

55
```
66
yarn
@@ -9,66 +9,102 @@ yarn build
99

1010
## Local Network
1111

12-
### Run tfchain
12+
### Run TFChain
1313

14-
see https://github.com/threefoldtech/tfchain
14+
See https://github.com/threefoldtech/tfchain
1515

1616
### Run Indexer
1717

18-
Check `indexer/.env` and adjust the websocket endpoint to your local tfchain address.
18+
Check `indexer/.env` and adjust the websocket endpoint to your local TFChain address.
1919

2020
```
2121
cd indexer
2222
docker-compose up -d
2323
```
2424

25-
Indexer services should now be started, you can check if it's syncing properly by streaming the logs for the indexer:
25+
Indexer services should now be started. Check if it's syncing properly by streaming the ingest logs:
2626

2727
```
2828
docker logs indexer-ingest-1 -f
2929
```
3030

31-
You should be able to follow tfchain blocks processing:
31+
You should see TFChain blocks being processed:
3232

33-
![image](https://user-images.githubusercontent.com/73958772/209998096-3d5381d9-97ee-438d-824d-d92d997b42aa.png)
33+
![Indexer logs](https://user-images.githubusercontent.com/73958772/209998096-3d5381d9-97ee-438d-824d-d92d997b42aa.png)
3434

35-
### Run processor
35+
### Run Processor
3636

37-
Check `.env` and adjust the websocket endpoint to your local tfchain address.
37+
Check `.env` and adjust the websocket endpoint to your local TFChain address.
3838

3939
```
4040
yarn build
4141
yarn db:up
4242
yarn process
4343
```
4444

45-
You should be able to follow tfchain blocks processing:
45+
You should see TFChain blocks being processed by the processor:
4646

47-
![image](https://user-images.githubusercontent.com/73958772/210000023-c575d91a-382e-4fdc-85b3-199a135b493f.png)
47+
![Processor logs](https://user-images.githubusercontent.com/73958772/210000023-c575d91a-382e-4fdc-85b3-199a135b493f.png)
4848

49-
50-
If you make some changes, don't forget to turn down container before tuning it on again.
49+
If you make changes, stop the containers before restarting:
5150

5251
```
5352
docker-compose down
5453
```
5554

56-
### Run graphql UI
55+
### Run GraphQL UI
56+
57+
At this step, running `docker ps` should show the indexer + processor containers running:
5758

58-
At this step, by running
59+
![Docker containers](https://user-images.githubusercontent.com/42457449/258668686-cd331bd6-ed80-47ea-87a5-16f88d969025.png)
60+
61+
Make sure indexer and processor are both connected to TFChain.
5962

6063
```
61-
docker ps
64+
yarn api
6265
```
6366

64-
it should display such list of running containers:
67+
Now you can use the GraphQL playground at http://localhost:4000/graphql
6568

66-
![image](https://user-images.githubusercontent.com/42457449/258668686-cd331bd6-ed80-47ea-87a5-16f88d969025.png)
69+
## Adding New Runtime Versions
6770

68-
Make sure indexer and processor are both listening to tfchain to be able to browse.
71+
When TFChain has a new spec version with type changes, see [typeChanges.md](./typeChanges.md) for the full workflow. The short version:
6972

73+
```bash
74+
# Point at your local chain (or a remote network via WS_URL=wss://...)
75+
make typegen-add
76+
77+
# Check what changed in src/types/, add handler branches if needed
78+
yarn build
7079
```
71-
yarn api
80+
81+
## Modifying the GraphQL Schema
82+
83+
If you need to add new entities or fields to the GraphQL API:
84+
85+
1. Edit `schema.graphql`
86+
2. Regenerate models and create a migration:
87+
```
88+
yarn codegen
89+
yarn build
90+
yarn db:create-migration
91+
```
92+
3. Add or update event handlers in `src/mappings/`
93+
4. Register new events in `src/processor.ts` if needed
94+
5. Test locally:
95+
```
96+
yarn db:up
97+
yarn db:migrate
98+
yarn process
99+
```
100+
101+
## Resetting the Processor Database
102+
103+
To reindex from scratch (e.g., after a mapping bug fix):
104+
105+
```bash
106+
./scripts/reset-db.sh
107+
yarn process
72108
```
73109

74-
Now you can use the UI (http://localhost:4000/graphql) and run some tests.
110+
This drops and recreates the processor database and reindexes from block 0.

docs/production.md

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,66 @@
1-
# Production setup
1+
# Production Setup
22

33
## Requirements
44

5-
- Tfchain network url. (e.g. `wss://tfchain.dev.grid.tf/ws`)
5+
- TFChain network WebSocket URL (e.g., `wss://tfchain.dev.grid.tf/ws`)
66
- Docker
7-
- Docker-compose
7+
- Docker Compose
88

9-
## Run the setup
9+
## Architecture
1010

11-
### Indexer
11+
The production stack has two independent layers:
1212

13-
Configure the `.env` file in `./indexer`
13+
1. **Indexer (archive)** — ingests raw blocks from a TFChain node into CockroachDB. Provides a GraphQL gateway for the processor to query block data.
14+
2. **Processor + Query Node** — reads events from the indexer, maps them to domain entities (nodes, farms, contracts, etc.), stores in PostgreSQL, and serves the public GraphQL API.
1415

15-
Set the `WS_URL` to a tfchain network url.
16+
## Run the Setup
17+
18+
### 1. Indexer
19+
20+
Configure `indexer/.env`:
21+
22+
| Variable | Description | Default |
23+
|----------|-------------|---------|
24+
| `WS_ENDPOINT` | TFChain node WebSocket URL | `ws://localhost:9944` |
25+
| `START_HEIGHT` | Block height to start ingesting from. `0` = genesis (full history). Set higher only for testing or partial deployments — the processor will miss events before this height. | `0` |
1626

1727
```bash
1828
cd indexer
1929
docker-compose up -d
2030
```
2131

22-
### Processor
32+
See [indexer/readme.md](../indexer/readme.md) for details on the indexer stack containers.
33+
34+
### 2. Processor + Query Node
2335

24-
Configure the `.env` file in the root of this repository.
36+
Configure `.env` in the project root:
2537

26-
Set the `WS_URL` to a tfchain network url.
38+
| Variable | Description | Default |
39+
|----------|-------------|---------|
40+
| `DB_NAME` | PostgreSQL database name | `tfgrid-graphql` |
41+
| `DB_USER` | PostgreSQL user | `postgres` |
42+
| `DB_PASS` | PostgreSQL password | `postgres` |
43+
| `DB_PORT` | PostgreSQL port | `5432` |
44+
| `INDEXER_ENDPOINT_URL` | Indexer GraphQL gateway URL | `http://localhost:8888/graphql` |
45+
| `WS_URL` | TFChain node WebSocket URL (used for RPC calls) | `ws://localhost:9944` |
46+
| `TYPEORM_LOGGING` | TypeORM log level | `error` |
2747

2848
```bash
2949
docker-compose up -d
3050
```
3151

32-
Now the graphql endpoint is available at `http://localhost:4000/graphql`
52+
The GraphQL endpoint is now available at `http://localhost:4000/graphql`
3353

34-
## Releasing
54+
## Reprocessing
3555

36-
See [release process](./release_process.md)
56+
If a mapping bug is fixed and data needs remapping, reset the processor database and reindex:
3757

38-
## Notes
58+
```bash
59+
docker-compose down processor query-node
60+
./scripts/reset-db.sh
61+
docker-compose up -d
62+
```
3963

40-
### Reprocessing of indexer data
64+
This drops and recreates the processor's PostgreSQL database and reindexes from block 0 against the existing indexer data. The indexer does not need to be restarted — it stores raw blocks independently.
4165

42-
Reprocessing of indexer data (running the processor) would be usefull in situation where bugs are found and the data that is mapped would need remapping. This can be done by deleting the processor data and running it from 0 again with the code changes.
66+
See [typeChanges.md](./typeChanges.md) for more detail on when a resync is needed.

docs/readme.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
# TFchain Graphql Documentation
1+
# TFChain GraphQL Documentation
22

33
## Development
44

5-
see [development](./development.md)
5+
See [development](./development.md)
66

7-
## Running in Production mode
7+
## Running in Production
88

9-
see [production](./production.md)
9+
See [production](./production.md)
10+
11+
## Handling Type Changes
12+
13+
See [typeChanges](./typeChanges.md) — how to add new runtime versions, resync the processor, and how version detection works.
14+
15+
## Releasing
16+
17+
See [release_process](./release_process.md)

docs/release_process.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
11
# Release Process
22

3-
## Release a new version
3+
## Automated Version Bump
44

5-
1. Update the version in `indexer/chart.yaml` and `processor-chart/chart.yaml`
6-
2. Update the version `package.json` and `package-lock.json` (by doing `npm install` or `yarn`)
7-
3. Commit and these changes and tag the commit with the new version (e.g. `v0.0.1`)
8-
4. Create a release on github release page from the tag. The release title should be the version number and the release description should contain the changelog.
5+
The Makefile automates version bumping across `package.json` and both Helm charts:
6+
7+
```bash
8+
make version-bump type=patch # 2.12.3 → 2.12.4
9+
make version-bump type=minor # 2.12.3 → 2.13.0
10+
make version-bump type=major # 2.12.3 → 3.0.0
11+
```
12+
13+
This will:
14+
1. Checkout the default branch and pull latest
15+
2. Create a new branch `{default-branch}-bump-version-to-{version}`
16+
3. Update versions in `package.json`, `indexer/chart/Chart.yaml`, and `processor-chart/Chart.yaml`
17+
4. Commit the changes
18+
19+
Then create a PR, get it merged, and tag the release.
20+
21+
## Manual Version Bump
22+
23+
If you prefer to do it manually:
24+
25+
1. Update the version in `package.json`
26+
2. Update `appVersion` in `indexer/chart/Chart.yaml` and `processor-chart/Chart.yaml`
27+
3. Commit and tag the commit with the new version (e.g., `v2.13.0`)
28+
29+
## Creating a Release
30+
31+
1. Create a release on the GitHub releases page from the tag
32+
2. The release title should be the version number
33+
3. The release description should contain the changelog
34+
4. The `publish_container_images.yml` workflow will automatically build and push container images on tagged releases

indexer/chart/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
# Indexer stack chart
1+
# Indexer Stack Chart
22

3-
## Install chart with helm
3+
## Install chart with Helm
44

5-
Create PersistentVolumeClaims for the database if wanted and reference the name in your values file in the `volume.existingpersistentVolumeClaim` property.
5+
Create PersistentVolumeClaims for the database if needed and reference the name in your values file in the `volume.existingpersistentVolumeClaim` property.
66

77
```sh
8-
helm installtfchainindexer [-f yourvaluesfile.yaml] .
8+
helm install tfchainindexer [-f yourvaluesfile.yaml] .
99
```
1010

11-
If the indexer cannot reach the database, you can set `db_url` to the db-service cluster ip.
11+
If the indexer cannot reach the database, you can set `db_url` to the db-service cluster IP:
1212

1313
```sh
1414
kubectl get svc
1515
```
1616

17-
NOTE: take note of the IP assigned the db-service. Use this IP in `values.yaml` for the db_endpoint, ws_endpoint and indexer_status_service_url. Until DNS resolution works you can update these via 'helm upgrade'.
17+
Take note of the IP assigned to the db-service. Use this IP in `values.yaml` for `db_endpoint`, `ws_endpoint`, and `indexer_status_service_url`. You can update these via `helm upgrade` if the IPs change.

indexer/development.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
# Tfchain hydra indexer development
1+
# Indexer Development
22

3-
## Modifying the types.json
3+
## typesBundle.json
44

5-
When the typesBundle.json file has been modified, it needs to be updated in the helm chart as well.
5+
The `typesBundle.json` file maps Substrate custom types for pre-V14 metadata (specVersions before ~v100). This file is **frozen** — TFChain now uses Polkadot SDK v1.1.0 with V14+ self-describing metadata, so new runtime versions do not require changes to this file.
6+
7+
See [docs/typeChanges.md](../docs/typeChanges.md#notes-on-typesbundlejson) for details.
8+
9+
## Updating the Helm Chart ConfigMap
10+
11+
If `typesBundle.json` ever needs updating (unlikely — only for newly discovered pre-V14 type gaps), regenerate the Helm chart configmap:
612

713
```sh
814
kubectl create configmap indexer-config --from-file=./typesBundle.json --dry-run=client --output=yaml > chart/templates/indexer-config.yaml
915
```
1016

11-
Don't forget to update the chart version afterwards.
17+
Then update the chart version in `chart/Chart.yaml`.

0 commit comments

Comments
 (0)