# navuluribalaji/model-inventory architecture

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

- Interactive diagram: https://gitdiagram.com/navuluribalaji/model-inventory
- Repository: https://github.com/navuluribalaji/model-inventory

## Overview

##### Project type and purpose
- This is a full-stack, single-page web application built on Next.js (App Router) whose purpose is to let users submit one prompt to multiple AI models (open-source via OpenRouter and proprietary via Google Gemini) and compare the responses side-by-side.

##### File structure
- Top-level:
- next.config.ts, tsconfig.json, tailwind.config.ts, package.json → Next.js + TypeScript + Tailwind CSS
- src/app → App Router entrypoints (layout.tsx, page.tsx, global CSS)
- src/components → UI layers split into “app” (page-specific components) and “ui” (reusable ShadCN UI primitives)
- src/ai → AI orchestration code (Genkit integration, flow definitions for generating requests, fetching model responses, summarization)
- src/lib → shared helpers (model definitions, OpenRouter wrapper, utils)
- src/hooks → React hooks (e.g., device detection, toast notifications)
- No dedicated database or backend folder—data persistence (chat history, API keys) happens in browser localStorage. Calls to AI providers are proxied via Genkit (serverless).

##### Extract insights from the README
- Key features: side-by-side comparison, performance metrics, persistent chat history, secure in-browser key storage, dynamic/interactive UI, JSON/table formatting, responsive design.
- Tech stack: Next.js, Genkit by Firebase, Tailwind CSS, ShadCN UI, Lucide React, TypeScript.

