Set Up Virtual Environment
Create and activate a Python virtual environment:
When activated successfully, you’ll see
(venv) at the beginning of your terminal prompt.Install Dependencies
Install all required Python packages: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
Configure Environment Variables
Create a Update the
.env file in the root directory by copying the template:.env file with your database credentials:.env
Create the Database
Create a MySQL database for the application:You can run this in your MySQL client or command line:
Run Database Migrations
Initialize the database schema using Flask-Migrate:This will create all necessary tables including:
colors- Color catalogwood_types- Wood type catalogfurniture_types- Furniture type catalogroles- User rolesunit_of_measures- Units of measurement
Start the Development Server
Run the Flask application:Or using Flask CLI:You should see output indicating the server is running:
The application includes a database connection test on startup to verify your configuration.
Make Your First API Request
Now let’s create a color in the catalog. Open a new terminal and use curl:You can also view the list of colors by visiting: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
ColorService.create() method handles the business logic:
app/catalogs/colors/services.py
Troubleshooting
Database connection failed
Database connection failed
Verify your
.env file has correct database credentials and that MySQL is running:ModuleNotFoundError
ModuleNotFoundError
Ensure your virtual environment is activated and dependencies are installed:
Migration errors
Migration errors
If migrations fail, ensure the database exists and is accessible: