How krnl-labs/my-krnl-app works
Project type and purpose
• This is a Next.js-based single-page application (SPA) with React 18+ and the App Router.
• It bundles on-chain logic (“kernels”) under src/components/kernels/onchain and an Ethereum smart contract ABI in src/mainContract/abi.json.
• In effect it’s a front-end dApp: a component-based UI that interacts with an Ethereum (or EVM-compatible) network via JSON-RPC, using environment-supplied endpoints and contract addresses.
File structure
• Top-level config:
– .env / .env.example: RPC URL, contract address, API keys
– next.config.ts, postcss.config.mjs, eslint.config.mjs, tsconfig.json
• Application code under src/:
– app/: Next.js pages (layout.tsx, page.tsx), global CSS
– components/: reusable UI pieces
– components/kernels/onchain/<chainId>/: per-chain on-chain logic (each has config.ts and index.ts)
• src/mainContract/abi.json: the ABI for interacting with a deployed smart contract
• public/: static assets served at runtime
Extracting insights from README
• Bootstrapped with Create-Next-App, uses next/font for optimized fonts.
• No backend folder or API routes—logic runs client-side or via Next.js server (SSR/SSG).
• Deployment target is Vercel (serverless), but could be any Next.js host.
Main components
a. User’s Browser (Client) – React SPA served by Next.js
b. Next.js Server / Build (SSG/SSR/runtime)
c. Static Asset Store (public/, CSS, fonts)
d. On-chain Kernels (dynamic modules under components/kernels/onchain)
e. Smart Contract ABI Module (src/mainContract/abi.json)
f. JSON-RPC Provider / Ethereum Network (external service)
g. Environment Variables Store (.env)
h. Deployment Platform (Vercel or equivalent)
Relationships and data flow
• Client → Next.js Server: initial HTML + JS bundle request
• Next.js Server → Static Store: fetch CSS, images, fonts
• Client/Server → On-chain Kernel: at runtime the SPA loads the appropriate kernel module (based on chainId)
• Kernel & ABI Module → JSON-RPC provider endpoint (ENV.RPC_URL): sends read/write calls to the smart contract
• Ethereum Network → Response → Kernel → React State → UI update
• Environment variables injected at build/runtime into Next.js via next.config.ts
Architectural patterns & design principles
• Component-based UI (React)
• Dynamic module loading for pluggable on-chain kernels
• Separation of concerns: UI vs. chain integration vs. contract spec
• SSR/SSG for performance, CSR for interactivity
• 12-factor principle: config via environment variables
Final checklist for the engineer
• Break the system into at least these layers:
– Client (browser)
– Next.js (SSG/SSR + CSR)
– UI Components & Kernels
– Smart Contract Interface
– Blockchain Network
• Hosting/deployment (Vercel) and environment management.
• Keep it uncluttered: group similar components, label connectors, and use consistent styling.