Skip to content

Commit a2f4b87

Browse files
authored
Merge pull request #329 from AugustoL/docs/update-claude-rules
docs(claude): update rules to reflect current architecture and workflow
2 parents da00c68 + 743e171 commit a2f4b87

File tree

5 files changed

+112
-77
lines changed

5 files changed

+112
-77
lines changed

.claude/rules/architecture.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,47 @@
44

55
OpenScan follows a layered architecture with clear separation between data fetching, transformation, and presentation:
66

7-
### 1. RPC Layer (`RPCClient.ts`)
8-
Handles JSON-RPC communication with blockchain nodes:
9-
- Supports two strategies: `fallback` (sequential with automatic failover) and `parallel` (query all providers simultaneously)
10-
- Strategy is configurable via user settings (`useDataService` hook applies strategy)
11-
- Parallel mode enables provider comparison and inconsistency detection
12-
13-
### 2. Fetcher Layer (`services/EVM/*/fetchers/`)
14-
Makes raw RPC calls for specific data types:
15-
- Network-specific implementations: `L1/`, `Arbitrum/`, `Optimism/`
16-
- Each fetcher handles one domain (blocks, transactions, addresses, network stats)
17-
18-
### 3. Adapter Layer (`services/EVM/*/adapters/`)
19-
Transforms raw RPC responses into typed domain objects:
20-
- Normalizes network-specific fields (e.g., Arbitrum's `l1BlockNumber`, Optimism's L1 fee data)
21-
- Ensures consistent type structure across networks
22-
23-
### 4. Service Layer (`DataService.ts`)
7+
### 1. Client Layer (`@openscan/network-connectors`)
8+
Typed RPC clients for blockchain communication:
9+
- `EthereumClient` - Standard JSON-RPC for EVM chains
10+
- `HardhatClient` - Extended client with Hardhat-specific methods (`hardhat_*`, `evm_*`, `debug_*`)
11+
- `BitcoinClient` - Bitcoin JSON-RPC (`getblock`, `getrawtransaction`, etc.)
12+
- Supports `fallback`, `parallel`, and `race` strategies
13+
14+
### 2. Adapter Layer (`services/adapters/`)
15+
Abstract `NetworkAdapter` base class with chain-specific implementations:
16+
- `EVMAdapter` - Default EVM adapter (Ethereum, BSC, Polygon, Sepolia)
17+
- `ArbitrumAdapter` - Adds `l1BlockNumber`, `sendCount`, `sendRoot`
18+
- `OptimismAdapter` / `BaseAdapter` - Adds L1 fee breakdown (`l1Fee`, `l1GasPrice`, `l1GasUsed`)
19+
- `HardhatAdapter` - Localhost (31337) with trace support via struct log conversion
20+
- `BitcoinAdapter` - Bitcoin networks with UTXO model, mempool, and block explorer
21+
- Each adapter implements: `getBlock`, `getTransaction`, `getAddress`, `getNetworkStats`, trace methods
22+
- `AdapterFactory` routes chain ID to the correct adapter
23+
24+
### 3. Service Layer (`DataService.ts`)
2425
Orchestrates data fetching with caching and metadata:
25-
- Instantiates network-specific fetchers/adapters based on chain ID
26+
- Instantiates the correct adapter via `AdapterFactory` based on chain ID
2627
- Returns `DataWithMetadata<T>` when using parallel strategy
2728
- 30-second in-memory cache keyed by `networkId:type:identifier`
2829
- Supports trace operations for Hardhat (31337) and localhost networks
2930

30-
### 5. Hook Layer (`hooks/`)
31+
### 4. Hook Layer (`hooks/`)
3132
React integration:
3233
- `useDataService(networkId)`: Creates DataService instance with strategy from settings
3334
- `useProviderSelection`: Manages user's selected RPC provider in parallel mode
3435
- `useSelectedData`: Extracts data from specific provider based on user selection
3536

36-
### 6. Context Layer (`context/`)
37+
### 5. Context Layer (`context/`)
3738
Global state management:
3839
- `AppContext`: RPC URLs configuration
39-
- `SettingsContext`: User settings including `rpcStrategy` ('fallback' | 'parallel')
40+
- `SettingsContext`: User settings including `rpcStrategy` ('fallback' | 'parallel' | 'race')
4041

