Skip to content

Commit 1f85150

Browse files
authored
Merge pull request #170 from TrainProtocol/dev
Dev to main
2 parents d9f682c + cf5cb44 commit 1f85150

1,149 files changed

Lines changed: 125490 additions & 107294 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/commands/packages.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Explain the Train Protocol packages architecture to help agents understand the codebase.
2+
3+
Read and summarize the following README files to understand what each package does:
4+
- packages/sdk/README.md — @train-protocol/sdk (core HTLC logic, API client, verification, key derivation)
5+
- packages/react/README.md — @train-protocol/react (React hooks, providers, swap state management)
6+
- packages/blockchains/evm/README.md — @train-protocol/evm (EVM HTLC client)
7+
8+
Also check for READMEs in other blockchain packages:
9+
- packages/blockchains/solana/
10+
- packages/blockchains/starknet/
11+
- packages/blockchains/aztec/
12+
13+
After reading, provide a concise summary of:
14+
1. What each package does and its key exports
15+
2. How the packages relate to each other (dependency graph)
16+
3. The plugin registration pattern (how chain-specific packages plug into the SDK)
17+
4. The provider hierarchy in @train-protocol/react
18+
5. The HTLC swap flow across packages

.claude/commands/reviewchanges.md

Lines changed: 308 additions & 0 deletions
Large diffs are not rendered by default.

.claude/rules/chain-integration.md