##### Main components & relationships
a. Frontend Browser (Client)
- React UI (src/app + src/components)
- CSS (Tailwind-generated)
- Local Storage (API keys, chat history)
b. Next.js Runtime (Serverless)
- App Router handles SSR/SSG and server components
- Routes invoke src/ai/genkit.ts → Genkit calls
c. Genkit (Firebase Gen AI Kit service)
- Orchestrates flows defined in src/ai/flows/*.ts
- Dispatches calls to external AI providers
d. External AI Providers
- OpenRouter endpoints (Llama 3, Mistral, etc.)
- Google Gemini API
e. Shared Code
- src/lib: abstracts model configs, HTTP wrappers, utilities
- src/hooks: state handling and UI utilities

Interactions:
1. User enters prompt → React component triggers an AI flow
2. Flow function (generate → get-model-responses → summarize) invoked via Genkit
3. Genkit forwards requests to each model endpoint
4. Responses return to Genkit → delivered back to Next.js route
5. UI renders response cards with timing metrics; chat saved to localStorage

##### Architectural patterns & design principles
- Component-based UI separation (app vs. UI primitives)
- Flow-based AI orchestration (modular “flows”)
- Thin serverless layer (Next.js + Genkit) — business logic in cloud functions
- Client-side persistence (no centralized database)
- API abstraction (src/lib/openrouter, genkit wrapper)

##### Detail without overthinking
- Break out src/ai/flows, src/lib, src/components/app, src/components/ui, and src/hooks as separate sub-components
- How configuration (next.config.ts, tailwind.config.ts) feeds into build/deploy
- Flow of data (prompt → multi-model calls → aggregated responses)
- No-server-DB choice (localStorage) and secure key management

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (Browser)" 
        direction TB
        Header["Header Component"]:::client
        PromptForm["PromptForm Component"]:::client
        ModelSelection["ModelSelection Component"]:::client
        ResponseCard["ResponseCard Component"]:::client
        APIKeyManager["API Key Manager Component"]:::client
        CameraCapture["Camera Capture Component"]:::client
        UIPrimitives["Reusable UI Primitives"]:::client
        ModelIcons["Model Icons"]:::client
        LocalStorage[(Local Storage)]:::storage
        Header -->|renders| PromptForm
        PromptForm -->|selects model| ModelSelection
        ModelSelection -->|submits prompt| APIKeyManager
        APIKeyManager -->|manages keys| LocalStorage
        PromptForm -->|captures image| CameraCapture
        ResponseCard -->|displays response| LocalStorage
        UIPrimitives -->|used by| PromptForm
        ModelIcons -->|used by| ModelSelection
        PromptForm -->|triggers| NextRoute
        UIPrimitives -->|used by| ResponseCard
    end

    %% Serverless Backend
    subgraph "Serverless Backend (Next.js + Genkit)" 
        direction TB
        NextRoute["Next.js Route (layout.tsx & page.tsx)"]:::backend
        GenkitIntegration["AI Genkit Integration"]:::backend
        subgraph "AI Flows" 
            direction TB
            FlowGenerate["Flow: generate-example-requests"]:::backend
            FlowResponses["Flow: get-model-responses"]:::backend
            FlowSummarize["Flow: summarize-use-cases"]:::backend
        end
        subgraph "Shared Lib" 
            direction TB
            Models["Model Definitions"]:::backend
            OpenRouter["OpenRouter Wrapper"]:::backend
            Utils["Shared Utilities"]:::backend
        end
        Hooks["React Hooks"]:::backend
        NextRoute -->|calls| GenkitIntegration
        GenkitIntegration -->|invokes| FlowGenerate
        FlowGenerate -->|uses| Models
        FlowGenerate -->|uses| OpenRouter
        FlowGenerate -->|uses| Utils
        FlowGenerate -->|calls| FlowResponses
        FlowResponses -->|dispatches| OpenRouter
        FlowResponses -->|calls| FlowSummarize
        FlowSummarize -->|uses| Utils
        Hooks -->|provides| NextRoute
        NextRoute -->|returns responses| ResponseCard
    end

    %% Configurations
    subgraph "Configurations" 
        direction TB
        NextConfig["next.config.ts"]:::backend
        TailwindConfig["tailwind.config.ts"]:::backend
        TsConfig["tsconfig.json"]:::backend
        NextConfig -->|configures| NextRoute
        TailwindConfig -->|configures| UIPrimitives
        TsConfig -->|configures| All
    end

    %% External Services
    subgraph "External AI Providers"
        direction TB
        OpenRouterAPI["OpenRouter API"]:::external
        GoogleGemini["Google Gemini API"]:::external
        OpenRouterAPI -->|responses| GenkitIntegration
        GoogleGemini -->|responses| GenkitIntegration
        GenkitIntegration -->|forwards requests| OpenRouterAPI
        GenkitIntegration -->|forwards requests| GoogleGemini
    end

    %% Click Events
    click Layout "https://github.com/navuluribalaji/model-inventory/blob/main/src/app/layout.tsx"
    click Page "https://github.com/navuluribalaji/model-inventory/blob/main/src/app/page.tsx"
    click GlobalsCSS "https://github.com/navuluribalaji/model-inventory/blob/main/src/app/globals.css"
    click BackgroundCSS "https://github.com/navuluribalaji/model-inventory/blob/main/src/app/background.css"
    click PromptForm "https://github.com/navuluribalaji/model-inventory/blob/main/src/components/app/prompt-form.tsx"
    click ModelSelection "https://github.com/navuluribalaji/model-inventory/blob/main/src/components/app/model-selection.tsx"
    click ResponseCard "https://github.com/navuluribalaji/model-inventory/blob/main/src/components/app/response-card.tsx"
    click APIKeyManager "https://github.com/navuluribalaji/model-inventory/blob/main/src/components/app/api-key-manager.tsx"
    click CameraCapture "https://github.com/navuluribalaji/model-inventory/blob/main/src/components/app/camera-capture.tsx"
    click Header "https://github.com/navuluribalaji/model-inventory/blob/main/src/components/app/header.tsx"
    click UIPrimitives "https://github.com/navuluribalaji/model-inventory/tree/main/src/components/ui/"
    click ModelIcons "https://github.com/navuluribalaji/model-inventory/blob/main/src/components/icons/model-icons.tsx"
    click GenkitIntegration "https://github.com/navuluribalaji/model-inventory/blob/main/src/ai/genkit.ts"
    click FlowGenerate "https://github.com/navuluribalaji/model-inventory/blob/main/src/ai/flows/generate-example-requests.ts"
    click FlowResponses "https://github.com/navuluribalaji/model-inventory/blob/main/src/ai/flows/get-model-responses.ts"
    click FlowSummarize "https://github.com/navuluribalaji/model-inventory/blob/main/src/ai/flows/summarize-use-cases.ts"
    click Models "https://github.com/navuluribalaji/model-inventory/blob/main/src/lib/models.ts"
    click OpenRouter "https://github.com/navuluribalaji/model-inventory/blob/main/src/lib/openrouter.ts"
    click Utils "https://github.com/navuluribalaji/model-inventory/blob/main/src/lib/utils.ts"
    click UseMobile "https://github.com/navuluribalaji/model-inventory/blob/main/src/hooks/use-mobile.tsx"
    click UseToast "https://github.com/navuluribalaji/model-inventory/blob/main/src/hooks/use-toast.ts"
    click NextConfig "https://github.com/navuluribalaji/model-inventory/blob/main/next.config.ts"
    click TailwindConfig "https://github.com/navuluribalaji/model-inventory/blob/main/tailwind.config.ts"
    click TsConfig "https://github.com/navuluribalaji/model-inventory/blob/main/tsconfig.json"

    %% Styles
    classDef client fill:#cfe2ff,stroke:#2f5d9c,color:#0f3057
    classDef backend fill:#d1e7dd,stroke:#276749,color:#1b4332
    classDef external fill:#ffe5b4,stroke:#c65d00,color:#663c00
    classDef storage fill:#f8d7da,stroke:#842029,color:#51141c
```
