You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Smart Stubble-to-Biomass Matching Marketplace
Team ResidueLink | Smart India Hackathon (SIH) 2026
Overview
This document covers the server-side architecture of ResidueLink: the FastAPI backend/API layer, the database schema (with MySQL and Supabase/PostgreSQL as alternative options — final choice pending), and the .NET-based authentication layer. It complements the frontend README, which covers the React.js client.
Tech Stack
Layer
Technology
Backend / API
Python — FastAPI
Authentication
.NET (ASP.NET Core) — separate auth service issuing tokens consumed by FastAPI
Database
MySQL or Supabase (PostgreSQL) — undecided, both covered below
ML / Prediction
Scikit-learn, Pandas, NumPy (regression models for harvest-date prediction)
External APIs
Open-Meteo / OpenWeatherMap (agro-climatic weather data), Distance Matrix API (geolocation/routing)
The .NET service owns identity (signup/login/token issuance); FastAPI owns all business logic and validates the JWTs issued by .NET on every request. Both services share the same database (or the .NET service owns only the users/auth-related tables while FastAPI owns the rest — see Authentication Layer for details).
POINT/DECIMAL lat-lng pairs, or MySQL spatial extensions
can use PostGIS extension for true geospatial queries
Auth integration
Managed separately (this project's .NET service) or via phpMyAdmin-hosted instance
Supabase has built-in Auth — if chosen, may reduce/replace some .NET auth responsibilities, but current plan keeps .NET as the auth layer regardless
Realtime features
None built-in — needs polling or a message broker for notifications/matching alerts
Supabase Realtime can push DB changes directly (useful for live notifications, baler status, incoming offers)
Hosting
phpMyAdmin-managed instance per current stack notes
Supabase-managed Postgres, integrates well with Render/Vercel deployment
Decision pending — the schema above is written to be portable between both; ENUM columns and JSON fields are the only points needing adjustment for PostgreSQL's stricter typing (Postgres ENUM types or CHECK constraints instead of MySQL's inline ENUM).
Authentication Layer (.NET)
The authentication layer is a separate ASP.NET Core service responsible for identity, credential management, and token issuance. FastAPI does not manage passwords or sessions directly — it only validates tokens issued by this service.
General Auth Flow
Registration — user (farmer/buyer/CHC official) signs up via phone number and/or email through the frontend, which calls the .NET auth service. Role is captured at signup.
Verification — OTP verification (recommended for farmers, given phone-first usage) or email verification link.
Login — credentials (phone+OTP, or email+password) are validated by the .NET service.
Token issuance — on successful login, the .NET service issues:
an access token (short-lived, contains user ID, role, and expiry as claims)
a refresh token (longer-lived, used to obtain new access tokens without re-login)
Token usage — the frontend attaches the access token to every request to the FastAPI backend via the Authorization: Bearer <token> header.
Token validation — FastAPI validates the token's signature and expiry on each request (using a shared signing key or the .NET service's public key/JWKS endpoint) and extracts the user's identity and role for authorization checks — without needing to call the .NET service on every request.
Refresh — when the access token expires, the frontend calls the .NET service's refresh endpoint with the refresh token to obtain a new access token.
Logout / revocation — refresh tokens are invalidated server-side on logout; the .NET service maintains a revocation list or short refresh-token lifetimes to limit exposure.
Role-Based Authorization
Each issued token carries a role claim (farmer, buyer, chc_official, admin).
FastAPI route dependencies check this claim to restrict access — e.g., only chc_official tokens can call baler-status-update or analytics endpoints; only farmer tokens can create farm/listing records for themselves.
The user_id claim ties every action back to the corresponding row in the users table (and its role-specific profile table) for data ownership checks.
Why a Separate .NET Service
Keeps identity/credential management isolated from core business logic — the FastAPI backend never touches raw passwords.
Allows the auth service to evolve independently (e.g., adding OAuth/social login, multi-factor auth) without changing the FastAPI API surface, as long as the token contract (claims format, signing method) stays stable.
The two services can share the same underlying database (users and related auth tables owned by .NET, business tables owned by FastAPI) or use separate databases, depending on final infrastructure decisions.
Open Decisions (flagged for later)
Exact .NET auth mechanism (ASP.NET Core Identity, custom JWT issuance, or a hybrid with OTP) — not yet finalized.
Whether the auth service and FastAPI backend share one database or communicate purely via token claims with fully separate stores.
Whether Supabase's built-in Auth is used alongside or instead of parts of the .NET layer, if Supabase is the final database choice.
Security Notes
All inter-service calls (frontend ↔ .NET, frontend ↔ FastAPI) should be over HTTPS.
Access tokens should be short-lived (e.g., 15–30 min); refresh tokens stored securely (httpOnly cookies preferred over local storage).
Role checks must be enforced server-side in FastAPI, never trusted from the frontend alone.
Sensitive fields (phone numbers, location data) should be access-controlled — e.g., a buyer only sees a farmer's contact details after a match is accepted.
Rate-limit OTP requests and login attempts to prevent abuse.