Skip to main content

Quickstart

Get the Sales Management System API up and running in just a few minutes.
1

Prerequisites

Before you begin, ensure you have the following installed:
  • Node.js (v14 or higher)
  • MySQL (v5.7 or higher)
  • npm or yarn package manager
2

Clone and Install

Clone the repository and install dependencies:
git clone <repository-url>
cd sistema-de-gestion-de-ventas
npm install
The project uses these core dependencies:
  • express (v5.2.1) - Web framework
  • mysql2 (v3.17.3) - MySQL client
  • zod (v4.3.6) - Schema validation
3

Setup Database

Create and configure the MySQL database:
CREATE DATABASE erpDB;
USE erpDB;

CREATE TABLE categories (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL UNIQUE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE clients(
    id BINARY(16) PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    email VARCHAR(150) NOT NULL UNIQUE
);

CREATE TABLE products (
    id BINARY(16) PRIMARY KEY,
    name VARCHAR(150) NOT NULL,
    description TEXT,
    price DECIMAL(10,2) NOT NULL,
    stock INT NOT NULL DEFAULT 0,
    category_id INT,
    is_deleted BOOLEAN DEFAULT FALSE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    FOREIGN KEY (category_id) REFERENCES categories(id)
);

CREATE TABLE sales (
    id BINARY(16) PRIMARY KEY,
    clients_id BINARY(16) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (clients_id) REFERENCES clients(id)
);

CREATE TABLE sale_details (
    id BINARY(16) PRIMARY KEY,
    sale_id BINARY(16) NOT NULL,
    product_id BINARY(16) NOT NULL,
    quantity INT NOT NULL,
    FOREIGN KEY (sale_id) REFERENCES sales(id) ON DELETE CASCADE,
    FOREIGN KEY (product_id) REFERENCES products(id)
);
The complete schema is available in src/model/database.sql
4

Configure Environment

Update the database configuration in src/config.js:
export default {
    PORT: 3000,
    HOST_DATABASE: "localhost",
    PORT_DATABASE: 3306,
    DATABASE_NAME: "erpDB",
    PASSWORD_DATABASE: "your_password",
    USER_DATABASE: "root"
}
Replace your_password with your actual MySQL password. Never commit credentials to version control.
5

Start the Server

Run the development server:
npm run dev
You should see:
Server on port http://localhost:3000
6

Make Your First Request

Test the API by creating a category and a product:Create a category:
curl -X POST http://localhost:3000/categories \
  -H "Content-Type: application/json" \
  -d '{"name":"bebidas"}'
Response:
{
  "error": false,
  "msg": "categorie was created sucessfully"
}
Create a product:
curl -X POST http://localhost:3000/products \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Coca Cola",
    "description": "Bebida gasificada de 2ltr",
    "stock": 40,
    "price": 3000,
    "categoriesID": 1
  }'
Response:
{
  "error": false,
  "msg": "Product was created successfully"
}

Next Steps

API Reference

Explore all available endpoints

Database Schema

Learn about the database structure

Architecture

Understand the system design

Error Handling

Handle errors gracefully

Build docs developers (and LLMs) love