How hoanjen/coinflip works
Main Components
• Frontend: A React.js interface that allows users to place bets and view results.
• Backend: A Node.js/Express API, containing controllers, routes, services, middleware, and models managing business logic, authentication, betting transactions, and database interactions.
• Smart Contract: Written in Solidity, this module (with Hardhat configuration, scripts, and tests) manages on-chain betting, randomness, and result validation.
• External Services/Infrastructure:
• The blockchain network (e.g., Ethereum or an EVM-compatible chain) where the smart contract is deployed.
• MongoDB as a database for storing user data, betting history, and transaction logs.
• Possibly an external blockchain node (like Ganache during development or a live RPC URL).
Analyzing the File Structure
• Backend:
• Organized in clear folders like controllers (handling requests), routes (defining API endpoints), services (business logic), models (data schema and plugins), middleware (authentication, error-handling, validation), and utilities.
• Configuration files (config.ts, database.ts, logger.ts, morgan.ts) indicate that logging, database connectivity, and middleware setup are key components.
• SmartContract:
• Contains Solidity contracts, Hardhat’s configuration (hardhat.config.ts), deployment scripts (deploy.ts, verify.ts), and test scripts ensuring correctness.
• Frontend:
• Although details aren’t fully listed, based on the README and naming conventions, it likely uses React components, API service integration, and state management for immediate display and user interaction.
• Backend as the central business logic layer with:
• Controllers and routes receiving incoming requests.
• Services processing the logic (including authentication and betting transactions) and interacting with the database.
• Middleware handling error processing and validation.
• Smart Contract as an independent yet connected component; the backend interacts with the blockchain by making transactions that call the deployed smart contract methods.
• An “External Blockchain Network” component (or similar) to denote the environment where the Smart Contract is deployed.
• A configuration or logging service indicator representing how logs (all.log/error.log) are managed.
Key Architectural Patterns & Technologies to Emphasize
• Separation of Concerns: Clearly segregate the concerns of user interface (Frontend), business logic & data management (Backend), and on-chain processing (Smart Contract).
• Use of API layering: The Backend acts as the mediator between the Frontend and Smart Contract.
• Modular design in the Backend where every layer (controllers, services, models) is separated for maintainability and scalability.
• Deployment and testing of Smart Contracts using Hardhat.
• Technologies include Node.js/Express, MongoDB, React.js, Solidity, Hardhat, and possibly blockchain nodes like Ganache.