Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Smart Valuator API

Java Spring Boot PostgreSQL Build AI Hugging Face


Description

AI-powered REST API for electronic item valuation built with Spring Boot 4.0.2 for the European market. It integrates Llama 3.3-70B via Hugging Face for intelligent price estimation in EUR (€) with market-based fallback pricing. Demonstrates clean layered architecture (Controller β†’ Service β†’ Repository β†’ Entity/DTO), AI integration, error handling, and REST best practices.


Features

  • AI-Powered Valuation

    • Natural language descriptions via Llama 3.3-70B
    • Intelligent price estimation based on market data
    • Fallback pricing when AI is unavailable
    • Condition-based price adjustment (1-10 scale)
  • Complete CRUD operations

    • Create, Read, Update, Delete estimations
    • Historical tracking with timestamps
    • Price and description storage
  • Architecture & Quality

    • Clean layered architecture
    • DTOs for API communication
    • Centralized error handling
    • BigDecimal for precise currency values
    • Proper JSON serialization (tools.jackson)
    • CORS enabled for frontend integration

Technologies

Technology Version
Java 17+
Spring Boot 4.0.2
Spring Data JPA -
PostgreSQL -
Hugging Face API Llama 3.3-70B
Lombok -
tools.jackson (Jackson 3.x) bundled with Spring Boot 4

Project Structure

com.yann.smart_valuator_api
β”‚
β”œβ”€β”€ config/           β†’ Spring configuration (JacksonConfig, CORS)
β”œβ”€β”€ controller/       β†’ REST endpoints (EstimationController)
β”œβ”€β”€ service/          β†’ Business logic (EstimationService, HuggingFaceService)
β”œβ”€β”€ repository/       β†’ JPA interfaces for persistence
β”œβ”€β”€ entity/           β†’ JPA entities (Estimation)
└── DTO/              β†’ API communication objects (AiEstimationResult, ChatCompletionRequest)

AI Valuation Flow

Client                          Server                          Hugging Face
  β”‚                                β”‚                                β”‚
  │──── POST /api/estimations ────>β”‚                                β”‚
  β”‚                                │──── AI Request ───────────────>β”‚
  β”‚                                β”‚                                β”‚ Llama 3.3-70B
  β”‚                                β”‚<─── JSON Response ─────────────│ processes item
  β”‚                                β”‚                                β”‚
  β”‚                                β”‚  Parse & Validate              β”‚
  β”‚                                β”‚  (or use fallback pricing)     β”‚
  β”‚                                β”‚                                β”‚
  β”‚<─── 200 OK + Estimation ───────│  Save to database             β”‚
  β”‚                                β”‚                                β”‚
  │──── GET /api/estimations ─────>β”‚                                β”‚
  β”‚<─── List of estimations ───────│                                β”‚
  1. Submit Item β€” Client sends item details (name, brand, category, year, condition)
  2. AI Processing β€” API calls Llama 3.3-70B with structured prompt
  3. Price Calculation β€” AI estimates market value or fallback applies condition-based pricing
  4. Storage β€” Estimation saved with description, price, and timestamp
  5. Retrieval β€” Historical estimations can be queried and managed

Endpoints

Estimations

Method Endpoint Description Body Required
POST /api/estimations Create new estimation Yes
GET /api/estimations List all estimations No
GET /api/estimations/{id} Get estimation by ID No
PUT /api/estimations/{id} Update estimation Yes
DELETE /api/estimations/{id} Delete estimation No

Examples

Create Estimation

POST /api/estimations
Content-Type: application/json

{
  "itemName": "iPhone 14 Pro",
  "brand": "Apple",
  "category": "Smartphone",
  "year": 2022,
  "conditionRating": 8
}

Response

{
  "id": 1,
  "itemName": "iPhone 14 Pro",
  "brand": "Apple",
  "category": "Smartphone",
  "year": 2022,
  "conditionRating": 8,
  "estimatedPrice": 400.00,
  "aiDescription": "iPhone 14 Pro from 2022 in very good condition (8/10). This model retains strong resale value in the European market with its A16 chip and advanced camera system.",
  "createdAt": "2026-02-13T08:30:15.123456"
}

Get All Estimations

GET /api/estimations

Response

[
  {
    "id": 1,
    "itemName": "iPhone 14 Pro",
    "estimatedPrice": 400.00,
    "createdAt": "2026-02-13T08:30:15.123456",
    ...
  },
  {
    "id": 2,
    "itemName": "MacBook Pro",
    "estimatedPrice": 680.00,
    "createdAt": "2026-02-13T08:25:10.654321",
    ...
  }
]

Update Estimation

PUT /api/estimations/1
Content-Type: application/json

{
  "itemName": "iPhone 14 Pro Max",
  "brand": "Apple",
  "category": "Smartphone",
  "year": 2022,
  "conditionRating": 9,
  "estimatedPrice": 500.00,
  "aiDescription": "Updated description"
}

