How heavyrisem/hostrix works
Project type and purpose
• Hostrix is a desktop application built with Electron (main + preload) and a React/TypeScript/Vite renderer.
• Its core purpose is to provide host‐file and ping utilities via a modern UI that communicates with OS resources through Electron IPC.
File structure
● Top‐level “electron” folder
• main.ts – Electron main process entry point
• preload.js – Exposes a typed window.ipc bridge to renderer
• modules/… – A set of IPC modules (hosts, ping) each exporting invoke‐able methods
• libs/… – Lower‐level host‐file reader/writer utilities used by modules
● Top‐level “src” folder (the renderer)
• app/… – React entrypoint, global providers (React Query client, routing)
• features/… – Feature slices (hosts, home) with API wrappers, query keys, hooks
• entities/… – Reusable data access/query logic (e.g., sections)
• pages/… / routes/… / widgets/… – UI components, pages, sidebars, route definitions
• shared/… – Utility functions, type definitions for IPC
● Configuration
• pnpm-workspace.yaml, tsconfig.json, vite.config.ts – Monorepo, TS, and bundler config
README for additional insights
• Electron modules must be registered in electron/modules/index.ts.
• Renderer uses React Query to call window.ipc.invoke(…) for each module method.
• Types flow from electron/modules into src/vite-env.d.ts and shared/types, ensuring compile‐time safety.
1. Renderer/UI Layer (React + Vite)
• React Tree (pages, widgets, features)
• React Query Client & Hooks
2. Preload Script
• Exposes window.ipc.invoke API surface
3. Main Process / IPC Router
• IPC registration (electron/modules/index.ts)
4. IPC Modules
• hosts module (reader, writer, constants, utils)
• ping module
5. Underlying Libraries / OS Access
• File System (hosts file read/write)
• Network (ICMP ping)
6. Data Store (if applicable) – in this case the local hosts file on disk
• User clicks UI → React component calls React Query hook → React Query issues window.ipc.invoke("moduleName", params)
• Preload.js receives invoke → forwards to main process IPC handler → dispatches to the appropriate module function
• Module function calls into libs (FS or network) → returns result back up
• Main process returns result via IPC → Preload → Promise resolves in React Query → UI updates
c. Architectural patterns and design principles
• Clear separation of concerns: UI vs. IPC vs. OS logic
• Monorepo workspace sharing types and code (shared/types)
• Module‐based IPC “microservices” that are auto‐registered
• React Query as an abstraction over IPC calls for caching, error handling, automatic refetch
d. Key technologies and frameworks
• Electron (main, preload, IPC)
• React + TypeScript + Vite
• React Query
• pnpm workspaces
• Node.js FS & network (ping) APIs