Skip to content

Commit 18d02fa

Browse files
authored
Add AI-generated docs (0LNetworkCommunity#107)
1 parent c647ba0 commit 18d02fa

3 files changed

Lines changed: 806 additions & 78 deletions

File tree

CLAUDE.md

Lines changed: 187 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -4,115 +4,224 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
## Project Overview
66

7-
This is the 0L Network Explorer, a full-stack application for exploring the 0L blockchain. The repository contains:
8-
9-
- **api/**: NestJS GraphQL backend with ClickHouse integration for blockchain data
10-
- **web-app/**: React frontend with TypeScript and Vite
11-
- **api/transformer/**: Rust binary for data transformation
7+
The 0L Network Explorer is a full-stack blockchain explorer application with:
8+
- **api/**: NestJS GraphQL backend with ClickHouse analytics
9+
- **web-app/**: React TypeScript frontend with Vite
10+
- **api/transformer/**: Rust binary for blockchain data transformation
1211
- **infra/**: Kubernetes deployment configurations
13-
- **ol-fyi-local-infra/**: Docker Compose setup for local development
12+
- **ol-fyi-local-infra/**: Docker Compose for local development
1413

1514
## Common Development Commands
1615

1716
### API (Backend)
1817
```bash
1918
cd api
2019
npm install
21-
npm run start:dev # Development with hot reload
22-
npm run build # Build production
23-
npm run test # Run Jest tests
24-
npm run test:e2e # End-to-end tests
25-
npm run lint # ESLint with auto-fix
26-
npm run format # Prettier formatting
27-
npx prisma generate # Generate Prisma client after schema changes
28-
npx prisma db push # Push schema changes to database
20+
npm run start:dev # Development with hot reload (port 3000)
21+
npm run build # Production build
22+
npm run test # Run Jest unit tests
23+
npm run test:watch # Jest watch mode
24+
npm run test:cov # Coverage report
25+
npm run test:e2e # End-to-end tests
26+
npm run lint # ESLint with auto-fix
27+
npm run format # Prettier formatting
28+
npx prisma generate # Regenerate Prisma client after schema changes
29+
npx prisma db push # Push schema changes to database
2930
```
3031

3132
### Web App (Frontend)
3233
```bash
3334
cd web-app
3435
npm install
35-
npm run dev # Vite development server
36-
npm run build # TypeScript compilation + Vite build
37-
npm run lint # ESLint
38-
npm run preview # Preview production build
39-
npm run prettier-check # Check formatting
40-
npm run prettier-fix # Fix formatting
36+
npm run dev # Vite dev server (port 5173)
37+
npm run build # TypeScript + Vite production build
38+
npm run lint # ESLint
39+
npm run preview # Preview production build
40+
npm run prettier-fix # Auto-format code
4141
```
4242

4343
### Transformer (Rust)
4444
```bash
4545
cd api/transformer
46-
cargo build # Build the binary
46+
cargo build # Build the transformer binary
4747
```
4848

4949
## Architecture Overview
5050

5151
### Backend Architecture (NestJS)
52-
- **GraphQL API** with Apollo Server and subscriptions
53-
- **Modular structure** with feature-based modules (accounts, validators, transactions, stats)
54-
- **Database layers**: PostgreSQL (Prisma) for app data, ClickHouse for blockchain analytics
55-
- **Background processing** with BullMQ queues and Redis
56-
- **External integrations**: S3, Firebase, NATS messaging
57-
- **Role-based workers** configured via ROLES environment variable
58-
59-
Key modules:
60-
- `OlModule`: Core blockchain data handling
61-
- `StatsModule`: Analytics and metrics
62-
- `NodeWatcherModule`: Network monitoring
63-
- `ValidatorsModule`: Validator information
64-
- `TransactionsModule`: Transaction processing with factory pattern
52+
53+
**Module Structure** (`api/src/`):
54+
- `app/app.module.ts`: Root module with dependency configuration
55+
- `ol/`: Core blockchain data handling
56+
- `accounts/`: Account processing and resolution
57+
- `validators/`: Validator information and statistics
58+
- `transactions/`: Transaction factory pattern implementation
59+
- `movements/`: Token movement tracking
60+
- `community-wallets/`: Community wallet management
61+
- `stats/`: Analytics and metrics processing
62+
- `node-watcher/`: Network monitoring
63+
- `clickhouse/`: ClickHouse database integration
64+
- `multi-sig/`: Multi-signature wallet operations
65+
- `redis/`, `nats/`, `s3/`, `firebase/`: Service integrations
66+
67+
**Role-Based Worker System**:
68+
Workers are configured via the `ROLES` environment variable:
69+
- `version-batch-processor`: Batch blockchain version processing
70+
- `parquet-producer-processor`: Parquet file generation for analytics
71+
- `version-processor`: Individual version processing
72+
- `clickhouse-ingestor-processor`: Data ingestion to ClickHouse
73+
- `expired-transactions-processor`: Clean up expired transactions
74+
- `accounts-processor`: Account data processing
75+
76+
**GraphQL Patterns**:
77+
- Resolvers use `@Resolver()` decorator with model types
78+
- Field resolvers use `@ResolveField()` for nested data
79+
- Pagination uses cursor-based approach with `PaginatedX` types
80+
- Custom scalars for Buffer and BigNumber types
81+
82+
**Transaction Processing**:
83+
Factory pattern in `api/src/ol/transactions/`:
84+
- `TransactionsFactory.ts`: Creates transaction handlers
85+
- `TransactionsService.ts`: Core business logic
86+
- `TransactionsRepository.ts`: Database operations
87+
- `OnChainTransactionsRepository.ts`: Blockchain data access
6588

6689
### Frontend Architecture (React)
67-
- **React 18** with TypeScript and Vite
68-
- **Routing** with React Router v6
69-
- **State management** via Apollo Client for GraphQL
70-
- **Styling** with Styled Components and Tailwind CSS
71-
- **Charts** using ECharts for data visualization
72-
- **Wallet integration** with Aptos wallet adapters
73-
74-
Component structure:
75-
- `modules/core/`: App setup, routing, Apollo client
76-
- `modules/core/routes/`: Page components (Account, Stats, Validators, etc.)
77-
- `modules/ui/`: Reusable UI components
78-
- `modules/interface/`: TypeScript interfaces
90+
91+
**Module Structure** (`web-app/src/modules/`):
92+
- `core/`: Application foundation
93+
- `router.tsx`: React Router v6 configuration
94+
- `apollo-client.ts`: GraphQL client setup with WebSocket subscriptions
95+
- `routes/`: Page components (Account, Stats, Validators, Blocks, etc.)
96+
- `ui/`: Reusable UI components
97+
- `interface/`: TypeScript interfaces and types
98+
- `aptos/`: Wallet integration components
99+
- `ol/`, `movements/`: Domain-specific modules
100+
101+
**Routing Structure**:
102+
- `/accounts/:address`: Account details with nested routes (movements, transactions)
103+
- `/transactions/:version`: Transaction details
104+
- `/blocks/:blockHeight`: Block exploration
105+
- `/validators`: Validator list and details
106+
- `/stats`: Network statistics dashboard
107+
- `/community-wallets`: Community wallet tracking
108+
109+
**State Management**:
110+
- Apollo Client for GraphQL state and caching
111+
- Real-time updates via GraphQL subscriptions
112+
- Styled Components + Tailwind CSS for styling
79113

80114
### Data Flow
81-
1. Blockchain data ingested via background processors
82-
2. Raw data transformed by Rust transformer binary
83-
3. Processed data stored in ClickHouse and PostgreSQL
84-
4. GraphQL resolvers query databases
85-
5. React frontend consumes GraphQL API with real-time subscriptions
115+
1. Blockchain data ingested via role-based processors
116+
2. Rust transformer processes raw data (`api/transformer/`)
117+
3. Processed data stored in ClickHouse (analytics) and PostgreSQL (app data)
118+
4. GraphQL resolvers query both databases
119+
5. React frontend consumes GraphQL API with real-time subscriptions via WebSocket
86120

87121
## Local Development Setup
88122

89-
1. **Prerequisites**: Docker, Node.js 20.11+, Rust
90-
2. **Start databases**: `cd ol-fyi-local-infra && docker compose up -d`
91-
3. **ClickHouse setup**: Connect and run migrations from `api/tables_local.sql`
92-
4. **Build transformer**: `cd api/transformer && cargo build`
93-
5. **API setup**: `cd api && npm install && cp .env.example .env`
94-
6. **Frontend setup**: `cd web-app && npm install`
95-
7. **Run API**: `npm run start:dev` (from api/)
96-
8. **Run frontend**: `npm run dev` (from web-app/)
97-
98-
## Key Technologies
99-
100-
- **Backend**: NestJS, GraphQL, Prisma, ClickHouse, BullMQ, Redis, NATS
101-
- **Frontend**: React, TypeScript, Apollo Client, Styled Components, ECharts
102-
- **Infrastructure**: Docker, Kubernetes, PostgreSQL, ClickHouse
103-
- **Blockchain**: Aptos SDK for 0L Network integration
123+
### Prerequisites
124+
- Docker and Docker Compose
125+
- Node.js 22+
126+
- Rust and Cargo
127+
- PostgreSQL client tools
128+
129+
### Setup Steps
130+
131+
1. **Start infrastructure**:
132+
```bash
133+
cd ol-fyi-local-infra
134+
docker compose up -d
135+
```
136+
137+
2. **Run ClickHouse migrations**:
138+
```bash
139+
docker compose exec -T clickhouse clickhouse-client --database=olfyi -n < ../api/tables_local.sql
140+
```
141+
142+
3. **Build transformer**:
143+
```bash
144+
cd api/transformer
145+
cargo build
146+
```
147+
148+
4. **Setup API**:
149+
```bash
150+
cd api
151+
npm install
152+
cp .env.example .env
153+
npx prisma generate
154+
npx prisma db push
155+
npm run start:dev
156+
```
157+
158+
5. **Setup frontend**:
159+
```bash
160+
cd web-app
161+
npm install
162+
npm run dev
163+
```
164+
165+
## Environment Configuration
166+
167+
Key environment variables in `api/.env`:
168+
- `DATABASE_URL`: PostgreSQL connection for Prisma
169+
- `CLICKHOUSE_HOST`, `CLICKHOUSE_DATABASE`: ClickHouse connection
170+
- `REDIS_HOST`: Redis for BullMQ queues
171+
- `NATS_SERVERS`: NATS messaging system
172+
- `RPC_PROVIDER_URL`: 0L blockchain RPC endpoint
173+
- `DATA_API_HOST`: Blockchain data API
174+
- `ROLES`: Comma-separated list of worker roles to enable
175+
- `S3_*`: Object storage configuration for Parquet files
104176

105177
## Testing Strategy
106178

107-
- API uses Jest for unit and e2e tests
108-
- Frontend uses ESLint for code quality
109-
- Prisma for database schema management
110-
- Both projects use Prettier for code formatting
111-
112-
## Code Quality Standards
113-
114-
When working with files in this repository:
115-
116-
- **ALWAYS ensure files end with a trailing newline** - This is required for proper POSIX compliance and prevents issues with git diffs and various tools
117-
- Follow existing code style and formatting conventions
118-
- Use the project's linting and formatting tools before committing
179+
### API Testing
180+
- **Test Files**: `*.spec.ts` files co-located with source code
181+
- **E2E Tests**: Separate `/test/` directory
182+
- **Configuration**: Jest with ESM support via ts-jest
183+
- **Run Tests**: `npm run test` (unit), `npm run test:e2e` (integration)
184+
185+
### Code Quality
186+
- **Prettier**: Line width 100, single quotes, trailing commas
187+
- **ESLint**: TypeScript configuration with auto-fix
188+
- **Pre-commit**: Run `npm run lint` and `npm run prettier-fix`
189+
190+
## Key Architectural Patterns
191+
192+
1. **Dependency Injection**: NestJS DI for service management
193+
2. **Factory Pattern**: Transaction processing with pluggable handlers
194+
3. **Repository Pattern**: Clean data access layer abstractions
195+
4. **Module Federation**: Feature-based module organization
196+
5. **Real-time Updates**: GraphQL subscriptions over WebSocket
197+
6. **Multi-database**: PostgreSQL (app), ClickHouse (analytics)
198+
7. **Background Processing**: BullMQ queues with Redis
199+
8. **Role-based Workers**: Configurable processing roles
200+
201+
## Database Schema
202+
203+
### PostgreSQL (Prisma)
204+
- Application configuration
205+
- User preferences
206+
- Wallet subscriptions
207+
- Multi-sig wallet data
208+
209+
### ClickHouse
210+
- Blockchain transactions
211+
- Account balances
212+
- Validator statistics
213+
- Network metrics
214+
- Time-series analytics
215+
216+
## Deployment
217+
218+
### Docker Build
219+
- **API**: Multi-stage build with Rust transformer and Node.js
220+
- **Frontend**: Vite build with Nginx serving
221+
- **Infrastructure**: Kubernetes manifests in `/infra/`
222+
223+
### Production Considerations
224+
- Enable specific worker roles per deployment
225+
- Configure appropriate database connections
226+
- Set up S3 for Parquet file storage
227+
- Configure Firebase for push notifications

0 commit comments

Comments
 (0)