Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

GhandyP/basic_shop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tienda Backend for Koyeb Deployment

This is a Flask-based backend for a store management system with PostgreSQL database, configured for deployment on Koyeb.

Features

  • Product management (CRUD operations)
  • Sales registration with stock control
  • Expense tracking
  • Reporting features (sales, profits)
  • RESTful API design

Tech Stack

  • Python 3.10+
  • Flask
  • SQLAlchemy ORM
  • PostgreSQL
  • Flask-Migrate for database migrations
  • Flask-CORS for cross-origin requests

Setup for Local Development

  1. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  2. Install dependencies:

    pip install -r requirements.txt
  3. Set up environment variables in a .env file:

    DATABASE_URL=postgresql://tienda_user:your_password@localhost:5432/tienda_db
    FLASK_ENV=development
    SECRET_KEY=your-secret-key-for-development
  4. Initialize the database:

    flask db upgrade
  5. Run the application:

    python app.py

The API will be available at http://localhost:5000.

API Endpoints

Products

  • GET /api/productos - Get all products
  • POST /api/productos - Create a new product

Sales

  • POST /api/ventas - Register a new sale

Reports

  • GET /api/reportes/ventas - Get sales report (optional date filters)
  • GET /api/reportes/ganancias - Get profit report

Database Models

  1. Producto - Store products with name, price, and stock
  2. Venta - Sales records with date and total amount
  3. VentaProducto - Junction table for sales and products with quantities
  4. Gasto - Expense tracking with description and amount

Deployment on Koyeb

  1. Create a Koyeb account at koyeb.com
  2. Connect your GitHub account to Koyeb
  3. 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: production
      • SECRET_KEY: A long random string for security
      • DATABASE_URL: Your PostgreSQL connection string
  4. If you don't have a PostgreSQL database, you can create one on Koyeb or use an external provider like Supabase or Render PostgreSQL.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages