# detalhe/vehicle-ai architecture

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

- Interactive diagram: https://gitdiagram.com/detalhe/vehicle-ai
- Repository: https://github.com/detalhe/vehicle-ai

## Overview

##### Project type and purpose
- This is a full-stack web application.

##### File structure
- Top level
- index.js (Express server entrypoint)
- package.json / package-lock.json (dependencies)
- .env (holds GOOGLE_API_KEY)
- vercel.json (Vercel deployment config)
- public/ (client-side static assets)
- css/index.css
- js/script.js
- img/ (logos, defaults)
- views/ (EJS templates)
- index.ejs (renders upload form + results)

##### README for additional insights
- Frameworks: Node.js, Express, EJS
- Uses multer for file uploads, uuid for temp filenames, axios for HTTP calls to @google/generative-ai.
- Deployable on Vercel.

##### Main components & interactions
a. Frontend (Browser)
- Image upload widget (drag-and-drop or file select)
- New: Text inputs for “Make” and “Model” override or supplement AI results
- Trigger: form submission → HTTP POST `/analyze`
b. Web Server (Express)
- Route `POST /analyze`
– multer middleware saves image locally or in memory
– Reads user-entered make/model fields
– Constructs request: image + optional user inputs
– Calls Google Gemini API via @google/generative-ai client
– Merges AI output with user overrides if provided
– Renders `views/index.ejs` with full result payload
c. External Service
- Google Gemini AI endpoint
d. Static Assets Server
- Serves CSS, JS, default/preview images, and manufacturer logos

##### Architectural patterns & design principles
- MVC-style separation:
- Model: external AI response + user input
- View: EJS template
- Controller: Express route handlers
- Single process server; no microservices
- Third-party integration via well-encapsulated API module (axios + @google/generative-ai)
- Stateless requests; can horizontally scale behind a load balancer

##### Incorporating the “add user input for make and model” feature
- Text input fields labeled “Make” and “Model”.
- In the flow, show these fields being packaged along with the image in the HTTP POST to the Express server.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Frontend (Browser)"
        UI["Image Upload & Make/Model Form"]:::frontend
        CSS["Stylesheet: index.css"]:::assets
        JS["Logic: script.js"]:::assets
    end

    subgraph "Express Server"
        SRV["index.js\n(Express, multer, axios,\n@google/generative-ai,\n.env overrides)"]:::server
        VIEW["EJS Template: views/index.ejs"]:::view
    end

    ExtAI["Google Gemini AI"]:::external
    Static["Static Assets (public/img/)"]:::assets

    subgraph "Project Files"
        pjson["package.json"]:::config
        lock["package-lock.json"]:::config
        env[".env"]:::config
        vercel["vercel.json"]:::config
        readme["README.md"]:::config
        license["LICENSE"]:::config
        gitignore[".gitignore"]:::config
    end

    UI -->|"POST /analyze\n(image + make/model)"| SRV
    SRV -->|"Render HTML Response"| UI
    SRV -->|"API Call"| ExtAI
    UI -->|"Fetch CSS/JS/Images"| Static

    classDef frontend fill:#E0F7FA,stroke:#0288D1,color:#000;
    classDef server fill:#E8F5E9,stroke:#388E3C,color:#000;
    classDef external fill:#FFECB3,stroke:#F57C00,color:#000;
    classDef assets fill:#CFD8DC,stroke:#455A64,color:#000;
    classDef view fill:#FFF9C4,stroke:#F9A825,color:#000;
    classDef config fill:#ECEFF1,stroke:#90A4AE,color:#000;

    click JS "https://github.com/detalhe/vehicle-ai/blob/main/public/js/script.js"
    click CSS "https://github.com/detalhe/vehicle-ai/blob/main/public/css/index.css"
    click SRV "https://github.com/detalhe/vehicle-ai/blob/main/index.js"
    click VIEW "https://github.com/detalhe/vehicle-ai/blob/main/views/index.ejs"
    click Static "https://github.com/detalhe/vehicle-ai/tree/main/public/img/"
    click pjson "https://github.com/detalhe/vehicle-ai/blob/main/package.json"
    click lock "https://github.com/detalhe/vehicle-ai/blob/main/package-lock.json"
    click env "https://github.com/detalhe/vehicle-ai/blob/main/.env"
    click vercel "https://github.com/detalhe/vehicle-ai/blob/main/vercel.json"
    click readme "https://github.com/detalhe/vehicle-ai/blob/main/README.md"
    click license "https://github.com/detalhe/vehicle-ai/tree/main/LICENSE"
    click gitignore "https://github.com/detalhe/vehicle-ai/blob/main/.gitignore"
```
