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.

The SmartStock360 Spring Boot backend is the central orchestration layer of the platform. It exposes a REST API that serves the product catalog from MySQL and transparently proxies demand-prediction requests to the Python FastAPI AI service — so frontend clients only ever talk to a single backend host on port 8080.

What the Service Does

The Spring Boot service is responsible for two core concerns:
  • Product catalog management — reads the producto table from MySQL via JPA/Hibernate and returns all records through a GET /api/productos endpoint.
  • AI prediction proxy — accepts a JSON payload at POST /api/productos/predict, forwards it unchanged to the Python FastAPI service running at http://127.0.0.1:8001/predict/smart-stock, and streams the AI response back to the caller.
This separation lets you swap or scale the AI backend independently without touching client code.

Prerequisites

Before starting, make sure the following tools are installed and available on your PATH:

Java 21

The service targets Java 21 (LTS). Check your version with java -version.

Maven 3.9+

The project ships with the Maven Wrapper (mvnw), so a system Maven is optional but recommended.
A running MySQL 8+ instance and a running Python FastAPI AI service are also required before the application will function fully. See Database Configuration and the Python setup guide for details.

Dependencies

The pom.xml declares the following key dependencies under the spring-boot-starter-parent BOM at version 4.1.0:
DependencyPurpose
spring-boot-starter-webmvcEmbedded Tomcat + Spring MVC for REST endpoints
spring-boot-starter-data-jpaJPA/Hibernate + Spring Data repositories
mysql-connector-jMySQL JDBC driver (runtime scope)
lombokBoilerplate reduction (@Data, getters/setters)
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>4.1.0</version>
</parent>

<properties>
    <java.version>21</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webmvc</artifactId>
    </dependency>
    <dependency>
        <groupId>com.mysql</groupId>
        <artifactId>mysql-connector-j</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

Building and Running

1

Navigate to the project directory

All Maven commands must be run from inside the smartstock directory, where pom.xml lives.
cd smartstock
2

Build the project

Run the full build lifecycle to compile sources, process annotations (Lombok), and package the JAR.
./mvnw clean install
The first run downloads dependencies from Maven Central; subsequent runs use the local cache.
3

Start the application

Launch the embedded Tomcat server. The application listens on port 8080 by default.
./mvnw spring-boot:run
You should see a Spring Boot banner followed by a line similar to:
Tomcat started on port 8080 (http) with context path '/'
4

Verify the service is running

Make a quick health check against the product listing endpoint:
curl http://localhost:8080/api/productos
A JSON array (empty [] or with seeded rows) confirms the service is up and connected to MySQL.
The Python AI service must be running at http://127.0.0.1:8001 before you call POST /api/productos/predict. If the Python process is not started, Spring Boot will throw a connection-refused error and return a 500 response to the client.

Project Structure

The source tree follows standard Spring Boot package-by-layer conventions:
smartstock/
├── src/main/java/com/smartstock/
│   ├── SmartstockApplication.java          # Application entry point
│   ├── controller/
│   │   └── ProductoController.java         # REST endpoints (@RequestMapping "/api/productos")
│   ├── service/
│   │   └── ProductoService.java            # Business logic + RestTemplate proxy
│   ├── entity/
│   │   └── Producto.java                   # JPA entity mapped to "producto" table
│   ├── dto/
│   │   └── PredictDto.java                 # Request body for predict endpoint
│   └── repository/
│       └── ProductoRepository.java         # Spring Data JPA repository
├── src/main/resources/
│   └── application.properties              # Datasource + Hibernate settings
└── pom.xml

Application Entry Point

The application boots through the standard @SpringBootApplication entry point, which triggers component scanning, auto-configuration, and the embedded Tomcat startup:
package com.smartstock;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SmartstockApplication {

    public static void main(String[] args) {
        SpringApplication.run(SmartstockApplication.class, args);
    }
}

CORS Configuration

The ProductoController is annotated with @CrossOrigin(origins = "*"), which instructs Spring MVC to include permissive CORS response headers for every request to /api/productos:
@RestController
@RequestMapping("/api/productos")
@CrossOrigin(origins = "*")
public class ProductoController { ... }
origins = "*" is convenient during local development because it lets the browser-based frontend (served from any port) call the Spring backend without a proxy. Restrict this to specific origins before deploying to production.

Build docs developers (and LLMs) love