4142
## Network-Specific Handling
4243

43-
Chain ID detection in `DataService` constructor determines which adapters/fetchers to use:
44+
Chain ID detection in `AdapterFactory` determines which adapter to instantiate:
4445

45-
- **Arbitrum** (42161): `ArbitrumAdapter` - adds `l1BlockNumber`, `sendCount`, `requestId`
46+
- **Arbitrum** (42161): `ArbitrumAdapter` - adds `l1BlockNumber`, `sendCount`, `sendRoot`
47+
- **Bitcoin** (bip122:*): `BitcoinAdapter` - UTXO model, mempool transactions, block rewards
4648
- **OP Stack** (10, 8453): `OptimismAdapter` (10), `BaseAdapter` (8453) - adds L1 fee breakdown (`l1Fee`, `l1GasPrice`, `l1GasUsed`)
4749
- **Hardhat** (31337): `HardhatAdapter` - uses `HardhatClient` from `@openscan/network-connectors`; trace support via struct log conversion (`buildCallTreeFromStructLogs`, `buildPrestateFromStructLogs` in `src/utils/structLogConverter.ts`) since Hardhat v3 does not support `callTracer`/`prestateTracer`
4850
- **Default**: `EVMAdapter` for Ethereum (1), BSC (56, 97), Polygon (137), Sepolia (11155111), Avalanche (43114)

.claude/rules/code-style.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ npm run typecheck
6161

6262
# 4. Verify i18n compliance
6363
# - Ensure no hardcoded user-facing strings
64-
# - Test in both English and Spanish if you added translations
64+
# - Test in multiple languages if you added translations (en, es, ja, pt-BR, zh)
6565

6666
# 5. Run tests (if applicable)
6767
npm run test:run

.claude/rules/i18n.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- **Library**: react-i18next (v16.5.4) with i18next (v25.8.0)
1010
- **Configuration**: `src/i18n.ts`
1111
- **Type Definitions**: `src/i18next.d.ts` (provides TypeScript autocomplete)
12-
- **Supported Languages**: English (en), Spanish (es)
12+
- **Supported Languages**: English (en), Spanish (es), Japanese (ja), Portuguese-BR (pt-BR), Chinese (zh)
1313
- **Language Detection**: Auto-detects from browser or localStorage (`openScan_language`)
1414

1515
## When to Use i18n
@@ -49,6 +49,7 @@ Choose the appropriate namespace based on the component location:
4949
8. **devtools** - Developer tools page
5050
9. **errors** - Error messages (if not in common)
5151
10. **tokenDetails** - Token detail pages (ERC20, ERC721, ERC1155)
52+
11. **tooltips** - Helper tooltip content for blockchain data fields (used by FieldLabel/HelperTooltip)
5253

5354
## Basic Usage
5455

@@ -153,9 +154,9 @@ const currentLang = i18n.language; // "en" or "es"
153154

154155
1. **Identify the appropriate namespace** based on component location
155156
2. **Add key to English file** (`src/locales/en/{namespace}.json`)
156-
3. **Add same key to Spanish file** (`src/locales/es/{namespace}.json`)
157+
3. **Add same key to all other locale files** (`src/locales/{es,ja,pt-BR,zh}/{namespace}.json`)
157158
4. **Use TypeScript autocomplete** to verify the key exists
158-
5. **Test in both languages** by switching in Settings
159+
5. **Test in multiple languages** by switching in Settings
159160

160161
### Example
161162

@@ -325,9 +326,9 @@ When adding or modifying components, ensure:
325326
326327
- [ ] No hardcoded user-facing strings remain
327328
- [ ] All text uses `t()` function from useTranslation
328-
- [ ] Translation keys exist in **both** en/ and es/ directories
329+
- [ ] Translation keys exist in **all** locale directories (en, es, ja, pt-BR, zh)
329330
- [ ] TypeScript compilation passes (`npm run typecheck`)
330-
- [ ] Tested in both English and Spanish (switch in Settings)
331+
- [ ] Tested in multiple languages (switch in Settings)
331332
332333
## Checklist for Code Review
333334
@@ -337,5 +338,5 @@ When reviewing code, verify:
337338
- [ ] Appropriate namespace is selected
338339
- [ ] Translation keys follow existing naming patterns
339340
- [ ] Interpolation variables are properly typed
340-
- [ ] Translations exist in all supported languages
341+
- [ ] Translations exist in all 5 supported languages (en, es, ja, pt-BR, zh)
341342
- [ ] No typos in translation keys (TypeScript should catch these)

