How derek2403/teetee works
Main Components
• Frontend Application:
• Represented by Next.js pages (e.g., pages/index.js, pages/chat.js, pages/ContributionPool.js) and UI components (found in the components folder).
• Hooks that manage blockchain calls and on-chain operations (e.g., useAIChat, useDepositToPool, etc.).
• Backend API:
• Captured in the pages/api folder (endpoints like /api/host-model.js, /api/models.js, /api/tee-nodes.js, etc.) which handle requests, model verification, and act as gatekeepers between the frontend and other layers.
• Dockerized TEE Nodes:
• The “TeeDockerFiles” directory houses Docker configurations and code for the two applications (app1 and app2) that handle distinct parts of the LLM inference process.
• Blockchain & Smart Contract Layer:
• Although the smart contract source code might not be directly in the file tree, the README clearly explains that on-chain interactions (profit sharing, token transactions, node registration, and attestations) are a core part of the system.
• Base Sepolia smart contract as an external blockchain component that interacts with both the frontend (for token buying, wallet interactions) and backend APIs.
• External Services:
• Phala Network as the TEE hosting platform provider (and on-chain attestation proofs) and any related external URLs (e.g., Phala Cloud, blockchain explorers).
• Additional Supporting Components:
• Tools like Ethers.js for blockchain interactions, Docker for containerization, and smart contract calls provide the integration glue.
Relationships and Data Flows
• The backend API then interfaces with the blockchain by invoking Ethers.js functions and calling smart contract methods for registration and profit sharing.
• Within the TEE layer:
• TEE Node 1 (from TeeDockerFiles/app1) receives user requests (via a user-facing endpoint such as /generate at port 5002) and processes input.
• It then forwards processed tensor data over to TEE Node 2 (from TeeDockerFiles/app2, typically at port 5001) for final output generation.
• On-chain attestation paths:
• That both TEE nodes generate attestation reports which are sent back through TEE 1 to the user, and these reports are also verified against the smart contract.
• For the self-hosting user flow:
• For token-based usage:
• Purchase of tokens (using wallet integrations such as RainbowKit) that are then used to generate queries via the API.
Architectural Patterns and Technologies
• Separation of Concerns:
• Clearly segregate frontend, backend, TEE container logic, and blockchain components.
• Microservices / Containerization:
• Use Docker container symbols for TEE nodes, showing that each service is isolated.
• Decentralized and Fault-Tolerant Design:
• As indicated in the README, highlight the dual flows (normal user vs. self-hosting) and represent the fail-over paths (e.g., multiple TEE nodes in future horizontal scalability).