How 0x5h31d0n/agriscrow-ton works
Project Type and Purpose
• Agriscrow is a full-stack, blockchain-powered agricultural marketplace.
• It connects four user roles (Farmers, Buyers, Landlords, Renters) via a React/TypeScript frontend, a Flask backend with SQLite, and smart contracts on the TON blockchain.
File Structure
• Top-level:
• Frontend/ – React (Vite + Tailwind) code, with components organized by feature (auth, community, marketplace, equipment, dashboard, wallet).
• backend/ – Flask app (app.py), CORS, SQLite storage, file uploads.
• contracts/ – Tact / TON smart contracts (auth.fc, escrow folder).
• Config: ESLint, Tailwind, Vite, Flask requirements.
• Persistence: backend/users.db, backend/uploads/.
• CI / scripts: none; deployment via Vite build & Flask + Gunicorn.
README for Insights
• Confirms architecture: React frontend ↔ Flask API ↔ SQLite + file storage + TON blockchain.
• Highlights: smart-contract escrow, wallet integration (TON Connect), multi-user roles, real-time updates.
a. Main Components
• Clients (Web browser, Mobile browser)
• Frontend SPA (React + Vite + Tailwind)
• Wallet Integration (TON Connect client library)
• Backend API (Flask + Flask-CORS)
• Database (SQLite)
• File Storage (uploads directory)
• Smart Contracts (Tact contracts deployed on TON network)
• External Services (TON Blockchain network, TON Sandbox/Testnet)
• Optional: Real-time layer (if using web sockets or polling)
b. Relationships & Data Flows
1. User interacts with Frontend SPA.
2. SPA calls REST endpoints on Flask API for auth, product listings, community posts, rentals.
3. Flask API reads/writes SQLite and serves uploaded files.
4. For payments/rentals: SPA invokes TON Connect → signs transaction → interacts directly with TON smart contracts.
5. Optional: Flask API may trigger off-chain events based on smart contract state (webhooks or polling).
6. Community and marketplace updates propagate via API → SPA.
c. Architectural Patterns
• Client-Server separation (SPA + REST API)
• Modular frontend by feature (Component-per-domain)
• Monolithic backend (single Flask app)
• Smart-contract layer decoupled from backend (on-chain escrow)
• FCFS order handling in smart contracts
• Single-source-of-truth on-chain for transactions; SQLite for off-chain data
d. Key Technologies
• Frontend: React 18, TypeScript, Vite, Tailwind CSS, TON Connect SDK
• Backend: Flask, Flask-CORS, SQLite, Werkzeug
• Smart Contracts: Tact, TON Core SDK, TON Blockchain
• Dev/Deployment: Node.js, Python 3.8+, Gunicorn/nginx for production