# jhn07/ai-floor-analysis architecture

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

- Interactive diagram: https://gitdiagram.com/jhn07/ai-floor-analysis
- Repository: https://github.com/jhn07/ai-floor-analysis

## Overview

##### Project type and purpose
- This is a full-stack Next.js 13 application (“app” directory, React components, built-in API routes) that lets users upload floor plans, run AI-powered analysis, chat about them, and even generate TTS responses.

##### File structure
- Top-level “app” directory: contains your React pages and built-in API routes (analyze, chat, tts).
- “components”: reusable UI pieces divided into analysis cards, chat UI, and generic UI elements.
- “hooks”: client-side React hooks for file uploads, chat state, and scrolling.
- “services”: a service layer that abstracts calls to your backend routes (api.service.ts) and to external AI providers (ai-analyzer.service.ts, ai-chat.service.ts).
- “lib/utils.ts” and “types”: application utilities and TypeScript typings.

##### README for additional insights
- Uses Next.js 13 with the App Router, React, and Vercel deployment.
- No dedicated database layer—AI requests go out at runtime via the API routes.

##### Elements
– Blue for frontend/UI
– Green for backend/API routes & services
– Orange for external systems (AI/TTS)
- Annotations for TypeScript types, utility modules, and the public asset directory if relevant.

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph "Client / Frontend Layer"
    direction TB
    Page["Next.js App Router Entry<br/>app/page.tsx"]:::frontend
    Layout["Global Layout<br/>app/layout.tsx"]:::frontend
    Styles["Global Styles<br/>app/globals.css"]:::frontend

    subgraph "UI Components"
      direction TB
      FloorPlanCard["Floor Plan Card"]:::frontend
      RecommendationCard["Recommendation Card"]:::frontend
      ScoreCard["Score Card"]:::frontend
      ChatContainer["Chat Container"]:::frontend
      ChatHeader["Chat Header"]:::frontend
      ChatMessage["Chat Message"]:::frontend
      ChatInput["Chat Input"]:::frontend
      TypingIndicator["Typing Indicator"]:::frontend
      AudioPlayer["Audio Message Player"]:::frontend
      UploadArea["Upload Area"]:::frontend
    end

    subgraph "Hooks"
      direction TB
      FileUploadHook["use-file-upload"]:::frontend
      ChatStateHook["use-floor-plan-chat"]:::frontend
      ScrollHook["use-scroll"]:::frontend
    end
  end

  subgraph "Backend / API Routes & Services"
    direction TB
    subgraph "API Routes"
      direction TB
      AnalyzeAPI["POST /api/analyze"]:::backend
      ChatAPI["POST /api/chat"]:::backend
      TTSAPI["POST /api/tts"]:::backend
    end
    subgraph "Service Layer"
      direction TB
      APIService["Backend Route Client<br/>api.service.ts"]:::backend
      AIAnalyzer["AI Analysis Service<br/>ai-analyzer.service.ts"]:::backend
      AIChat["AI Chat Service<br/>ai-chat.service.ts"]:::backend
    end
  end

  subgraph "External Systems"
    direction TB
    AIProvider["External AI Provider<br/>(LLM & Embeddings)"]:::external
    TTSEngine["External TTS Engine"]:::external
  end

  Public["Static Assets<br/>public/"]:::backend

  %% Data Flows
  Page -->|renders| FloorPlanCard
  Page -->|renders| RecommendationCard
  Page -->|renders| ScoreCard
  Page -->|renders| ChatContainer
  Page -->|renders| UploadArea
  Layout -->|applies| Styles

  FloorPlanCard -->|uses| FileUploadHook
  RecommendationCard -->|uses| FileUploadHook
  ScoreCard -->|uses| FileUploadHook
  ChatContainer -->|uses| ChatStateHook
  ChatContainer -->|uses| ScrollHook
  ChatInput -->|uses| ChatStateHook
  TypingIndicator -->|uses| ChatStateHook
  AudioPlayer -->|plays| TTSAPI

  UploadArea -->|uploads via HTTP| AnalyzeAPI
  ChatContainer -->|sends via HTTP| ChatAPI
  AudioPlayer -->|fetches via HTTP| TTSAPI

  AnalyzeAPI -->|calls| AIAnalyzer
  ChatAPI -->|calls| AIChat
  TTSAPI -->|calls| APIService

  AIAnalyzer -->|requests embeddings| AIProvider
  AIChat -->|requests chat completions| AIProvider
  APIService -->|requests audio| TTSEngine

  AnalyzeAPI -->|returns JSON| UploadArea
  ChatAPI -->|returns messages| ChatContainer
  TTSAPI -->|returns audio blob| AudioPlayer

  Page -->|serves static| Public

  %% Click Events
  click Page "https://github.com/jhn07/ai-floor-analysis/blob/main/app/page.tsx"
  click Layout "https://github.com/jhn07/ai-floor-analysis/blob/main/app/layout.tsx"
  click Styles "https://github.com/jhn07/ai-floor-analysis/blob/main/app/globals.css"
  click AnalyzeAPI "https://github.com/jhn07/ai-floor-analysis/blob/main/app/api/analyze/route.ts"
  click ChatAPI "https://github.com/jhn07/ai-floor-analysis/blob/main/app/api/chat/route.ts"
  click TTSAPI "https://github.com/jhn07/ai-floor-analysis/blob/main/app/api/tts/route.ts"
  click FloorPlanCard "https://github.com/jhn07/ai-floor-analysis/blob/main/components/analysis/floorplan-card.tsx"
  click RecommendationCard "https://github.com/jhn07/ai-floor-analysis/blob/main/components/analysis/recommendation-card.tsx"
  click ScoreCard "https://github.com/jhn07/ai-floor-analysis/blob/main/components/analysis/score-card.tsx"
  click ChatContainer "https://github.com/jhn07/ai-floor-analysis/blob/main/components/chat-interface.tsx"
  click ChatHeader "https://github.com/jhn07/ai-floor-analysis/blob/main/components/chat/chat-header.tsx"
  click ChatMessage "https://github.com/jhn07/ai-floor-analysis/blob/main/components/chat/chat-message.tsx"
  click ChatInput "https://github.com/jhn07/ai-floor-analysis/blob/main/components/chat/chat-input.tsx"
  click TypingIndicator "https://github.com/jhn07/ai-floor-analysis/blob/main/components/chat/typing-indicator.tsx"
  click AudioPlayer "https://github.com/jhn07/ai-floor-analysis/blob/main/components/audio-message.tsx"
  click UploadArea "https://github.com/jhn07/ai-floor-analysis/blob/main/components/upload-area.tsx"
  click FileUploadHook "https://github.com/jhn07/ai-floor-analysis/blob/main/hooks/use-file-upload.ts"
  click ChatStateHook "https://github.com/jhn07/ai-floor-analysis/blob/main/hooks/use-floor-plan-chat.ts"
  click ScrollHook "https://github.com/jhn07/ai-floor-analysis/blob/main/hooks/use-scroll.ts"
  click APIService "https://github.com/jhn07/ai-floor-analysis/blob/main/services/api.service.ts"
  click AIAnalyzer "https://github.com/jhn07/ai-floor-analysis/blob/main/services/ai-analyzer.service.ts"
  click AIChat "https://github.com/jhn07/ai-floor-analysis/blob/main/services/ai-chat.service.ts"

  %% Styles
  classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#000
  classDef backend fill:#D5F5E3,stroke:#28a745,color:#000
  classDef external fill:#FFE5B4,stroke:#e67e22,color:#000
```
