# sayan365/plant-identifier architecture

> Architecture diagram of the GitHub repository sayan365/plant-identifier, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sayan365/plant-identifier
- Repository: https://github.com/sayan365/plant-identifier

## Overview

##### Project Type and Purpose
- This is a full-stack, server-rendered web application built with React and Next.js.
- Purpose: Let users upload/capture plant photos and fetch species info from an external Plant Identification API.

##### Main Architectural Components
a. Client (Web Browser)
– React pages (app/page.js) and components (PlantCard.js, SearchBar.js)
– Tailwind CSS for styling (globals.css, tailwind.config.js)
b. Next.js Server
– Page rendering (SSR/SSG) via layout.js & page.js
– API Routes (app/api/identify/route.js & app/api/test/route.js)
– Static assets served from public/
c. External Service
– Plant Identification API (third-party HTTP service)
d. Infrastructure & Build
– next.config.js, tsconfig.json, postcss.config.js
– Environment variable (NEXT_PUBLIC_API_KEY)

##### Relationships & Data Flows
1. User visits the site → HTTP GET to Next.js server → Server sends pre-rendered HTML + JS bundle
2. User uploads/captures image in UI → Frontend issues POST to `/api/identify`
3. Next.js API handler (route.js)
- Receives image payload
- Reads NEXT_PUBLIC_API_KEY from env
- Forwards request to external Plant Identification API
4. External API returns JSON plant data → Next.js API handler transforms it → Responds to client
5. Frontend updates React state → Renders PlantCard with species details

##### Architectural Patterns & Design Principles
- File-based routing: pages and API routes co-located under `app/`
- Component-based UI: reusable PlantCard & SearchBar
- Serverless functions: Next.js API routes act as lightweight backends
- Environment isolation: `.env.local` for secrets
- Utility-first styling: Tailwind CSS

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        BrowserClient["Browser UI (React + Tailwind)"]:::frontend
        MainPage["Main Page"]:::frontend
        LayoutWrapper["Layout Wrapper"]:::frontend
        PlantCard["PlantCard Component"]:::frontend
        SearchBar["SearchBar Component"]:::frontend
        GlobalStyles["Global Styles (globals.css)"]:::frontend
        TailwindConfig["Tailwind Config"]:::frontend
    end

    %% Server Layer
    subgraph "Next.js Server"
        direction TB
        PageRenderer["Page Renderer (SSR/SSG)"]:::server
        APIIdentify["API Route: /api/identify"]:::server
        APITest["API Route: /api/test"]:::server
        StaticAssets["Static Assets (public/)"]:::server
        NextConfig["Next.js Config"]:::server
        PostCSSConfig["PostCSS Config"]:::server
        TSConfig["TypeScript Config"]:::server
    end

    %% External Services
    subgraph "External Services"
        direction TB
        PlantAPI["Plant Identification API"]:::external
    end

    %% Data Flows
    BrowserClient -->|"GET / (HTML+JS bundle)"| PageRenderer
    SearchBar -->|"POST /api/identify (image)"| APIIdentify
    APIIdentify -->|"GET (image + API_KEY)"| PlantAPI
    PlantAPI -->|"JSON {species, common_name,...}"| APIIdentify
    APIIdentify -->|"JSON response"| BrowserClient

    %% Click Events
    click MainPage "https://github.com/sayan365/plant-identifier/blob/main/app/page.js"
    click LayoutWrapper "https://github.com/sayan365/plant-identifier/blob/main/app/layout.js"
    click PlantCard "https://github.com/sayan365/plant-identifier/blob/main/app/Component/PlantCard.js"
    click SearchBar "https://github.com/sayan365/plant-identifier/blob/main/app/Component/SearchBar.js"
    click GlobalStyles "https://github.com/sayan365/plant-identifier/blob/main/app/globals.css"
    click TailwindConfig "https://github.com/sayan365/plant-identifier/blob/main/tailwind.config.js"
    click NextConfig "https://github.com/sayan365/plant-identifier/blob/main/next.config.js"
    click PostCSSConfig "https://github.com/sayan365/plant-identifier/blob/main/postcss.config.js"
    click TSConfig "https://github.com/sayan365/plant-identifier/blob/main/tsconfig.json"
    click APIIdentify "https://github.com/sayan365/plant-identifier/blob/main/app/api/identify/route.js"
    click APITest "https://github.com/sayan365/plant-identifier/blob/main/app/api/test/route.js"
    click StaticAssets "https://github.com/sayan365/plant-identifier/tree/main/public/"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#0277BD,color:#000;
    classDef server fill:#E8F5E9,stroke:#2E7D32,color:#000;
    classDef external fill:#FFF3E0,stroke:#EF6C00,color:#000;
```
