How amanaakash/carbon-track works
Project Type and Purpose
• CarbonTrack is a full-stack web application built with Next.js (App Router), React, and TypeScript.
• Purpose: provide real-time air quality monitoring, historical data visualization, and AI-powered carbon reduction recommendations.
File Structure Analysis
• Top level
• package.json, next.config.ts, tsconfig.json, tailwind.config.ts, postcss.config.mjs – build & config
• src/
– app/ – Next.js App Router (layout.tsx, page.tsx, global CSS)
– components/ – reusable UI components (shadcn/ui Button, Card, Input)
– lib/ – utility functions, API wrappers (utils.ts)
• No dedicated “api” folder; data fetching occurs in server components or client components using fetch.
• No database folder: all data is fetched at runtime from external services.
README Insights
• External APIs:
• Open-Meteo Air Quality for pollutant data
• OpenStreetMap Nominatim for geocoding
• OpenRouter AI for GPT-powered insights
• Architecture patterns: server components (Next.js), client components, utility layer, static assets, environment variables.
Main Components
a. Client Layer
– Web Browser (user interface)
– Next.js client-side bundles (React components, CSS, charts)
b. Server Layer
– Next.js server (App Router) handling SSR/SSG and server components
– Utility module (src/lib/utils.ts) encapsulating fetch logic
c. External Services
– Air Quality API (Open-Meteo)
– Geocoding API (OpenStreetMap Nominatim)
– AI Recommendations API (OpenRouter → OpenAI GPT)
d. Static Assets & Build
– CDN or Vercel/Netlify hosting static assets (public/)
– Build pipeline (Turbopack) for dev & production
Relationships and Data Flow
• User enters a city in the UI → browser sends event to React component → component invokes Next.js fetch (in server/client component)
• Next.js server handles data requests:
• calls Geocoding API → gets coordinates
• calls Air Quality API → retrieves pollutant data
• optionally calls AI API → gets recommendations
• Next.js composes response (JSON + HTML) → sends to browser
• Browser renders charts (Recharts) and UI components (shadcn/ui)
• For subsequent interactions, client-side fetches may bypass SSR for faster updates
Architectural Patterns and Principles
• Single Page Application with hybrid SSR/CSR (Next.js App Router)
• Separation of concerns:
• UI layer (components/)
• Data layer (lib/utils.ts)
• Style layer (Tailwind CSS, globals.css)
• External service abstraction for maintainability
• No in-house database: relies on real-time APIs