cd backendpython -m venv venv.\venv\Scripts\Activate.ps1If activation is successful, the terminal should show:
(venv)
pip install fastapi "uvicorn[standard]" sqlalchemy psycopg pydantic-settings python-dotenv python-multipartThese packages are used for:
fastapi→ REST API frameworkuvicorn[standard]→ ASGI serversqlalchemy→ Database ORMpsycopg→ PostgreSQL database driverpydantic-settings→.envconfigurationpython-dotenv→ Environment variable supportpython-multipart→ File uploads and multipart/form-data
python -m uvicorn app.main:app --reloadBackend will run at:
http://127.0.0.1:8000
Swagger UI:
http://127.0.0.1:8000/docs
ReDoc:
http://127.0.0.1:8000/redoc
API health:
GET /health
Database health:
GET /health/db
Expected responses:
{
"status": "ok",
"service": "Simple Digital Khata API"
}and:
{
"status": "ok",
"database": "connected"
}Create:
backend/.env
Example:
DATABASE_URL=postgresql+psycopg://postgres:YOUR_PASSWORD@localhost:5432/simpledigitalkhataNever commit the actual .env file to GitHub.
Create a safe example file:
backend/.env.example
with:
DATABASE_URL=postgresql+psycopg://postgres:YOUR_PASSWORD@localhost:5432/simpledigitalkhatabackend/
│
├── app/
│ ├── __init__.py
│ ├── main.py
│ │
│ ├── core/
│ │ ├── __init__.py
│ │ ├── config.py
│ │ └── database.py
│ │
│ ├── models/
│ │ ├── __init__.py
│ │ ├── product.py
│ │ ├── customer.py
│ │ ├── bill.py
│ │ ├── bill_item.py
│ │ └── shop_settings.py
│ │
│ ├── schemas/
│ │ ├── __init__.py
│ │ ├── product.py
│ │ ├── customer.py
│ │ ├── bill.py
│ │ ├── settings.py
│ │ └── backup.py
│ │
│ ├── routers/
│ │ ├── __init__.py
│ │ ├── product.py
│ │ ├── customer.py
│ │ ├── bill.py
│ │ ├── settings.py
│ │ └── backup.py
│ │
│ └── services/
│ ├── __init__.py
│ └── bill_service.py
│
├── .env
├── .env.example
└── requirements.txt
After installing all dependencies:
pip freeze > requirements.txtThis allows the backend environment to be reproduced later.
Whenever you open the project again:
cd backend
.\venv\Scripts\Activate.ps1
uvicorn app.main:app --reloadBACKEND
[✓] Python environment
[✓] Virtual environment
[✓] Dependencies
[✓] Environment variables
[✓] PostgreSQL connection
[✓] FastAPI application
[✓] Uvicorn server
[✓] Swagger documentation
[✓] ReDoc documentation
API MODULES
[✓] Products
[✓] Customers
[✓] Bills
[✓] Shop Settings
[✓] Backup Export
[✓] Backup Validation
[✓] Backup Restore
SECURITY
[✓] .env protected
[✓] .gitignore
[✓] CORS
[✓] Safe error handling
DATABASE
[✓] PostgreSQL
[✓] Tables
[✓] Constraints
[✓] Indexes
[✓] Dummy data
[✓] Bill number sequence
[✓] Updated-at trigger
TESTING
[ ] Complete Swagger API testing
[ ] Edge-case testing
[ ] Transaction rollback testing
[ ] Stock deduction testing
[ ] Frontend integration testing