Delete Estimation

DELETE /api/estimations/1

AI Pricing Logic

Llama 3.3-70B Integration

  • Natural language prompts with European market context
  • Structured JSON output parsing
  • Markdown cleanup and validation
  • Timeout handling (15s connection, 30s read)
  • Pricing in EUR (€) for European market

Fallback Pricing (when AI unavailable)

Base Prices by Category (EUR):

Product Category Base Price (EUR)
iPhone 15/16 €650
iPhone 14 €500
iPhone 13 €380
iPhone 12 €280
iPhone 11 €200
iPhone X/10 €170
Samsung Galaxy S23/24 €470
Samsung Galaxy S22/21 €320
MacBook Pro €850
MacBook Air €550
iPad Pro €470
iPad Air €280
Generic Laptop €370
Generic Tablet €180
Smartwatch €230
AirPods €90
Gaming Console €320

Condition Multiplier:

Final Price = Base Price Γ— (Condition Rating / 10)

Example:
iPhone 14 (base: €500) with condition 8/10
= €500 Γ— 0.8 = €400.00

Installation

Prerequisites

# Java 17+
java -version

# Maven
mvn -version

# PostgreSQL running on localhost:5432

Setup

# Clone the project
git clone <repo-url>
cd smart-valuator-api

# Configure database
# Edit src/main/resources/application.properties:
spring.datasource.url=jdbc:postgresql://localhost:5432/smartvaluator
spring.datasource.username=your_username
spring.datasource.password=your_password

# Set Hugging Face API key as environment variable
export HF_API_KEY=your_huggingface_api_key

# Build
mvn clean compile

# Run tests
mvn test

# Run the project
mvn spring-boot:run

API available at: http://localhost:8080


Configuration

application.properties

# Database
spring.datasource.url=jdbc:postgresql://localhost:5432/smartvaluator
spring.datasource.username=smartvaluator
spring.datasource.password=smartvaluator
spring.jpa.hibernate.ddl-auto=update

# Hugging Face API β€” set HF_API_KEY as an environment variable
hf.api.key=${HF_API_KEY}

# Server (default port)
server.port=8080

# CORS is enabled globally via @CrossOrigin on EstimationController

Database Schema

CREATE TABLE estimations (
    id SERIAL PRIMARY KEY,
    item_name VARCHAR(255) NOT NULL,
    brand VARCHAR(100),
    category VARCHAR(100),
    year INTEGER NOT NULL,
    condition_rating INTEGER CHECK (condition_rating BETWEEN 1 AND 10),
    estimated_price NUMERIC(10,2),
    ai_description TEXT,
    created_at TIMESTAMP DEFAULT NOW()
);

Error Handling

AI Service Failures

// Automatic fallback to market-based pricing
if (aiResponse.equals("API_ERROR")) {
    return createFallbackResult(productDetails);
}

Network Timeouts

// Configured timeouts prevent hanging
factory.setConnectTimeout(15000); // 15s
factory.setReadTimeout(30000);    // 30s

Price Validation

// Ensures price is never null or zero
if (price == null || price.compareTo(BigDecimal.ZERO) == 0) {
    price = estimateFallbackPrice(productDetails);
}

Developer Notes

  • BigDecimal is used for all monetary values to ensure precision
  • EUR (€) is the currency for all prices (European market)
  • LocalDateTime is serialized in ISO-8601 format for frontend compatibility
  • tools.jackson (Jackson 3.x) is used for JSON processing in Spring Boot 4
  • Fallback pricing ensures the system works even without AI connectivity
  • Condition rating (1-10) directly affects final price estimation
  • AI descriptions provide natural language context for valuations in European market context
  • All timestamps are automatically generated via @PrePersist
  • CORS is configured to allow frontend access from localhost:4200
  • Prices are adjusted for European market (approx. 0.92x USD β†’ EUR conversion)

Testing Flow

  1. Start PostgreSQL database
  2. Configure API key in application.properties
  3. Run the application: mvn spring-boot:run
  4. Test with Postman or integrated frontend:
    • Create estimation β†’ Verify AI description and price
    • List estimations β†’ Check historical data
    • Update estimation β†’ Modify values
    • Delete estimation β†’ Clean up data

Future Enhancements

  • User authentication and authorization
  • Multiple AI model support
  • Image upload for item photos
  • Price history tracking over time
  • Market trend analysis
  • Export estimations to PDF/Excel
  • Email notifications for price changes
  • Mobile app integration

Personal project β€” Educational purpose β€” No restrictive licenses

About

Backend Spring Boot for Smart Valuator, an AI chatbot that provides detailed and natural descriptions of electronic items and gives an estimated profitability based on the year of manufacture and item condition.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages