How jackpham1510/hfcyt works
Project type and purpose
• This is a full-stack, real-time web application called “How Fast Can You Type?”
• The backend is built with Node.js and Express and uses Socket.io for real-time bidirectional communication.
• The frontend is a React single-page app (SPA) using Element-UI for styling.
File structure
• Top-level
• index.js – server entry point
• lib.js – shared business-logic/functions (e.g., typing-speed calculations, room management)
• package.json/.gitignore – project metadata and excludes
• client/
• package.json – React app metadata
• public/ – static assets (index.html, manifest.json)
• src/ – React components (App.js, Intro.js, service worker, CSS, tests)
• No database directory or config, so state is likely in memory or ephemeral.
Key insights from README
• Run the Node/Express server (index.js) in the root, then run the React dev server in client/
• In production, Express can be configured to serve the React build output from client/build
• Stack: Express (HTTP), Socket.io (WebSockets), React (UI), Element-UI (styles)
Main components
a. Client Layer
• Browser running React SPA
• UI components (App, Intro) styled with Element-UI
• Socket.io client library (in registerServiceWorker or App.js)
b. Server Layer
• Node.js + Express HTTP server (index.js)
• Socket.io server module attached to Express
• lib.js: game logic, typing-speed computation, room/user management
c. Data/State
• In-memory game state (no external DB)
d. External Services
• Deployment host (e.g., Heroku)
• Optional CDN for serving static assets
Relationships and interactions
• React UI emits “key-press” events over WebSocket → Socket.io server
• Server processes events (via lib.js) → calculates WPM, accuracy
• Server broadcasts state updates (“score-update”, “leaderboard”) to all connected clients
• HTTP (Express) serves SPA assets (in production) and/or health-check endpoints
• Browser may fall back to REST endpoints for initial page load
Architectural patterns and design principles
• Separation of concerns:
• UI rendering and state management in React
• Real-time messaging and game logic on the server
• Event-driven architecture with WebSockets
• Single code branch for shared logic in lib.js (if reused on client in future)
Technologies and frameworks to annotate
• React.js, Element-UI
• Node.js, Express.js
• Socket.io (client + server)
• (Heroku) or another PaaS—optional