Backend service for managing sales data and generating insights, based on the project PRD (Sales Insights Backend PRD.pdf).
Production API: https://sales-insight-backend-7j96.onrender.com
- API Base URL:
https://sales-insight-backend-7j96.onrender.com - Interactive API Docs: https://sales-insight-backend-7j96.onrender.com/docs
- ReDoc Documentation: https://sales-insight-backend-7j96.onrender.com/redoc
- Framework: FastAPI
- ORM: SQLAlchemy 2.0 (async)
- Validation: Pydantic v2
- Database:
- Development: SQLite (via aiosqlite)
- Production: PostgreSQL (via asyncpg)
app/main.py– FastAPI application instance and root routeapp/database.py– SQLAlchemy async engine and session factoryapp/models/– ORM models (Sale model implemented)app/schemas/– Pydantic schemas for validation and serializationapp/routes/– API routers for sales CRUD operationsapp/services/– Business logic and database operationsapp/utils/– Shared utility functions
- Navigate to project directory:
cd sales_insight- Create virtual environment (optional but recommended):
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate- Install dependencies:
pip install -r requirements.txtStart the development server:
uvicorn app.main:app --reloadThe server will start on http://127.0.0.1:8000
Local Development:
curl http://localhost:8000/Production:
curl https://sales-insight-backend-7j96.onrender.com/Expected response:
{"message": "Sales Insights Backend Running"}FastAPI automatically generates interactive API documentation:
Local Development:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Production:
- Swagger UI: https://sales-insight-backend-7j96.onrender.com/docs
- ReDoc: https://sales-insight-backend-7j96.onrender.com/redoc
These pages show all available endpoints, request/response schemas, and allow you to test APIs directly from the browser.
Create a Sale (Production):
curl -X POST https://sales-insight-backend-7j96.onrender.com/api/sales \
-H "Content-Type: application/json" \
-d '{
"product_name": "Laptop",
"quantity": 2,
"price": 999.99,
"sale_date": "2024-11-27"
}'List All Sales:
curl https://sales-insight-backend-7j96.onrender.com/api/salesThe database file sales_insights.db will be created automatically when the server starts. You can verify it exists:
ls -lh sales_insights.dbTo inspect the database structure (optional):
sqlite3 sales_insights.db ".schema sales"Completed:
- Project structure setup
- Database configuration (SQLAlchemy 2.0 async) with PostgreSQL support
- Sale model with all fields, constraints, and indexes
- Pydantic schemas (SaleCreate, SaleUpdate, SaleResponse)
- Complete CRUD API routes for sales management
- Service layer for business logic
- Health check endpoint
- Deployed to Render - Production API live at https://sales-insight-backend-7j96.onrender.com
All endpoints are prefixed with /api/sales:
POST /api/sales- Create a new saleGET /api/sales- List all sales (with optional filters:start_date,end_date,product_name)GET /api/sales/{sale_id}- Get a specific sale by IDPUT /api/sales/{sale_id}- Update a saleDELETE /api/sales/{sale_id}- Delete a sale
This application is deployed on Render:
- Service: sales-insight-backend-7j96.onrender.com
- Database: PostgreSQL (automatically configured via Render)
- Auto-deploy: Enabled on push to
mainbranch
For detailed deployment instructions, see DEPLOYMENT.md.
- The
--reloadflag enables auto-reload on code changes - Check the terminal for startup logs and any errors
- Database tables are created automatically on first startup
- Use the
/docsendpoint to explore and test APIs interactively - For production, the app automatically uses PostgreSQL when
DATABASE_URLis set