How kapilbhadu0017/testrepo works
Project Type and Purpose
• This is a modern full-stack web application (“VayuCheck+”) that • monitors real-time air quality data, • stores it in MongoDB, and • uses Google Gemini AI to generate personalized health advice.
• The frontend (React + Vite + Tailwind + Leaflet) provides a UI and map visualization. The backend (FastAPI) exposes REST endpoints for data retrieval, AI suggestions, and map services. External APIs (WAQI, AirNow) and Google Gemini AI are key data sources.
File-Structure Analysis
• Top level:
• frontend/ – React app
• backend/ – FastAPI app + scripts
• README.md, package.json (root) – orchestrate install/run scripts
• Frontend:
• src/components – UI widgets (Map, Charts, Forms)
• config/api.js – base URL/endpoints
• public/index.html + Vite config – build/runtime
• Backend:
• app/routes – three route modules: aqi.py (air quality index), map.py (geodata), suggest.py (AI health advice)
• app/models/schemas.py – Pydantic schemas
• app/utils/db_utils.py – MongoDB helpers
• clear_data.py – optional data cleanup
• env.example – env var template (GEMINI_API_KEY, WAQI_TOKEN, AIRNOW_API_KEY, MONGODB_URL)
Extracted Architectural Patterns
• Layered architecture:
• Presentation (React SPA)
• API layer (FastAPI routes)
• Business logic (utils + AI integration)
• Persistence (MongoDB)
• Single-page-app communicates via REST to backend.
• No microservices: monolithic backend.
Main Components
a. Frontend (React + Vite)
– UI components: Home, HealthForm, DataCharts, Map, Sidebar, Navbar, LoadingSpinner, ErrorBoundary.
– Configuration: src/config/api.js points to FastAPI endpoints.
b. Backend (FastAPI)
– Route Modules:
• /aqi → fetch AQI from WAQI/AirNow, store/fetch in MongoDB
• /map → geospatial data for Leaflet
• /suggest → call Google Gemini AI with AQI + user data
– Models/Schemas: Pydantic for request/response validation
– Utilities: MongoDB connection & helpers
c. Database (MongoDB Atlas)
– Collections: air_quality_readings, user_suggestions (example tables)
d. External Services
– WAQI API
– AirNow API
– Google Gemini AI
e. Developer Scripts & Tools
– clear_data.py (data cleanup)
– npm run dev (concurrently launches Vite and Uvicorn)
Relationships & Data Flow
1. User interacts with React UI → submits a location/health form.
2. Frontend issues REST call to FastAPI /aqi endpoint.
3. Backend fetches AQI data from WAQI/AirNow → optionally cache/save in MongoDB → returns JSON to UI.
4. Frontend displays map/charts via Leaflet and DataCharts.
5. When user requests health advice, frontend calls /suggest.
6. Backend aggregates latest AQI + user data → sends payload to Google Gemini AI → receives suggestion → stores/retrieves in MongoDB → returns to UI.
Architectural Patterns & Principles
• Separation of concerns: UI vs API vs Data persistence vs AI integration
• Single responsibility: each route focuses on one external service or AI action
• Asynchronous I/O in FastAPI for low-latency external calls
• Stateless REST API – easy to horizontally scale
Detail
• .env configuration feeding into backend at startup.
• Developer workflow: “npm run dev” → concurrently starts Uvicorn and Vite dev server.