Skip to content

Commit ef0f02b

Browse files
committed
add claude.md file
1 parent 9e4dad9 commit ef0f02b

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

CLAUDE.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
This document assumes that your human has already set up all database configuration required for the test suite to run.
6+
7+
## Project Overview
8+
9+
Graph Node is a Rust-based decentralized blockchain indexing protocol that enables efficient querying of blockchain data through GraphQL. It's the core component of The Graph protocol, written as a Cargo workspace with multiple crates organized by functionality.
10+
11+
## Essential Development Commands
12+
13+
### Testing
14+
15+
```bash
16+
# Run unit tests (integration tests are excluded due to missing environment dependencies)
17+
# Claude should set the database URL before running tests:
18+
export THEGRAPH_STORE_POSTGRES_DIESEL_URL="postgresql://graph:graph@127.0.0.1:5432/graph-test"
19+
cargo test --workspace --exclude graph-tests
20+
21+
# Or run inline:
22+
THEGRAPH_STORE_POSTGRES_DIESEL_URL="postgresql://graph:graph@127.0.0.1:5432/graph-test" cargo test <test_name>
23+
```
24+
25+
### Code Quality
26+
```bash
27+
# Format all code
28+
cargo fmt --all
29+
30+
# Check code without building
31+
cargo check
32+
```
33+
34+
## High-Level Architecture
35+
36+
### Core Components
37+
- **`graph/`**: Core abstractions, traits, and shared types
38+
- **`node/`**: Main executable and CLI (graphman)
39+
- **`chain/`**: Blockchain-specific adapters (ethereum, near, substreams)
40+
- **`runtime/`**: WebAssembly runtime for subgraph execution
41+
- **`store/`**: PostgreSQL-based storage layer
42+
- **`graphql/`**: GraphQL query execution engine
43+
- **`server/`**: HTTP/WebSocket APIs
44+
45+
### Data Flow
46+
```
47+
Blockchain → Chain Adapter → Block Stream → Trigger Processing → Runtime → Store → GraphQL API
48+
```
49+
50+
1. **Chain Adapters** connect to blockchain nodes and convert data to standardized formats
51+
2. **Block Streams** provide event-driven streaming of blockchain blocks
52+
3. **Trigger Processing** matches blockchain events to subgraph handlers
53+
4. **Runtime** executes subgraph code in WebAssembly sandbox
54+
5. **Store** persists entities with block-level granularity
55+
6. **GraphQL** processes queries and returns results
56+
57+
### Key Abstractions
58+
- **`Blockchain`** trait: Core blockchain interface
59+
- **`Store`** trait: Storage abstraction with read/write variants
60+
- **`RuntimeHost`**: WASM execution environment
61+
- **`TriggerData`**: Standardized blockchain events
62+
- **`EventConsumer`/`EventProducer`**: Component communication
63+
64+
### Architecture Patterns
65+
- **Event-driven**: Components communicate through async streams and channels
66+
- **Trait-based**: Extensive use of traits for abstraction and modularity
67+
- **Async/await**: Tokio-based async runtime throughout
68+
- **Multi-shard**: Database sharding for scalability
69+
- **Sandboxed execution**: WASM runtime with gas metering
70+
71+
## Development Guidelines
72+
73+
### Commit Convention
74+
Use format: `{crate-name}: {description}`
75+
- Single crate: `store: Support 'Or' filters`
76+
- Multiple crates: `core, graphql: Add event source to store`
77+
- All crates: `all: {description}`
78+
79+
### Git Workflow
80+
- Rebase on master (don't merge master into feature branch)
81+
- Keep commits logical and atomic
82+
- Use `git rebase -i` to clean up history before merging
83+
84+
### Testing Requirements
85+
- Unit tests inline with source code
86+
- Integration tests require Docker Compose setup and additional environment dependencies
87+
- Claude cannot run integration tests due to missing environment dependencies
88+
- Claude must set `THEGRAPH_STORE_POSTGRES_DIESEL_URL` before running any tests
89+
90+
### Environment Variables
91+
- `GRAPH_LOG=debug`: Enable debug logging
92+
- `THEGRAPH_STORE_POSTGRES_DIESEL_URL`: Required for most tests - Claude must set this to `postgresql://graph:graph@127.0.0.1:5432/graph-test`
93+
- `GRAPH_NODE_TEST_CONFIG`: Points to test configuration file
94+
95+
## Crate Structure
96+
97+
### Core Crates
98+
- **`graph`**: Shared types, traits, and utilities
99+
- **`node`**: Main binary and component wiring
100+
- **`core`**: Business logic and subgraph management
101+
102+
### Blockchain Integration
103+
- **`chain/ethereum`**: Ethereum chain support
104+
- **`chain/near`**: NEAR protocol support
105+
- **`chain/substreams`**: Substreams data source support
106+
107+
### Infrastructure
108+
- **`store/postgres`**: PostgreSQL storage implementation
109+
- **`runtime/wasm`**: WebAssembly runtime and host functions
110+
- **`graphql`**: Query processing and execution
111+
- **`server/`**: HTTP/WebSocket servers
112+
113+
### Key Dependencies
114+
- **`diesel`**: PostgreSQL ORM
115+
- **`tokio`**: Async runtime
116+
- **`tonic`**: gRPC framework
117+
- **`wasmtime`**: WebAssembly runtime
118+
- **`web3`**: Ethereum interaction
119+
120+
## Test Environment Requirements
121+
Most tests require external services to be running:
122+
- **IPFS**: Required for distributed storage functionality
123+
- **PostgreSQL**: Required for database operations and storage tests
124+
- Your human should ensure these services are running before test execution

0 commit comments

Comments
 (0)