# psw3137/nutritrend-dashboard architecture

> Architecture diagram of the GitHub repository psw3137/nutritrend-dashboard, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/psw3137/nutritrend-dashboard
- Repository: https://github.com/psw3137/nutritrend-dashboard

## Overview

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: [`components/search/SearchForm.tsx`](https://github.com/psw3137/nutritrend-dashboard/blob/master/components/search/SearchForm.tsx) (Search workflow), [`app/(dashboard)/layout.tsx`](https://github.com/psw3137/nutritrend-dashboard/blob/master/app/(dashboard)/layout.tsx) (Dashboard frame), [`components/nutrition/ComparePanel.tsx`](https://github.com/psw3137/nutritrend-dashboard/blob/master/components/nutrition/ComparePanel.tsx) (Nutrition charts), [`components/trends/NewsListCard.tsx`](https://github.com/psw3137/nutritrend-dashboard/blob/master/components/trends/NewsListCard.tsx) (Trend cards)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Next.js app"]
  node_app_layout["Root shell<br/>layout<br/>[layout.tsx]"]
  node_app_styles["Global styles<br/>[globals.css]"]
  node_dashboard_layout["Dashboard frame<br/>layout<br/>[layout.tsx]"]
  node_dashboard_home["Dashboard home<br/>page<br/>[page.tsx]"]
  node_nutrition_page["Nutrition page<br/>[page.tsx]"]
  node_trends_page["Trends page<br/>[page.tsx]"]
end

subgraph group_api["API routes"]
  node_food_search_api["Food search API<br/>route<br/>[route.ts]"]
  node_news_search_api["News search API<br/>route<br/>[route.ts]"]
  node_trends_analyze_api["Trend analysis API<br/>route<br/>[route.ts]"]
end

subgraph group_features["Feature UI"]
  node_search_ui["Search workflow<br/>feature set<br/>[SearchForm.tsx]"]
  node_nutrition_ui["Nutrition charts<br/>feature set<br/>[ComparePanel.tsx]"]
  node_trends_ui["Trend cards<br/>feature set<br/>[NewsListCard.tsx]"]
end

subgraph group_shared["Shared client layer"]
  node_food_api_lib["Food client<br/>api adapter<br/>[food-api.ts]"]
  node_news_api_lib["News client<br/>api adapter<br/>[news-api.ts]"]
  node_claude_api_lib["Claude client<br/>api adapter<br/>[claude-api.ts]"]
  node_food_store["Food store<br/>client state<br/>[food-store.ts]"]
  node_search_hooks["Browser hooks<br/>client state"]
  node_food_convert["Food mapping<br/>transform<br/>[food-converter.ts]"]
  node_news_utils["News utils<br/>transform<br/>[news-utils.ts]"]
  node_ui_kit["UI kit<br/>component library<br/>[button.tsx]"]
end

subgraph group_domain["Domain models"]
  node_food_domain["Food models<br/>types<br/>[food.ts]"]
  node_news_domain["News models<br/>types<br/>[news.ts]"]
  node_nutrition_domain["Nutrition rules<br/>constants<br/>[nutrition.ts]"]
end

node_app_layout -->|"wraps"| node_dashboard_layout
node_app_layout -->|"loads"| node_app_styles
node_dashboard_layout -->|"routes to"| node_dashboard_home
node_dashboard_layout -->|"routes to"| node_nutrition_page
node_dashboard_layout -->|"routes to"| node_trends_page
node_dashboard_home -->|"uses"| node_search_ui
node_nutrition_page -->|"uses"| node_nutrition_ui
node_trends_page -->|"uses"| node_trends_ui
node_search_ui -->|"fetches"| node_food_search_api
node_trends_ui -->|"fetches"| node_news_search_api
node_trends_ui -->|"fetches"| node_trends_analyze_api
node_food_search_api -->|"delegates to"| node_food_api_lib
node_news_search_api -->|"delegates to"| node_news_api_lib
node_trends_analyze_api -->|"delegates to"| node_claude_api_lib
node_food_api_lib -->|"normalizes"| node_food_convert
node_food_convert -->|"maps to"| node_food_domain
node_food_convert -->|"applies"| node_nutrition_domain
node_news_api_lib -->|"formats"| node_news_utils
node_news_utils -->|"maps to"| node_news_domain
node_nutrition_ui -->|"reads"| node_food_domain
node_nutrition_ui -->|"reads"| node_nutrition_domain
node_search_ui -->|"shares state"| node_food_store
node_search_ui -->|"persists"| node_search_hooks
node_search_ui -->|"builds on"| node_ui_kit
node_nutrition_ui -->|"builds on"| node_ui_kit
node_trends_ui -->|"builds on"| node_ui_kit

click node_app_layout "https://github.com/psw3137/nutritrend-dashboard/blob/master/app/layout.tsx"
click node_app_styles "https://github.com/psw3137/nutritrend-dashboard/blob/master/app/globals.css"
click node_dashboard_layout "https://github.com/psw3137/nutritrend-dashboard/blob/master/app/(dashboard)/layout.tsx"
click node_dashboard_home "https://github.com/psw3137/nutritrend-dashboard/blob/master/app/(dashboard)/page.tsx"
click node_nutrition_page "https://github.com/psw3137/nutritrend-dashboard/blob/master/app/(dashboard)/nutrition/page.tsx"
click node_trends_page "https://github.com/psw3137/nutritrend-dashboard/blob/master/app/(dashboard)/trends/page.tsx"
click node_food_search_api "https://github.com/psw3137/nutritrend-dashboard/blob/master/app/api/food/search/route.ts"
click node_news_search_api "https://github.com/psw3137/nutritrend-dashboard/blob/master/app/api/news/search/route.ts"
click node_trends_analyze_api "https://github.com/psw3137/nutritrend-dashboard/blob/master/app/api/trends/analyze/route.ts"
click node_search_ui "https://github.com/psw3137/nutritrend-dashboard/blob/master/components/search/SearchForm.tsx"
click node_nutrition_ui "https://github.com/psw3137/nutritrend-dashboard/blob/master/components/nutrition/ComparePanel.tsx"
click node_trends_ui "https://github.com/psw3137/nutritrend-dashboard/blob/master/components/trends/NewsListCard.tsx"
click node_food_api_lib "https://github.com/psw3137/nutritrend-dashboard/blob/master/lib/api/food-api.ts"
click node_news_api_lib "https://github.com/psw3137/nutritrend-dashboard/blob/master/lib/api/news-api.ts"
click node_claude_api_lib "https://github.com/psw3137/nutritrend-dashboard/blob/master/lib/api/claude-api.ts"
click node_food_store "https://github.com/psw3137/nutritrend-dashboard/blob/master/lib/store/food-store.ts"
click node_search_hooks "https://github.com/psw3137/nutritrend-dashboard/blob/master/lib/hooks/use-search-history.ts"
click node_food_domain "https://github.com/psw3137/nutritrend-dashboard/blob/master/types/food.ts"
click node_news_domain "https://github.com/psw3137/nutritrend-dashboard/blob/master/types/news.ts"
click node_nutrition_domain "https://github.com/psw3137/nutritrend-dashboard/blob/master/lib/constants/nutrition.ts"
click node_food_convert "https://github.com/psw3137/nutritrend-dashboard/blob/master/lib/utils/food-converter.ts"
click node_news_utils "https://github.com/psw3137/nutritrend-dashboard/blob/master/lib/utils/news-utils.ts"
click node_ui_kit "https://github.com/psw3137/nutritrend-dashboard/blob/master/components/ui/button.tsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_layout,node_app_styles,node_dashboard_layout,node_dashboard_home,node_nutrition_page,node_trends_page toneBlue
class node_food_search_api,node_news_search_api,node_trends_analyze_api toneAmber
class node_search_ui,node_nutrition_ui,node_trends_ui toneMint
class node_food_api_lib,node_news_api_lib,node_claude_api_lib,node_food_store,node_search_hooks,node_food_convert,node_news_utils,node_ui_kit toneRose
class node_food_domain,node_news_domain,node_nutrition_domain toneIndigo
```

## Components

### Next.js app

Routing shell and dashboard pages

- [Root shell](https://github.com/psw3137/nutritrend-dashboard/blob/master/app/layout.tsx): layout · Global app layout and document shell · `app/layout.tsx`
- [Global styles](https://github.com/psw3137/nutritrend-dashboard/blob/master/app/globals.css): styles · App-wide CSS entrypoint · `app/globals.css`
- [Dashboard frame](https://github.com/psw3137/nutritrend-dashboard/blob/master/app/(dashboard)/layout.tsx): layout · Section layout for dashboard pages · `app/(dashboard)/layout.tsx`
- [Dashboard home](https://github.com/psw3137/nutritrend-dashboard/blob/master/app/(dashboard)/page.tsx): page · Landing page for the dashboard · `app/(dashboard)/page.tsx`
- [Nutrition page](https://github.com/psw3137/nutritrend-dashboard/blob/master/app/(dashboard)/nutrition/page.tsx): page · Nutrition comparison and visualization page · `app/(dashboard)/nutrition/page.tsx`
- [Trends page](https://github.com/psw3137/nutritrend-dashboard/blob/master/app/(dashboard)/trends/page.tsx): page · News and trend analysis page · `app/(dashboard)/trends/page.tsx`

### API routes

Server-side endpoints exposed by the app

- [Food search API](https://github.com/psw3137/nutritrend-dashboard/blob/master/app/api/food/search/route.ts): route · Server endpoint for food lookup · `app/api/food/search/route.ts`
- [News search API](https://github.com/psw3137/nutritrend-dashboard/blob/master/app/api/news/search/route.ts): route · Server endpoint for news retrieval · `app/api/news/search/route.ts`
- [Trend analysis API](https://github.com/psw3137/nutritrend-dashboard/blob/master/app/api/trends/analyze/route.ts): route · Server endpoint for AI trend summarization · `app/api/trends/analyze/route.ts`

### Feature UI

Search, nutrition, and trends screens

- [Search workflow](https://github.com/psw3137/nutritrend-dashboard/blob/master/components/search/SearchForm.tsx): feature set · Search form, filters, results, history, and favorites · `components/search/SearchForm.tsx`
- [Nutrition charts](https://github.com/psw3137/nutritrend-dashboard/blob/master/components/nutrition/ComparePanel.tsx): feature set · Comparison panels and nutrition visualizations · `components/nutrition/ComparePanel.tsx`
- [Trend cards](https://github.com/psw3137/nutritrend-dashboard/blob/master/components/trends/NewsListCard.tsx): feature set · News feed and AI insight presentation · `components/trends/NewsListCard.tsx`

### Shared client layer

Reusable API adapters, state, hooks, and utilities

- [Food client](https://github.com/psw3137/nutritrend-dashboard/blob/master/lib/api/food-api.ts): api adapter · Outbound adapter for nutrition database requests · `lib/api/food-api.ts`
- [News client](https://github.com/psw3137/nutritrend-dashboard/blob/master/lib/api/news-api.ts): api adapter · Outbound adapter for news search requests · `lib/api/news-api.ts`
- [Claude client](https://github.com/psw3137/nutritrend-dashboard/blob/master/lib/api/claude-api.ts): api adapter · Outbound adapter for AI analysis requests · `lib/api/claude-api.ts`
- [Food store](https://github.com/psw3137/nutritrend-dashboard/blob/master/lib/store/food-store.ts): client state · Shared food-related application state · `lib/store/food-store.ts`
- [Browser hooks](https://github.com/psw3137/nutritrend-dashboard/blob/master/lib/hooks/use-search-history.ts): client state · Search history and favorites persistence hooks · `lib/hooks/use-search-history.ts`
- [Food mapping](https://github.com/psw3137/nutritrend-dashboard/blob/master/lib/utils/food-converter.ts): transform · Normalizes external food payloads into app models · `lib/utils/food-converter.ts`
- [News utils](https://github.com/psw3137/nutritrend-dashboard/blob/master/lib/utils/news-utils.ts): transform · Transforms and formats news data · `lib/utils/news-utils.ts`
- [UI kit](https://github.com/psw3137/nutritrend-dashboard/blob/master/components/ui/button.tsx): component library · Reusable shadcn/ui primitives used across the app · `components/ui/button.tsx`

### Domain models

Nutrition and news contracts plus mappings

- [Food models](https://github.com/psw3137/nutritrend-dashboard/blob/master/types/food.ts): types · Food and nutrition domain contracts · `types/food.ts`
- [News models](https://github.com/psw3137/nutritrend-dashboard/blob/master/types/news.ts): types · News and trend domain contracts · `types/news.ts`
- [Nutrition rules](https://github.com/psw3137/nutritrend-dashboard/blob/master/lib/constants/nutrition.ts): constants · Daily-value constants and nutrition comparison rules · `lib/constants/nutrition.ts`

## Connections

- 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
