How formesean/sproutspot works
Project Type & Purpose
• This is a full-stack web application (Next.js + React) that provides an AI-powered digital-twin playground for farms. Users upload CSV data, view an actual farm grid, run “what-if” simulations, and receive AI-driven crop predictions and insights.
File-Structure Analysis
• src/app/: Next.js app directory (React pages, layouts, server/app-route APIs).
• src/app/api/: NextAuth and tRPC server routes under Next.js API (route.ts files).
• src/server/: Shared server code (tRPC router definitions, auth config, Prisma DB connection).
• prisma/: Schema for database models.
• public/: Static assets (videos, images).
• components.json, src/components/: Shared UI components (shadcn/ui, MagicUI).
• start-database.sh, .env.example: Local/dev database bootstrap.
README Insights
• Frontend: Next.js + TypeScript + Tailwind + shadcn/ui.
• Backend: NextAuth.js (auth), tRPC (typed RPC), Prisma ORM, Supabase (PostgreSQL)
• AI/ML: Gemini 2.0 Flash external service for predictions.
• Workflows: CSV upload → store in DB → duplicate for simulation → run ML inference → present in UI.
Main Components
a. User & Browser: The farmer’s web client.
b. Next.js Frontend:
• Pages & React components under src/app (Landing, Farm grid, Experimental playground, FAQ, etc.)
• Static assets in /public
• UI layer calling tRPC & REST endpoints.
c. API Layer:
• NextAuth.js (JWT/session management)
• tRPC router (src/server/api/routers/*) exposed via Next.js API routes (src/app/api/trpc)
d. Business Logic / Services:
• CSV parser & duplication logic (server-side code in TRPC resolvers)
• Simulation engine invoking ML models
• AI/ML service (external Gemini 2.0 Flash endpoint)
e. Database:
• Supabase/PostgreSQL accessed via Prisma client (src/server/db.ts)
• Tables: Users, Farms, GridItems, Playgrounds, Experiments, etc.
f. External Services:
• Supabase Auth (optional)
• Gemini 2.0 Flash for AI inference
• (Optional) Cloud storage for media (if used)
Relationships & Data Flow
• Browser → Next.js Frontend (HTTP/WS)
• Frontend → NextAuth endpoints (login/signup) → Issues session token
• Frontend → tRPC client → tRPC server/router → Business logic → Prisma → Database
• Business logic → calls out to Gemini AI API → receives predictions → writes back to DB or returns to client
• Frontend reads simulation results via tRPC and renders interactive grid/visualizations
Architectural Patterns & Principles
• Layered Architecture: UI → API layer → Business logic → Data layer
• Server-Side Rendering for initial pages (Next.js app directory) and API routes for dynamic calls
• Typed contracts end-to-end via tRPC
• ORM Abstraction via Prisma
• Modular UI with shadcn/ui and MagicUI components
• Separation of Concerns: authentication, data access, ML integration, UI