Skip to main content
This guide will walk you through setting up the Furniture Store Backend and making your first API request.
1

Clone the Repository

First, clone the repository to your local machine:
git clone <URL_DEL_REPOSITORIO>
cd backend-muebleria
2

Set Up Virtual Environment

Create and activate a Python virtual environment:
python -m venv venv
venv\Scripts\activate
When activated successfully, you’ll see (venv) at the beginning of your terminal prompt.
3

Install Dependencies

Install all required Python packages:
pip install -r requirements.txt
This will install Flask, SQLAlchemy, and all other dependencies including:
  • Flask 3.1.2
  • Flask-SQLAlchemy 3.1.1
  • Flask-Migrate 4.1.0
  • PyMySQL 1.1.2
  • Flask-WTF 1.2.2
4

Configure Environment Variables

Create a .env file in the root directory by copying the template:
cp .env-template .env
Update the .env file with your database credentials:
.env
FLASK_APP=app.py
FLASK_ENV=development

DB_USER=your_mysql_user
DB_PASSWORD=your_mysql_password
DB_HOST=localhost
DB_PORT=3306
DB_NAME=furniture_store_db
Never commit the .env file to version control. It contains sensitive credentials.
5

Create the Database

Create a MySQL database for the application:
CREATE DATABASE furniture_store_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
You can run this in your MySQL client or command line:
mysql -u root -p -e "CREATE DATABASE furniture_store_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
6

Run Database Migrations

Initialize the database schema using Flask-Migrate:
flask db upgrade
This will create all necessary tables including:
  • colors - Color catalog
  • wood_types - Wood type catalog
  • furniture_types - Furniture type catalog
  • roles - User roles
  • unit_of_measures - Units of measurement
7

Start the Development Server

Run the Flask application:
python run.py
Or using Flask CLI:
flask run
You should see output indicating the server is running:
Database connection successful!
 * Running on http://127.0.0.1:5000
The application includes a database connection test on startup to verify your configuration.
8

Make Your First API Request

Now let’s create a color in the catalog. Open a new terminal and use curl:
curl -X POST http://127.0.0.1:5000/colors/create \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "name=Natural"
You can also view the list of colors by visiting:
curl http://127.0.0.1:5000/colors/
Or open in your browser: http://127.0.0.1:5000/colors/

Next Steps

Congratulations! You’ve successfully set up the Furniture Store Backend. Here’s what you can explore next:

API Reference

Explore all available endpoints and their parameters

Architecture

Learn about the MVC layered architecture

Models

Understand the database schema and models

Development Guide

Best practices and coding conventions

Understanding the Code

The color creation request you just made flows through these layers:
app/catalogs/colors/routes.py
@colors_bp.route("/create", methods=["GET", "POST"])
def create_color():
    form = ColorForm()
    
    if form.validate_on_submit():
        data = {"name": form.name.data}
        try:
            ColorService.create(data)
            flash("Color creado exitosamente", "success")
            return redirect(url_for("colors.create_color"))
        except ConflictError as e:
            flash(e.message, "error")
    
    return render_template("colors/create.html", form=form)
The ColorService.create() method handles the business logic:
app/catalogs/colors/services.py
@staticmethod
def create(data: dict) -> dict:
    name = data.get("name")
    
    if not name or not name.strip():
        raise ValidationError("El nombre del color es requerido")
    
    name = name.strip()
    
    # Check for duplicates
    existing = Color.query.filter(func.lower(Color.name) == name.lower()).first()
    if existing:
        raise ConflictError(f"Ya existe un color con el nombre '{name}'")
    
    color = Color(name=name)
    db.session.add(color)
    db.session.commit()
    
    return color.to_dict()

Troubleshooting

Verify your .env file has correct database credentials and that MySQL is running:
mysql -u your_user -p -e "SELECT 1;"
Ensure your virtual environment is activated and dependencies are installed:
pip install -r requirements.txt
If migrations fail, ensure the database exists and is accessible:
flask db current

Build docs developers (and LLMs) love