This is a Flask-based backend for a store management system with PostgreSQL database, configured for deployment on Koyeb.
- Product management (CRUD operations)
- Sales registration with stock control
- Expense tracking
- Reporting features (sales, profits)
- RESTful API design
- Python 3.10+
- Flask
- SQLAlchemy ORM
- PostgreSQL
- Flask-Migrate for database migrations
- Flask-CORS for cross-origin requests
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables in a
.envfile:DATABASE_URL=postgresql://tienda_user:your_password@localhost:5432/tienda_db FLASK_ENV=development SECRET_KEY=your-secret-key-for-development
-
Initialize the database:
flask db upgrade
-
Run the application:
python app.py
The API will be available at http://localhost:5000.
GET /api/productos- Get all productsPOST /api/productos- Create a new product
POST /api/ventas- Register a new sale
GET /api/reportes/ventas- Get sales report (optional date filters)GET /api/reportes/ganancias- Get profit report
- Producto - Store products with name, price, and stock
- Venta - Sales records with date and total amount
- VentaProducto - Junction table for sales and products with quantities
- Gasto - Expense tracking with description and amount
- Create a Koyeb account at koyeb.com
- Connect your GitHub account to Koyeb
- Create a new Web Service:
- Select your repository
- Set the build command to:
pip install -r requirements.txt - Set the run command to:
gunicorn --bind 0.0.0.0:$PORT app:app - Add environment variables:
FLASK_ENV:productionSECRET_KEY: A long random string for securityDATABASE_URL: Your PostgreSQL connection string
- If you don't have a PostgreSQL database, you can create one on Koyeb or use an external provider like Supabase or Render PostgreSQL.