Lines changed: 626 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
---
2+
name: next-best-practices
3+
description: Next.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling
4+
user-invocable: false
5+
---
6+
7+
# Next.js Best Practices
8+
9+
Apply these rules when writing or reviewing Next.js code.
10+
11+
## File Conventions
12+
13+
See [file-conventions.md](./file-conventions.md) for:
14+
- Project structure and special files
15+
- Route segments (dynamic, catch-all, groups)
16+
- Parallel and intercepting routes
17+
- Middleware rename in v16 (middleware → proxy)
18+
19+
## RSC Boundaries
20+
21+
Detect invalid React Server Component patterns.
22+
23+
See [rsc-boundaries.md](./rsc-boundaries.md) for:
24+
- Async client component detection (invalid)
25+
- Non-serializable props detection
26+
- Server Action exceptions
27+
28+
## Async Patterns
29+
30+
Next.js 15+ async API changes.
31+
32+
See [async-patterns.md](./async-patterns.md) for:
33+
- Async `params` and `searchParams`
34+
- Async `cookies()` and `headers()`
35+
- Migration codemod
36+
37+
## Runtime Selection
38+
39+
See [runtime-selection.md](./runtime-selection.md) for:
40+
- Default to Node.js runtime
41+
- When Edge runtime is appropriate
42+
43+
## Directives
44+
45+
See [directives.md](./directives.md) for:
46+
- `'use client'`, `'use server'` (React)
47+
- `'use cache'` (Next.js)
48+
49+
## Functions
50+
51+
See [functions.md](./functions.md) for:
52+
- Navigation hooks: `useRouter`, `usePathname`, `useSearchParams`, `useParams`
53+
- Server functions: `cookies`, `headers`, `draftMode`, `after`
54+
- Generate functions: `generateStaticParams`, `generateMetadata`
55+
56+
## Error Handling
57+
58+
See [error-handling.md](./error-handling.md) for:
59+
- `error.tsx`, `global-error.tsx`, `not-found.tsx`
60+
- `redirect`, `permanentRedirect`, `notFound`
61+
- `forbidden`, `unauthorized` (auth errors)
62+
- `unstable_rethrow` for catch blocks
63+
64+
## Data Patterns
65+
66+
See [data-patterns.md](./data-patterns.md) for:
67+
- Server Components vs Server Actions vs Route Handlers
68+
- Avoiding data waterfalls (`Promise.all`, Suspense, preload)
69+
- Client component data fetching
70+
71+
## Route Handlers
72+
73+
See [route-handlers.md](./route-handlers.md) for:
74+
- `route.ts` basics
75+
- GET handler conflicts with `page.tsx`
76+
- Environment behavior (no React DOM)
77+
- When to use vs Server Actions
78+
79+
## Metadata & OG Images
80+
81+
See [metadata.md](./metadata.md) for:
82+
- Static and dynamic metadata
83+
- `generateMetadata` function
84+
- OG image generation with `next/og`
85+
- File-based metadata conventions
86+
87+
## Image Optimization
88+
89+
See [image.md](./image.md) for:
90+
- Always use `next/image` over `<img>`
91+
- Remote images configuration
92+
- Responsive `sizes` attribute
93+
- Blur placeholders
94+
- Priority loading for LCP
95+
96+
## Font Optimization
97+
98+
See [font.md](./font.md) for:
99+
- `next/font` setup
100+
- Google Fonts, local fonts
101+
- Tailwind CSS integration
102+
- Preloading subsets
103+
104+
## Bundling
105+
106+
See [bundling.md](./bundling.md) for:
107+
- Server-incompatible packages
108+
- CSS imports (not link tags)
109+
- Polyfills (already included)
110+
- ESM/CommonJS issues
111+
- Bundle analysis
112+
113+
## Scripts
114+
115+
See [scripts.md](./scripts.md) for:
116+
- `next/script` vs native script tags
117+
- Inline scripts need `id`
118+
- Loading strategies
119+
- Google Analytics with `@next/third-parties`
120+
121+
## Hydration Errors
122+
123+
See [hydration-error.md](./hydration-error.md) for:
124+
- Common causes (browser APIs, dates, invalid HTML)
125+
- Debugging with error overlay
126+
- Fixes for each cause
127+
128+
## Suspense Boundaries
129+
130+
See [suspense-boundaries.md](./suspense-boundaries.md) for:
131+
- CSR bailout with `useSearchParams` and `usePathname`
132+
- Which hooks require Suspense boundaries
133+
134+
## Parallel & Intercepting Routes
135+
136+
See [parallel-routes.md](./parallel-routes.md) for:
137+
- Modal patterns with `@slot` and `(.)` interceptors
138+
- `default.tsx` for fallbacks
139+
- Closing modals correctly with `router.back()`
140+
141+
## Self-Hosting
142+
143+
See [self-hosting.md](./self-hosting.md) for:
144+
- `output: 'standalone'` for Docker
145+
- Cache handlers for multi-instance ISR
146+
- What works vs needs extra setup
147+
148+
## Debug Tricks
149+
150+
See [debug-tricks.md](./debug-tricks.md) for:
151+
- MCP endpoint for AI-assisted debugging
152+
- Rebuild specific routes with `--debug-build-paths`
153+
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Async Patterns
2+
3+
In Next.js 15+, `params`, `searchParams`, `cookies()`, and `headers()` are asynchronous.
4+
5+
## Async Params and SearchParams
6+
7+
Always type them as `Promise<...>` and await them.
8+
9+
### Pages and Layouts
10+
11+
```tsx
12+
type Props = { params: Promise<{ slug: string }> }
13+
14+
export default async function Page({ params }: Props) {
15+
const { slug } = await params
16+
}
17+
```
18+
19+
### Route Handlers
20+
21+
```tsx
22+
export async function GET(
23+
request: Request,
24+
{ params }: { params: Promise<{ id: string }> }
25+
) {
26+
const { id } = await params
27+
}
28+
```
29+
30+
### SearchParams
31+
32+
```tsx
33+
type Props = {
34+
params: Promise<{ slug: string }>
35+
searchParams: Promise<{ query?: string }>
36+
}
37+
38+
export default async function Page({ params, searchParams }: Props) {
39+
const { slug } = await params
40+
const { query } = await searchParams
41+
}
42+
```
43+
44+
### Synchronous Components
45+
46+
Use `React.use()` for non-async components:
47+
48+
```tsx
49+
import { use } from 'react'
50+
51+
type Props = { params: Promise<{ slug: string }> }
52+
53+
export default function Page({ params }: Props) {
54+
const { slug } = use(params)
55+
}
56+
```
57+
58+
### generateMetadata
59+
60+
```tsx
61+
type Props = { params: Promise<{ slug: string }> }
62+
63+
export async function generateMetadata({ params }: Props): Promise<Metadata> {
64+
const { slug } = await params
65+
return { title: slug }
66+
}
67+
```
68+
69+
## Async Cookies and Headers
70+
71+
```tsx
72+
import { cookies, headers } from 'next/headers'
73+
74+
export default async function Page() {
75+
const cookieStore = await cookies()
76+
const headersList = await headers()
77+
78+
const theme = cookieStore.get('theme')
79+
const userAgent = headersList.get('user-agent')
80+
}
81+
```
82+
83+
## Migration Codemod
84+
85+
```bash
86+
npx @next/codemod@latest next-async-request-api .
87+
```

0 commit comments

Comments
 (0)