.claude/rules/patterns.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22

33
## When Modifying Data Fetching
44

5-
- Always maintain the adapter pattern: Fetcher → Adapter → Service
5+
- Always maintain the adapter pattern: Client → Adapter → Service
6+
- All adapters extend the abstract `NetworkAdapter` class (`services/adapters/NetworkAdapter.ts`)
67
- If adding parallel strategy support, ensure complete objects are built for each provider
7-
- Test both `fallback` and `parallel` strategies
8+
- Test `fallback`, `parallel`, and `race` strategies
89
- Update TypeScript types in `src/types/index.ts` if adding new fields
910

1011
## When Adding L2-Specific Features
1112

1213
- Check if network is OP Stack-based (Optimism, Base) or Arbitrum
1314
- Add network-specific types (e.g., `TransactionOptimism extends Transaction`)
14-
- Create adapters that inherit base behavior and add L2 fields
15-
- Update `DataService` conditional logic in constructor and relevant methods
15+
- Create a new adapter extending `NetworkAdapter` in `services/adapters/[Network]/`
16+
- Register the adapter in `AdapterFactory` (`services/adapters/adaptersFactory.ts`)
1617

1718
## When Working with Cache
1819

@@ -32,10 +33,10 @@
3233

3334
1. Add chain ID to `src/types/index.ts` if creating new domain types
3435
2. Add default RPC endpoints to `src/config/rpcConfig.ts`
35-
3. Determine if network needs a custom adapter (L1, Arbitrum-like, OP Stack-like, Hardhat-like)
36-
4. If custom: create `src/services/adapters/[Network]Adapter/[Network]Adapter.ts`
37-
5. Register the adapter in `src/services/adapters/adaptersFactory.ts` with its chain ID
38-
6. Add network config to `src/config/networks.json`
36+
3. Determine if network needs a custom adapter (L1, Arbitrum-like, OP Stack-like, Bitcoin, Hardhat-like)
37+
4. If custom: create `src/services/adapters/[Network]/[Network]Adapter.ts` extending `NetworkAdapter`
38+
5. Register the adapter in `AdapterFactory` (`src/services/adapters/adaptersFactory.ts`)
39+
6. Add network config to `ALL_NETWORKS` in `src/config/networks.ts`
3940
7. Add network logo to `public/` and update `logoType` in network config
4041

4142
## Testing with Local Networks
@@ -51,7 +52,7 @@ OpenScan includes special support for localhost development:
5152

5253
### Address Page Components
5354
- Use display components for different address types: `AccountDisplay`, `ContractDisplay`, `ERC20Display`, `ERC721Display`, `ERC1155Display`
54-
- Shared components in `src/components/pages/address/shared/`
55+
- Shared components in `src/components/pages/evm/address/shared/`
5556
- Card-based layout with Overview and More Info sections
5657

5758
### Theming

.claude/rules/workflow.md

Lines changed: 69 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,76 +2,107 @@
22

33
## Branch Strategy
44

5-
The project follows a structured branching workflow:
5+
The project uses two workflows depending on the scope of changes:
6+
7+
### Patch Releases (default workflow)
8+
9+
For incremental work (bug fixes, small features, improvements) that goes into the next patch version:
610

711
```
8-
feature/fix/refactor branches → release branch (vX.Y.Z) → dev (staging/QA) → main (production)
12+
feature/fix/refactor branches → dev (release candidate) → main (production)
913
```
1014

11-
### Branch Types
15+
1. **Dev Branch**: Always holds the next release candidate (patch increment)
16+
- Feature/fix PRs are created directly against `dev`
17+
- Used for QA/staging before production
18+
- Always represents the next patch version (e.g., if main is v1.2.0, dev is the v1.2.1 candidate)
1219

