How psw3137/nutritrend-dashboard works
1. What this repository is
- This is a Next.js App Router dashboard for nutrition search and trend analysis.
- The runtime is split into a client-side UI layer and a small server-side API layer under app/api.
- The codebase is currently centered on the dashboard experience plus data-fetching/analysis endpoints; the README also describes a Python crawler and email delivery workflow, but the checked-in tree mainly shows the web app and API surface.
2. Top-level app structure
- app/layout.tsx and app/globals.css provide the global shell and styling.
- app/(dashboard)/layout.tsx wraps the dashboard section, while the visible pages are:
- app/(dashboard)/page.tsx — dashboard landing
- app/(dashboard)/nutrition/page.tsx — nutrition comparison/visualization view
- app/(dashboard)/trends/page.tsx — news/trend analysis view
- This routing layout suggests a single app with multiple feature pages, not separate services.
3. Server boundary: API routes
- app/api/food/search/route.ts is the backend entry point for food lookup against the external food nutrition database.
- app/api/news/search/route.ts likely serves news retrieval/search for the trends feature.
- app/api/trends/analyze/route.ts is the AI analysis endpoint, likely aggregating news and sending it to Claude for summarization or trend extraction.
- These routes are the main boundary between the UI and external systems.
4. External integrations
- The app depends on the Food Safety Ministry nutrition DB API for product nutrition records.
- It also integrates with Anthropic Claude API for trend analysis and summarization.
- The README additionally mentions Gmail SMTP / SendGrid for email reports, but no mail-specific route files are visible in this tree.
5. Shared API/client layer
- lib/api/food-api.ts, lib/api/news-api.ts, and lib/api/claude-api.ts isolate outbound requests and keep vendor-specific logic out of UI components.
- This layer is where request shaping, error handling, and response normalization should live.
- The architecture uses this as a clean separation so pages and components consume app-specific data rather than raw third-party payloads.
6. Data normalization and domain modeling
- types/food.ts, types/news.ts, and types/nutrition.ts define the application’s domain contracts.
- lib/utils/food-converter.ts, lib/utils/news-utils.ts, and lib/constants/nutrition.ts convert external API fields into UI-friendly nutrition models and daily-value comparisons.
- docs/amt_num_mapping.json and the Excel reference file support the nutrition field mapping used during conversion.
- This is an important boundary: raw API data is transformed before it reaches visual components.
7. State management and local user state
- lib/store/food-store.ts holds shared food-related state across pages/components.
- lib/hooks/use-search-history.ts and lib/hooks/use-favorites.ts encapsulate browser-side persistence/interaction for search history and saved foods.
- The architecture appears to rely on client-local state for favorites/history rather than a dedicated backend database.
8. Search feature subsystem
- components/search/SearchForm.tsx, FilterPanel.tsx, SearchResults.tsx, SearchHistory.tsx, and FavoritesList.tsx form the search workflow UI.
- This subsystem is responsible for collecting query/filter input, presenting matching foods, and supporting repeated user workflows through history/favorites.
- It likely consumes the food search API and updates the shared store/hooks.
9. Nutrition visualization subsystem
- components/nutrition/NutritionRadarChart.tsx, NutritionBarChart.tsx, and ComparePanel.tsx power the nutrition comparison page.
- The README’s “6대 영양소 레이더 차트” and “최대 3개 식품 비교” map directly to this component group.
- These components sit on top of the normalized nutrition model and the nutrition constants, so the charting layer stays presentation-only.
10. Trends analysis subsystem
- components/trends/NewsListCard.tsx and TrendAnalysisCard.tsx represent the news feed and AI-generated insight output.
- Data likely flows from news/search into trends/analyze, where Claude produces a synthesized trend summary that is then rendered in the cards.
- This subsystem is the clearest example of a pipeline: news collection → AI analysis → dashboard presentation.
11. UI foundation and visualization library
- components/ui/* is a shadcn/ui component set for inputs, buttons, pagination, sliders, etc.
- recharts is the primary charting layer for nutrition visuals.
- Tailwind CSS provides styling, so UI composition is component-driven rather than template-driven.
12. Project support and operational artifacts
- docs/ contains mapping/reference data used by the nutrition conversion logic.
- DEVELOPMENT_LOG.md and the Korean planning/spec documents document the design process and requirements.
- public/ contains static assets, while test-news-api.js indicates manual/standalone API verification.
- Overall, the repository is organized as a frontend-centric dashboard with thin API routes, shared normalization utilities, and domain-specific feature components.
Main entry points: SearchForm.tsx Search workflow · layout.tsx Dashboard frame · ComparePanel.tsx Nutrition charts · NewsListCard.tsx Trend cards
Components 23
Next.js app
Routing shell and dashboard pages
- Root shell · Global app layout and document shell
app/layout.tsx - Global styles · App-wide CSS entrypoint
app/globals.css - Dashboard frame · Section layout for dashboard pages
app/(dashboard)/layout.tsx - Dashboard home · Landing page for the dashboard
app/(dashboard)/page.tsx - Nutrition page · Nutrition comparison and visualization page
app/(dashboard)/nutrition/page.tsx - Trends page · News and trend analysis page
app/(dashboard)/trends/page.tsx
API routes
Server-side endpoints exposed by the app
- Food search API · Server endpoint for food lookup
app/api/food/search/route.ts - News search API · Server endpoint for news retrieval
app/api/news/search/route.ts - Trend analysis API · Server endpoint for AI trend summarization
app/api/trends/analyze/route.ts
Feature UI
Search, nutrition, and trends screens
- Search workflow · Search form, filters, results, history, and favorites
components/search/SearchForm.tsx - Nutrition charts · Comparison panels and nutrition visualizations
components/nutrition/ComparePanel.tsx - Trend cards · News feed and AI insight presentation
components/trends/NewsListCard.tsx
Shared client layer
Reusable API adapters, state, hooks, and utilities
- Food client · Outbound adapter for nutrition database requests
lib/api/food-api.ts - News client · Outbound adapter for news search requests
lib/api/news-api.ts - Claude client · Outbound adapter for AI analysis requests
lib/api/claude-api.ts - Food store · Shared food-related application state
lib/store/food-store.ts - Browser hooks · Search history and favorites persistence hooks
lib/hooks/use-search-history.ts - Food mapping · Normalizes external food payloads into app models
lib/utils/food-converter.ts - News utils · Transforms and formats news data
lib/utils/news-utils.ts - UI kit · Reusable shadcn/ui primitives used across the app
components/ui/button.tsx
Domain models
Nutrition and news contracts plus mappings
- Food models · Food and nutrition domain contracts
types/food.ts - News models · News and trend domain contracts
types/news.ts - Nutrition rules · Daily-value constants and nutrition comparison rules
lib/constants/nutrition.ts
Connections 26
- Root shell → Dashboard frame: wraps · Root shell contains the dashboard section
- Root shell → Global styles: loads · Global document uses shared CSS
- Dashboard frame → Dashboard home: routes to · Dashboard section exposes the landing page
- Dashboard frame → Nutrition page: routes to · Dashboard section exposes nutrition analysis
- Dashboard frame → Trends page: routes to · Dashboard section exposes trend analysis
- Dashboard home → Search workflow: uses · Landing experience likely centers on search workflow
- Nutrition page → Nutrition charts: uses · Nutrition page renders comparison and chart components
- Trends page → Trend cards: uses · Trends page renders news and AI insight cards
- Search workflow → Food search API: fetches · Search workflow queries food lookup endpoint
- Trend cards → News search API: fetches · Trend feed starts from news search endpoint
- Trend cards → Trend analysis API: fetches · Trend analysis requests synthesized AI output
- Food search API → Food client: delegates to · Server route uses shared food adapter
- News search API → News client: delegates to · Server route uses shared news adapter
- Trend analysis API → Claude client: delegates to · Server route uses shared Claude adapter
- Food client → Food mapping: normalizes · Food responses are converted into app-friendly structures
- Food mapping → Food models: maps to · Normalized food data conforms to food contracts
- Food mapping → Nutrition rules: applies · Conversion uses nutrition constants and daily-value rules
- News client → News utils: formats · News payloads are shaped for UI consumption
- News utils → News models: maps to · Formatted news data conforms to news contracts
- Nutrition charts → Food models: reads · Charts and comparisons consume normalized food data
- Nutrition charts → Nutrition rules: reads · Visualization uses nutrition thresholds and labels
- Search workflow → Food store: shares state · Search components coordinate through shared food state
- Search workflow → Browser hooks: persists · History and favorites are managed in browser state
- Search workflow → UI kit: builds on · Search screens compose reusable UI primitives
- Nutrition charts → UI kit: builds on · Nutrition screens compose reusable UI primitives
- Trend cards → UI kit: builds on · Trend cards compose reusable UI primitives