xiaohongshu
xiaohongshu
hono-ipc-setup
Set up Hono-based type-safe IPC architecture for Electron applications. Use when implementing IPC communication, creating routes between main and renderer processes, or migrating from traditional ipcRenderer to type-safe RPC.
Full skill instructions
This skill provides comprehensive knowledge for setting up type-safe IPC communication in Electron applications using Hono RPC.
ipcRenderer.invoke / ipcMain.handle to Honopnpm add hono @hono/zod-validator zod
src/
├── shared/
│ └── callable/
│ ├── index.ts # Factory and app creation
│ └── types.d.ts # Type export for client
├── main/
│ └── callable/
│ └── index.ts # Service injection
└── renderer/
└── src/
└── adapters/
└── client.ts # Type-safe hc client
See SHARED-DIRECTORY.md for why the shared/ architecture prevents dependency leakage. See FACTORY-PATTERN.md for complete factory implementation. See REFERENCE.md for Hono RPC API reference.
┌─────────────────────────────────────────────────────────────┐
│ RENDERER PROCESS │
│ │
│ React/Vue/etc Component │
│ │ │
│ ▼ │
│ client.users[':id'].$get({ param: { id: 'xxx' } }) │
│ │ │
│ ▼ │
│ hc<CallableType> with custom fetch │
│ │ │
│ ▼ │
│ ipcRenderer.invoke('hono-rpc-electron', url, method, ...) │
└──────────────────────────────────────────────────────────────┘
│
▼
┌──────────────────────────────────────────────────────────────┐
│ MAIN PROCESS │
│ │
│ ipcMain.handle('hono-rpc-electron', handler) │
│ │ │
│ ▼ │
│ callable.request(url, { method, headers, body }) │
│ │ │
│ ▼ │
│ Hono Router │
│ │ │
│ ▼ │
│ Route Handler: (c) => c.var.services.xxx.method() │
│ │ │
│ ▼ │
│ Service Layer (injected via DI) │
└───────────────────────────────────────────────────────────────┘
The key to type safety is the CallableType:
// src/shared/callable/types.d.ts
import type { createApp } from '.';
export type CallableType = ReturnType<typeof createApp>;
// src/renderer/src/adapters/client.ts
import type { CallableType } from '@shared/callable/types';
export const client = hc<CallableType>('http://internal.localhost', { ... });
// Now client has full autocomplete:
// client.users.$get() - GET /users
// client.users[':id'].$get() - GET /users/:id
// client.auth.sign_in.$post() - POST /auth/sign_in
| Aspect | Traditional IPC | Hono IPC |
|---|---|---|
| Type Safety | Manual typing | Full inference |
| API Design | Ad-hoc channels | RESTful routes |
| Validation | Manual | Zod middleware |
| Testing | Mock IPC | Standard HTTP |
| Error Handling | Per-handler | Centralized |
| Scalability | One channel each | Single channel |
import { zValidator } from '@hono/zod-validator';
import { z } from 'zod';
const CreateUserBody = z.object({
name: z.string().min(1),
email: z.string().email(),
});
.post('/users', zValidator('json', CreateUserBody), (c) => {
const body = c.req.valid('json'); // Fully typed
return c.json(body, 201);
})
.get('/users/:id', (c) => {
const id = c.req.param('id');
return c.var.services.users.get(id).then(user => c.json(user));
})
const QueryParams = z.object({
limit: z.coerce.number().default(10),
offset: z.coerce.number().default(0),
});
.get('/users', zValidator('query', QueryParams), (c) => {
const { limit, offset } = c.req.valid('query');
return c.var.services.users.list({ limit, offset });
})
Only JSON-serializable data can be sent through IPC:
Supported:
dayjs on receive)Not Supported (need manual conversion):
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience