A Next.js application for the Hack4Change hackathon with trash mapping and AI-powered analysis capabilities.
- Interactive Trash Map: View trash locations on an interactive map using MapLibre GL JS
- AI-Powered Analysis: Generate insights about trash distribution patterns using OpenAI
- Real-time Data: Fetch trash location data from GraphQL API
- Responsive Design: Modern UI built with Tailwind CSS
- Install dependencies:
npm install
# or
yarn install- Set up environment variables:
Create a
.env.localfile in the root directory with:
OPENAI_API_KEY=your_openai_api_key_here
- Get your OpenAI API key:
- Visit OpenAI Platform
- Create a new API key
- Add it to your
.env.localfile
- Run the development server:
npm run dev
# or
yarn dev- Open http://localhost:3000 in your browser
The application includes a complex operation that:
- Fetches trash data from the GraphQL API (
thrashmapquery) - Pipes the data to OpenAI's GPT-4 model
- Generates insights about trash distribution patterns
- Provides recommendations for environmental improvement
- The
TrashAnalysiscomponent fetches trash location data - Data is sent to the
/api/analyze-trashendpoint - The endpoint uses OpenAI's API to analyze the trash points
- Results include thoughts, insights, recommendations, and environmental impact assessment
POST /api/analyze-trash- Analyzes trash points using OpenAI
ThrashMap- Interactive map displaying trash locationsTrashAnalysis- AI-powered analysis interfaceOpenAIService- Service for OpenAI API integration
- Next.js 14 - React framework
- TypeScript - Type safety
- Tailwind CSS - Styling
- Apollo Client - GraphQL client
- MapLibre GL JS - Interactive maps
- OpenAI API - AI analysis
- GraphQL - Data fetching
src/
├── api/
│ ├── openai/
│ │ └── openai.service.ts # OpenAI integration
│ └── __generated__/ # GraphQL generated types
├── components/
│ └── widgets/
│ ├── ThrashMap.tsx # Interactive map component
│ └── TrashAnalysis.tsx # AI analysis component
└── ...
npm run dev- Start development servernpm run build- Build for productionnpm run start- Start production servernpm run generate- Generate GraphQL types