Welcome to the Python Developers Hackathon. Build a retail store application using Python/FastAPI (or Flask) for the backend, React for the frontend, and SQLite for the database.
Prerequisites:
- Python 3.9+
- Node.js (v18 or later) for React frontend
- VS Code or PyCharm
- GitHub Copilot extension (recommended)
- Git installed locally
Recommended VS Code Extensions:
- Python
- Pylance
- GitHub Copilot
- ES7+ React/Redux/React-Native snippets
- SQLite Viewer
git clone https://github.com/hosseinzahed/demant-github-hackathon.git
cd demant-github-hackathon
git checkout -b team1 # Replace 'team1' with your team namepython --version # Should show 3.9 or later
# or
python3 --version# Create project directory
mkdir retail-store-api
cd retail-store-api
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
# Install required packages
pip install fastapi uvicorn sqlalchemy pydantic python-multipart
# For Excel/PDF export
pip install openpyxl reportlab pandas
# For CORS
pip install fastapi[all]
# Create requirements.txt
pip freeze > requirements.txt# Create project directory
mkdir retail-store-api
cd retail-store-api
# Create virtual environment
python -m venv venv
# Activate virtual environment
venv\Scripts\activate # Windows
# source venv/bin/activate # macOS/Linux
# Install required packages
pip install flask flask-sqlalchemy flask-cors
# For Excel/PDF export
pip install openpyxl reportlab pandas
pip freeze > requirements.txt# In the project root directory
npx create-react-app retail-store-ui
cd retail-store-ui
# Install additional packages
npm install axios react-router-domBuild a web application for managing customers, products, and purchase orders.
Tech Stack:
- Backend: FastAPI or Flask
- Frontend: React
- Database: SQLite with SQLAlchemy ORM
- ORM: SQLAlchemy
- React-based SPA (Single Page Application)
- Intuitive and user-friendly design
- Responsive layout
- Model Properties: id, name, surname, address, birth_date, email
- CRUD operations (Create, Read, Update, Delete)
- Email validation
- RESTful API endpoints
- Model Properties: id, name, description, price
- CRUD operations
- Search functionality by id and name
- RESTful API endpoints
- Model Properties: id, order_number, purchase_date, customer_id, product_ids
- CRUD operations
- Search by order_number and customer name
- RESTful API endpoints
- Export customers to Excel and PDF
- Export purchase orders to Excel and PDF
retail-store-api/
βββ app/
β βββ __init__.py
β βββ main.py
β βββ models.py
β βββ schemas.py
β βββ database.py
β βββ routers/
β β βββ __init__.py
β β βββ customers.py
β β βββ products.py
β β βββ orders.py
β βββ services/
β βββ export_service.py
βββ requirements.txt
βββ retailstore.db (created automatically)
retail-store-api/
βββ app/
β βββ __init__.py
β βββ models.py
β βββ routes.py
β βββ database.py
β βββ services/
β βββ export_service.py
βββ run.py
βββ requirements.txt
βββ retailstore.db (created automatically)
retail-store-ui/
βββ src/
β βββ components/
β β βββ Customers/
β β βββ Products/
β β βββ Orders/
β βββ services/
β β βββ api.js
β βββ App.js
β βββ index.js
βββ package.json
FastAPI Example (database.py):
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
SQLALCHEMY_DATABASE_URL = "sqlite:///./retailstore.db"
engine = create_engine(
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()# Install testing packages
pip install pytest pytest-cov httpx
# For FastAPI
pip install pytest-asyncio
# Create tests directory
mkdir testsTest Structure:
tests/
βββ __init__.py
βββ test_customers.py
βββ test_products.py
βββ test_orders.py
Test Coverage:
- Unit tests for API endpoints
- Model validation tests
- Database operation tests
# In retail-store-ui directory
npm install --save-dev @testing-library/react @testing-library/jest-domRun Tests:
# Backend
pytest --cov=app tests/
# Frontend
cd retail-store-ui
npm testCreate .github/workflows/python-ci.yml:
name: Python CI
on:
push:
branches: [ main, team* ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
cd retail-store-api
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest pytest-cov
- name: Run tests
run: |
cd retail-store-api
pytest --cov=app tests/
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install frontend dependencies
run: |
cd retail-store-ui
npm ci
- name: Build frontend
run: |
cd retail-store-ui
npm run build
- name: Test frontend
run: |
cd retail-store-ui
npm test -- --watchAll=falseCreate DOCS.md including:
- Application architecture overview
- Tech stack: FastAPI/Flask + React + SQLite
- Database schema (ER diagram)
- API endpoints documentation (use FastAPI's automatic Swagger docs at
/docs) - Setup and installation steps
- Virtual environment setup
- Build commands
- Test commands:
pytest,npm test - Run commands:
uvicorn app.main:app --reloadorpython run.py,npm start
- "Create a FastAPI project structure with SQLAlchemy"
- "Set up Flask application with SQLAlchemy and SQLite"
- "Configure CORS for React frontend in FastAPI"
- "Generate a Customer SQLAlchemy model with id, name, surname, address, birth_date, email"
- "Create a Product model using SQLAlchemy with id, name, description, price"
- "Generate a PurchaseOrder model with relationships to Customer and Products in SQLAlchemy"
- "Create database initialization script for SQLAlchemy models"
- "Generate Pydantic schemas for Customer model with validation"
- "Create Pydantic schema for Product with price validation"
- "Add email validation to Customer Pydantic schema"
- "Generate FastAPI router for Customer CRUD operations"
- "Create Flask routes for Product management with GET, POST, PUT, DELETE"
- "Add search endpoint for products by id and name in FastAPI"
- "Generate async CRUD endpoints for PurchaseOrder in FastAPI"
- "Add email validation to Customer model using Pydantic validators"
- "Implement input validation for Product price field"
- "Implement Excel export for Customer list using openpyxl"
- "Generate PDF report for purchase orders using reportlab"
- "Create an export service class for data export to Excel and PDF"
- "Create a React component for displaying customer list"
- "Generate a form component for adding/editing customers with validation"
- "Create an axios service for API calls to FastAPI backend"
- "Build a product search component with React hooks"
- "Generate pytest tests for Customer API endpoints"
- "Create unit tests for Product model validation"
- "Write integration tests for FastAPI endpoints with TestClient"
- "Generate pytest fixtures for database testing"
- "Create a GitHub Actions workflow for Python FastAPI application with pytest"
- "Add React build steps to GitHub Actions workflow"
cd retail-store-api
source venv/bin/activate # or venv\Scripts\activate on Windows
uvicorn app.main:app --reload
# API will be available at http://localhost:8000
# API docs at http://localhost:8000/docscd retail-store-api
source venv/bin/activate # or venv\Scripts\activate on Windows
python run.py
# API will be available at http://localhost:5000cd retail-store-ui
npm start
# React app will be available at http://localhost:3000π‘Tips:
- Use GitHub Copilot Chat to explain SQLAlchemy relationships
- Ask Copilot to help debug CORS issues between React and FastAPI/Flask
- Request code reviews and optimization suggestions
- Use Copilot to generate sample data seeders
- Take advantage of FastAPI's automatic API documentation at
/docs