13-
1. **Feature/Fix/Refactor Branches**: Created from the **release branch** for specific changes
20+
2. **Feature/Fix/Refactor Branches**: Created from `dev`
1421
- Naming: `feat/<description>`, `fix/<description>`, `refactor/<description>`
15-
- Example: `feat/token-holdings`, `fix/light-theme-colors`, `refactor/address-layout`
16-
- PRs are created against the release branch
17-
18-
2. **Release Branches**: Created for each release cycle
19-
- Naming: `release/vX.Y.Z` (e.g., `release/v1.1.1`)
20-
- All feature branches are merged here
21-
- When features are complete, merged to `dev` for QA/staging
22+
- PRs are created against `dev`
2223

23-
3. **Dev Branch**: Staging/QA environment
24-
- Receives merges from release branches
25-
- Used for QA testing before production
26-
- If fixes are needed during QA, PRs can be created directly against `dev`
27-
28-
4. **Main Branch**: Production-ready code
24+
3. **Main Branch**: Production-ready code
2925
- Only receives merges from `dev` after QA approval
30-
- Always stable and deployable
26+
- Tagged with the version on merge
3127

32-
### Workflow Steps
28+
#### Patch Workflow Steps
3329

34-
1. Create or checkout the release branch:
30+
1. Create feature branch from `dev`:
3531
```bash
36-
git checkout release/v1.1.1
37-
git pull origin release/v1.1.1
32+
git checkout dev
33+
git pull origin dev
34+
git checkout -b feat/my-feature
3835
```
3936

40-
2. Create feature branch from the release branch:
37+
2. Work on feature, commit changes following conventional commits
38+
39+
3. Push and create PR to `dev`:
4140
```bash
42-
git checkout -b feat/my-feature
41+
git push -u origin feat/my-feature
42+
gh pr create --base dev
4343
```
4444

45-
3. Work on feature, commit changes following conventional commits
45+
4. After PR approval and merge to `dev`, delete feature branch
4646

47-
4. Push and create PR to the **release branch**:
47+
5. After QA approval, merge `dev` to `main`:
4848
```bash
49-
git push -u origin feat/my-feature
50-
gh pr create --base release/v1.1.1
49+
git checkout main
50+
git merge dev
51+
git tag v1.2.1
52+
git push origin main --tags
5153
```
5254

53-
5. After PR approval and merge to release branch, delete feature branch
55+
### Minor/Major Releases (release branch workflow)
56+
57+
For larger milestones with multiple coordinated changes (new features, breaking changes):
5458

55-
6. When release is ready for QA, merge release branch to `dev`:
59+
```
60+
feature/fix/refactor branches → release branch (vX.Y.Z) → dev → main
61+
```
62+
63+
1. **Release Branches**: Created from `dev` for each release cycle
64+
- Naming: `release/vX.Y.Z` (e.g., `release/v1.3.0`)
65+
- Feature branches are created from and merged into the release branch
66+
- When features are complete, merged to `dev` for QA/staging
67+
68+
2. **Feature Branches**: Created from the **release branch**
69+
- PRs are created against the release branch
70+
71+
#### Release Branch Workflow Steps
72+
73+
1. Create the release branch from `dev`:
5674
```bash
5775
git checkout dev
58-
git merge release/v1.1.1
59-
git push origin dev
76+
git checkout -b release/v1.3.0
77+
git push -u origin release/v1.3.0
78+
```
79+
80+
2. Create feature branches from the release branch:
81+
```bash
82+
git checkout release/v1.3.0
83+
git checkout -b feat/my-feature
6084
```
6185

62-
7. **QA/Staging fixes**: If issues are found during QA, create PRs directly against `dev`:
86+
3. Push and create PR to the **release branch**:
87+
```bash
88+
git push -u origin feat/my-feature
89+
gh pr create --base release/v1.3.0
90+
```
91+
92+
4. When all features are merged, merge release branch to `dev` for QA:
6393
```bash
6494
git checkout dev
65-
git checkout -b fix/qa-issue
66-
# ... fix the issue ...
67-
gh pr create --base dev
95+
git merge release/v1.3.0
96+
git push origin dev
6897
```
6998

70-
8. After QA approval, merge `dev` to `main`:
99+
5. QA fixes go directly against `dev`
100+
101+
6. After QA approval, merge `dev` to `main`:
71102
```bash
72103
git checkout main
73104
git merge dev
74-
git tag v1.1.1
105+
git tag v1.3.0
75106
git push origin main --tags
76107
```
77108

0 commit comments

Comments
 (0)