Web Mine Craft
Production-grade Web App software engineering system implemented in TypeScript, JavaScript. Features a decoupled multi-tier architecture with validated API endpoints and resilient state processing.
Technical Architecture & Engineering Overview
Detailed system design and core implementation
The core of the system is a Next.js application that hosts the game at /play. The UI layer uses TailwindCSS for responsive menus, inventory hotbars, and authentication screens, while the 3D world is rendered inside an R3F <Canvas> component. Player input is captured by a custom Player class (see scripts/player.js) which translates keyboard and mouse events into movement vectors, applies sprinting, jumping, and tool animations, and synchronizes camera lock state.
Terrain is generated per‑chunk in a dedicated Web Worker (app/workers/chunkWorker.ts). The worker uses simplex-noise to compute height values for a 16×16 block grid, returning only the top‑layer block positions to keep the main thread lightweight. Generated blocks are batched into an InstancedMesh, dramatically reducing draw calls and enabling near‑Minecraft performance in the browser.
State sharing across the client is handled by Zustand, which stores player position, inventory, and selected toolbar slot. This store is also the source of truth for UI components, allowing instant reactivity without prop‑drilling. For multiplayer, a Colyseus server (Node.js + TypeScript) will host rooms that broadcast player positions and world updates via WebSocket, ensuring delta‑compressed synchronization.
Persistence is achieved through MongoDB Atlas. User accounts, JWT‑based authentication, and saved chunk modifications are managed via Next.js API routes (/api/chunks, /api/auth). Mongoose schemas define the shape of user documents and chunk data, enabling efficient queries and updates. The overall build pipeline deploys the front‑end to Vercel, while the Colyseus server can run on a Node‑compatible platform (e.g., Vercel Serverless Functions or a dedicated VM).
System Diagrams & Flow Visualizations
Interactive Mermaid architecture & execution flows
Core System Features
Key capabilities & architectural features
**React/Next.js** front‑end with server‑side rendering for SEO‑friendly landing pages
**React/Next.js** front‑end with server‑side rendering for SEO‑friendly landing pages
Declarative 3D rendering via `react-three-fiber` and GPU‑efficient `InstancedMesh` block drawing
Declarative 3D rendering via `react-three-fiber` and GPU‑efficient `InstancedMesh` block drawing
Real‑time physics using `@react-three/rapier` for player‑world collision
Real‑time physics using `@react-three/rapier` for player‑world collision
State management with **Zustand** for fast, minimal boilerplate stores
State management with **Zustand** for fast, minimal boilerplate stores
Chunk generation off‑loaded to a **Web Worker** using `simplex-noise`
Chunk generation off‑loaded to a **Web Worker** using `simplex-noise`
Sliding‑window infinite world algorithm that loads/unloads chunks based on player position
Sliding‑window infinite world algorithm that loads/unloads chunks based on player position
User authentication with JWTs and secure Next.js API routes
User authentication with JWTs and secure Next.js API routes
Persistence of user data and modified chunks in **MongoDB Atlas** via **Mongoose**
Persistence of user data and modified chunks in **MongoDB Atlas** via **Mongoose**
Planned multiplayer support using **Colyseus** rooms and delta‑compressed WebSocket sync
Planned multiplayer support using **Colyseus** rooms and delta‑compressed WebSocket sync
Asset loading abstraction (`ModelLoader`) for GLTF models like pickaxes
Asset loading abstraction (`ModelLoader`) for GLTF models like pickaxes
Responsive UI built with **TailwindCSS** including hotbar, health, and crosshair
Responsive UI built with **TailwindCSS** including hotbar, health, and crosshair
Modular game component that can be dynamically imported to avoid SSR conflicts
Modular game component that can be dynamically imported to avoid SSR conflicts
Keyboard and mouse controls supporting movement, sprint, jump, and tool selection
Keyboard and mouse controls supporting movement, sprint, jump, and tool selection
Debug camera mode toggled with `F10` for development inspection
Debug camera mode toggled with `F10` for development inspection
Extensible architecture ready for future features such as volumetric lighting, voice chat, and vehicles
Extensible architecture ready for future features such as volumetric lighting, voice chat, and vehicles
Engineering Challenges & Solutions
Problem statements & resolution strategies
Balancing **GPU load** vs. block count: using `InstancedMesh` reduces draw calls but requires careful management of instance matrices for dynamic block updates.
Balancing **GPU load** vs. block count: using `InstancedMesh` reduces draw calls but requires careful management of instance matrices for dynamic block updates.
Ensuring **smooth chunk generation** without frame drops: off‑loading to Web Workers mitigates main‑thread stalls but introduces message‑passing latency.
Ensuring **smooth chunk generation** without frame drops: off‑loading to Web Workers mitigates main‑thread stalls but introduces message‑passing latency.
Designing a **stateless multiplayer server**: Colyseus handles room state, yet persisting world changes to MongoDB must be synchronized without race conditions.
Designing a **stateless multiplayer server**: Colyseus handles room state, yet persisting world changes to MongoDB must be synchronized without race conditions.
Managing **authentication across HTTP and WebSocket** layers: JWT validation must be performed consistently for API routes and Colyseus connections.
Managing **authentication across HTTP and WebSocket** layers: JWT validation must be performed consistently for API routes and Colyseus connections.
Handling **type safety** between client and server: shared TypeScript interfaces reduce mismatches but require disciplined versioning across the monorepo.
Handling **type safety** between client and server: shared TypeScript interfaces reduce mismatches but require disciplined versioning across the monorepo.
Key Code Modules & Architecture
Core file entrypoints and service responsibilities
minecraft-nextjs/appModule component managing app source logic
minecraft-nextjs/app/componentsModule component managing components source logic
minecraft-nextjs/app/storeModule component managing store source logic
public/modelsModule component managing models source logic
scriptsModule component managing scripts source logic
User Journey Pipeline
- 1User Access & Preset Selection: User opens client interface and configures request parameters or task workflow presets.
- 2Client Payload Dispatch: Front-end components (React, Next.js, TailwindCSS) serialize input objects and send HTTP/WebSocket requests to `/api/analyze`.
- 3Middleware & Validation Check: API Gateway evaluates CORS headers, authorization tokens, and input validation schemas.
- 4Service & Inference Execution: Service controllers dispatch request frames to model inference engine (Local Engine) or storage layer.
- 5Response Delivery & State Synchronization: Serialized output payload is returned to the client and rendered in the visual workspace.
Execution Code Flow
- 1Entrypoint Invocation: Request enters network interface layer via `POST /api/analyze`.
- 2Schema & Guardrail Verification: Middleware sanitizes payload parameters and checks rate-limiting limits.
- 3Controller Dispatch: Router delegates validated object to `App` service controller.
- 4Engine Execution & Storage Operations: Controller executes business logic, queries database models (Persistence), and invokes ML workers.
- 5Response Serialization: Result model is formatted into standard JSON response frame and delivered with HTTP 200 OK.
System FAQ & Technical Specifications
Frequently asked questions and core architecture details
Q: What technologies are used in Web Mine Craft?
Web Mine Craft is engineered using modern full-stack frameworks.
Q: What core engineering problem does Web Mine Craft solve?
Production-grade Web App software engineering system implemented in TypeScript, JavaScript. Features a decoupled multi-tier architecture with validated API endpoints and resilient state processing.
Q: How is 'Balancing **GPU load** vs. block count: using `InstancedMesh` reduces draw calls but requires careful management of instance matrices for dynamic block updates.' resolved in Web Mine Craft?
Resolved through specialized system architecture and resilient state handling.
Related Systems & Case Studies
Explore similar technical architectures and projects