This document provides a comprehensive summary of the structural and architectural changes implemented to evolve GreenGuard from a basic prototype into a robust, community-driven portal.
- Change: Switched from
.insert()to.upsert()for thepublic.profilestable in theregisterendpoint. - Rationale: Prevents a race condition where the Supabase Database Trigger (see below) might create a skeleton profile before the backend finishes, leading to "Duplicate Key" errors.
- Impact: Registration is now idempotent and highly stable.
- File:
backend/src/controllers/auth.controller.js
- Change: Implemented an PostgreSQL Trigger
on_auth_user_createdin theauth.usersschema. - Detail: The function
public.handle_new_user()auto-syncs OAuth metadata (Google/Apple/Facebook) into ourpublic.profilestable. - Safety: Includes logic to skip email/password registrations to avoid conflicts with custom backend flows.
- File:
supabase/auth_trigger_migration.sql
- Change: Added Google, Apple, and Facebook login buttons to the
LoginandRegisterpages. - Detail: Currently set to "Coming Soon" (faded out and disabled) until production API keys are configured in the Supabase Dashboard.
- File:
frontend/src/components/auth/SocialButtons.tsx
- Change: Created a unified design system using CSS variables (
--gg-*). - Design Language: Vibrant primary greens (
#10b981), deep dark mode support, and glassmorphism. - File:
frontend/src/app/globals.css
- Change: Redesigned the registration page with a visual role selector (Plant Adopter vs. NGO).
- Detail: NGOs are automatically routed to a specialized onboarding flow after successful sign-up.
- File:
frontend/src/app/register/page.tsx
- Change: Implemented smooth transitions, hover effects, and a mobile-first dashboard layout.
- File:
frontend/src/components/layout/Navbar.tsx
- Change: Added
utils/response.jsto ensure every API call returns a consistent JSON structure{ success: boolean, data?: any, error?: { code, message } }. - File:
backend/src/utils/response.js
- Change: Enhanced error logging in the
authcontroller to include full stack traces and specific error codes (e.g.,REGISTRATION_CRASH). - File:
backend/src/controllers/auth.controller.js
- Change: Enabled the
postgisextension and added thelocationcolumn (geography type) to theplantstable. - Impact: Enables "Nearby Plants" searches and distance-based filtering on the map.
- File:
supabase/schema.sql(initial setup)
- Change: Created the
ngo_profilestable, linking it toprofileswith anapproved_bycolumn for admin verification. - File:
supabase/schema.sql
- Change: Created a 90-line testing manual covering unit tests, integration paths, and manual QA checklists.
- File:
docs/TESTING_GUIDE.md
- Change: Migrated both the Main API and AI Consultant service to Hugging Face Spaces (Docker containerized).
- Rationale: Provides free, stable, and persistent hosting for production-grade microservices.
- Architecture: Decoupled the AI reasoning engine (Flora Genius) into an independent service to ensure zero-latency bottlenecks for the main application.
- Change: Implemented GitHub Actions for automated deployment.
- Detail: Every push to the
mainbranch triggers a subtree split and push to the respective Hugging Face Spaces. - File:
.github/workflows/deploy-hf.yml
- Change: Integrated the
sharplibrary into the AI service to handle WebP-to-JPEG conversion. - Rationale: Resolves compatibility issues with the PlantNet identification engine which only accepts standard image formats.
- File:
flora-genius-consultant/src/services/plantnet.service.js
- Change: Configured
app.set('trust proxy', 1)in the Express backend. - Rationale: Essential for running behind Hugging Face's load balancer; ensures correct IP tracking and rate-limiting functionality.
- File:
backend/app.js
- Change: Fixed the
deploy-hf.ymlGitHub Action by replacing the invalidgit subtree push --forcesyntax with asplit-and-pushoperation. - Rationale: Subtree push does not support the
--forceflag natively; the new method allows forceful overrides to HF Spaces branches. - File:
.github/workflows/deploy-hf.yml
- State Management: Consider moving from
prop-drillingto a robust Context-based auth provider (seelib/auth.ts). - Infinite Scroll: Implement
IntersectionObserverfor the community feed to handle large volumes of NGO posts.
- Email Service: Replace
email_confirm: truewith a real SMTP service (e.g., Resend or SendGrid) once the domain is ready. - File Storage: Ensure the Supabase Storage Buckets have correct RLS policies for
publicvsprivateplant images. - n8n Integration: Finalize the webhook listener for the AI Leaf Diagnosis feature.
Created by: Students of Vidyalankar Institute of Technology, Mumbai in collaboration with Google's Antigravity Last Updated: 2026-06-19