Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/JFKoryy/autopart-pro/llms.txt

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

This guide walks you through every step required to run AutoPart Pro on your local machine — from cloning the repository to making your first authenticated API call. The entire process takes under 10 minutes on a machine that already has Node.js and MySQL installed.
AutoPart Pro enforces CORS at the server level. By default, only http://localhost:5173 and http://192.168.1.165:5173 are listed as allowed origins in backend/src/app.js. If you access the frontend from any other origin — including a different port or a remote IP — the browser will block API requests with a CORS error. Update the origin array in app.js and restart the backend server if you need to allow additional origins.
1

Prerequisites

Before you begin, make sure the following are installed and accessible on your PATH:
  • Node.js 18 or later — verify with node -v
  • npm (bundled with Node.js) — verify with npm -v
  • MySQL 8 or later — verify with mysql --version
You will also need a running MySQL server with a user that has permission to create databases and tables. The default setup assumes the root user, but any sufficiently privileged account works.
2

Clone the Repository

Clone the AutoPart Pro repository from GitHub and enter the project root:
git clone https://github.com/JFKoryy/autopart-pro.git
cd autopart-pro
The repository contains two top-level directories — backend/ and frontend/ — that are developed and run independently.
3

Set Up the Database

AutoPart Pro ships with a single SQL file that creates the database, all tables, and a test connection record. Run it against your MySQL server:
mysql -u root -p < backend/database.sql
Enter your MySQL root password when prompted. The script creates the autopart_pro database (if it does not already exist) and provisions the following tables:
TablePurpose
usersRegistered users with hashed passwords and an admin | employee | client role
productsParts catalog — SKU, name, brand, compatible vehicles, price, stock, min_stock threshold, category, description, and optional image URL
salesSale header records linked to the purchasing user, with a total and a pending | completed | cancelled status
sale_itemsLine items for each sale — product, quantity, and unit price at time of purchase
A test_connection table is also created and seeded with a single row as a sanity-check that the script ran successfully.
4

Configure the Backend Environment

Create a .env file inside the backend/ directory. This file is read by dotenv at startup and must be present before you start the server:
touch backend/.env
Populate it with the following variables, replacing the placeholder values with your own:
PORT=5000
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_mysql_password
DB_NAME=autopart_pro
JWT_SECRET=your_long_random_secret_key
FRONTEND_URL=http://localhost:5173
See the Environment Variables reference for a full description of every variable and guidance on choosing a secure JWT_SECRET.
5

Install Dependencies and Start the Backend

Install Node.js dependencies and start the Express development server:
cd backend
npm install
npm run dev
npm run dev launches the server with nodemon, so file changes automatically restart the process during development. On a successful start you will see:
🚀 Servidor corriendo en el puerto 5000
Prueba el servidor en: http://localhost:5000/api/health
The backend now listens on port 5000 and exposes the API under the /api prefix.
6

Configure the Frontend Environment

Open a second terminal, return to the project root, and create a .env file inside frontend/:
touch frontend/.env
Add the following variable, pointing the frontend at the local backend:
VITE_API_URL=http://localhost:5000/api
Vite only exposes environment variables prefixed with VITE_ to the browser bundle — any other variables in this file are ignored at build time.
7

Install Dependencies and Start the Frontend

From the frontend/ directory, install dependencies and start the Vite development server:
cd frontend
npm install
npm run dev
Vite starts on port 5173 by default. You will see output similar to:
  VITE v6.x.x  ready in Xms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
Open http://localhost:5173 in your browser to view the AutoPart Pro UI.
8

Verify the Backend is Running

With the backend server running, confirm the health endpoint responds correctly:
curl http://localhost:5000/api/health
Expected response:
{
  "status": "ON",
  "message": "Servidor de AutoPart Pro funcionando correctamente",
  "timestamp": "2025-01-01T00:00:00.000Z"
}
A 200 OK with "status": "ON" confirms that the Express server started successfully and the process is healthy. The timestamp will reflect the current server time.
9

Make Your First Authenticated API Call

AutoPart Pro’s protected endpoints require a Bearer token obtained by logging in. First, register a new user account:
curl -s -X POST http://localhost:5000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Jane Smith",
    "email": "jane@example.com",
    "password": "securepassword123"
  }'
A successful registration returns the new user record. Next, log in to receive a JWT:
curl -s -X POST http://localhost:5000/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "jane@example.com",
    "password": "securepassword123"
  }'
The response includes a token field. Copy that value and use it as a Bearer token to call any protected endpoint — for example, listing all products:
curl -s http://localhost:5000/api/products \
  -H "Authorization: Bearer <your_token_here>"
New users registered through the API are assigned the client role by default. To create an admin or employee account, insert a row directly into the users table (with a bcrypt-hashed password) or promote an existing user through the admin panel once you have an admin account.

Build docs developers (and LLMs) love