Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/JoseOlivares19/Proyecto-PC3-JavaScript-Avanzado/llms.txt

Use this file to discover all available pages before exploring further.

SmartStock360 uses a MySQL database named smartstock to persist the product catalog. Spring Boot connects through a standard JDBC datasource, and Hibernate manages the table schema automatically — so you never have to write DDL statements by hand. This page walks through creating the database, understanding the configuration properties, and seeding initial product data.

Prerequisites

MySQL 8+

A locally running MySQL instance accessible on localhost:3306. Create a user with full privileges on the smartstock schema.

Spring Boot Backend

The application reads application.properties at startup. Make sure the file is in place before running ./mvnw spring-boot:run.

Application Properties

The datasource and JPA settings live in src/main/resources/application.properties. The full file used by SmartStock360 is:
spring.datasource.url=jdbc:mysql://localhost:3306/smartstock
spring.datasource.username=root
spring.datasource.password=your_password_here
spring.jpa.hibernate.ddl-auto=update
Never commit real database passwords to version control. Replace your_password_here with a strong, unique credential and consider externalising secrets via environment variables (SPRING_DATASOURCE_PASSWORD) or a secrets manager before any deployment beyond your local machine.
PropertyValuePurpose
spring.datasource.urljdbc:mysql://localhost:3306/smartstockJDBC connection URL pointing to the smartstock schema
spring.datasource.usernamerootMySQL user (change for non-local environments)
spring.datasource.passwordyour_password_hereMySQL password for the above user
spring.jpa.hibernate.ddl-autoupdateHibernate auto-creates or alters tables on startup to match entity definitions
ddl-auto=update is safe for development: Hibernate adds missing columns and creates missing tables but never drops existing columns or data. For a clean schema reset, use create-drop during early prototyping, or manage migrations with Flyway/Liquibase in production.

Creating the Database

Before starting the Spring Boot service for the first time, create the smartstock schema in MySQL. Connect to your MySQL server and run:
CREATE DATABASE smartstock;
Hibernate will automatically create the producto table the first time the application boots, based on the Producto entity definition.

The Producto Entity and Table Schema

The Producto JPA entity is annotated with @Entity, which maps the Java class to a MySQL table named producto (Hibernate’s default lowercase naming). All fields map to columns of the same name using Hibernate’s default CamelCase → snake_case column naming strategy.
@Entity
@Data
public class Producto {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String nombre;
    private Double precio;
    private Integer stockActual;
    private Integer ventas7d;
    private Integer descuentoPct;
    private Integer temporada;
    private Integer diasSinReabastecer;
    private Double ratingProducto;
}
The resulting table schema that Hibernate generates is:
ColumnMySQL TypeConstraintsDescription
idBIGINTPRIMARY KEY, AUTO_INCREMENTSurrogate primary key
nombreVARCHAR(255)Product display name
precioDOUBLEUnit price
stock_actualINTCurrent units in stock
ventas_7dINTUnits sold in the last 7 days
descuento_pctINTActive discount percentage (0–100)
temporadaINTSeason code: 0 = normal, 1 = campaign, 2 = holiday/high demand
dias_sin_reabastecerINTDays elapsed since last restock
rating_productoDOUBLEAverage customer rating (0.0–5.0)
The temporada column drives the AI model’s demand seasonality weighting. Products with temporada = 2 (holiday/high demand) typically receive higher predicted demand and lower restock thresholds.

Seeding Product Data

After the schema is created you can populate the table with representative products using standard SQL INSERT statements. Connect to the smartstock database and run your seeds:
-- High-demand sporting goods in a holiday season
INSERT INTO producto (nombre, precio, stock_actual, ventas_7d, descuento_pct, temporada, dias_sin_reabastecer, rating_producto)
VALUES ('Zapatillas Deportivas', 129.90, 80, 420, 20, 2, 18, 4.6);

-- Mid-range electronics, normal season
INSERT INTO producto (nombre, precio, stock_actual, ventas_7d, descuento_pct, temporada, dias_sin_reabastecer, rating_producto)
VALUES ('Auriculares Bluetooth', 59.90, 150, 210, 10, 0, 5, 4.2);

-- Clearance item with heavy discount
INSERT INTO producto (nombre, precio, stock_actual, ventas_7d, descuento_pct, temporada, dias_sin_reabastecer, rating_producto)
VALUES ('Mochila Urbana', 45.00, 30, 95, 35, 1, 30, 3.9);
Because id is an AUTO_INCREMENT primary key, you do not need to supply it in INSERT statements — MySQL assigns the next available integer automatically.

Verifying the Connection

Once the application is running, you can confirm the datasource is healthy by hitting the product listing endpoint:
curl http://localhost:8080/api/productos
A successful response returns a JSON array of all rows in the producto table. If you receive a 500 error, check:
  1. MySQL is running and reachable on localhost:3306.
  2. The smartstock schema exists.
  3. The username and password in application.properties are correct.
  4. The Spring Boot logs for any HikariCP or Hibernate connection errors.

Build docs developers (and LLMs) love