TerraMind AI - Crop Recommendation Prototype
An academic full-stack crop-recommendation prototype combining a React and TypeScript interface with a Python FastAPI backend. The backend uses scikit-learn to compare submitted soil and climate values against crop records and return the three nearest suggestions.

Overview
I developed TerraMind AI as an academic crop-recommendation project combining a React and TypeScript interface with a Python FastAPI backend. The application collects seven soil and climate values: nitrogen, phosphorus, potassium, temperature, humidity, rainfall and pH, and sends them to a recommendation service. The Python engine standardizes the submitted values and compares them with cleaned crop records using scikit-learn's NearestNeighbors algorithm and Euclidean distance. It returns the three nearest crop suggestions, which the frontend transforms into clear, responsive result cards. This project allowed me to work across interface design, typed request data, API integration, data preprocessing and recommendation logic.
My goal
My goal was to make crop-recommendation data easier to explore through a simple interface. Instead of asking users to interpret a dataset manually, I wanted them to enter familiar soil and climate measurements and receive a small ranked set of understandable crop suggestions.
The problem
Crop suitability depends on several numerical conditions that use different units and ranges. The application needed to collect seven numerical inputs consistently, validate and structure the values before sending them, keep frontend and backend field names aligned, standardize features with different scales before comparison, and return a small and understandable set of results without claiming to replace agricultural expertise.
What I built
I built a React and TypeScript form that collects and validates the seven inputs and sends them as a typed JSON request to a FastAPI backend. The backend receives and validates the request through a Pydantic model, passes the values to the recommendation engine, and returns ranked crop results. The frontend maps the distances into a presentation score and renders the results as responsive cards.
Preparing the crop data
I sourced the data from the Kaggle Crop Recommendation Dataset (atharvaingle/crop-recommendation-dataset) and prepared a cleaned CSV for the Python recommendation workflow. The connected project version used 98 records and seven numerical columns: N, P, K, temperature, humidity, rainfall and pH. Because these values use different numerical ranges, the features were standardized before calculating Euclidean distance.
How TerraMind produces a recommendation
The seven submitted values travel from the React form through a Vite proxy to the FastAPI backend, where Pydantic validates the request before the recommendation engine standardizes the features and finds the three nearest crop records by Euclidean distance.
React and TypeScript
- Responsibility
- Collect the seven values, structure the request and render the returned results.
- Receives
- User-entered soil and climate values.
- Produces
- A typed JSON request and responsive result cards.
Vite proxy
- Responsibility
- Connect the frontend development server to the local Python API.
- Receives
- Requests sent to /api/recommend.
- Produces
- A rewritten request to the backend /recommend route.
FastAPI and Pydantic
- Responsibility
- Expose the recommendation endpoint and validate its input.
- Receives
- Seven numerical fields in JSON.
- Produces
- A structured recommendations response.
StandardScaler
- Responsibility
- Put all seven features onto comparable numerical scales.
- Receives
- Dataset values and the submitted input.
- Produces
- Standardized feature vectors.
NearestNeighbors
- Responsibility
- Find the records closest to the submitted agricultural conditions.
- Receives
- A standardized input vector.
- Produces
- The three nearest records and their Euclidean distances.
Main challenges
- Keeping frontend field names aligned with the Pydantic model
- Connecting port 8080 and port 8001 through a Vite proxy
- Resolving /api/recommend to the backend /recommend endpoint
- Configuring CORS and the Vite proxy correctly during local development
- Standardizing features with different numerical ranges fairly
- Converting raw Euclidean distances into a readable presentation score for the interface
- Managing loading and API-error states in the frontend
- Simplifying the application for academic presentation without breaking the connected workflow
What I learned
Building TerraMind improved my understanding of building typed forms around structured numerical data, connecting a React frontend to a Python API, FastAPI and Pydantic validation, Vite proxy configuration for local full-stack development, pandas data preparation, feature standardization and its effect on distance-based algorithms, nearest-neighbor recommendation logic, translating raw algorithmic output into understandable interface content, and distinguishing Euclidean distance from confidence or probability.
Current status
TerraMind is an academic prototype. During development, I completed and tested the connected workflow between the React interface, Vite proxy and FastAPI recommendation service. The currently available repository snapshot contains the frontend in a standalone demonstration state with local fallback logic, while the connected architecture represents the complete version built and demonstrated during the project. Results were not validated for professional farming decisions. Euclidean distance is not a probability of crop success. Production deployment, monitoring and expert validation remain future work.
