Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

SIMPLE DIGITAL KHATA — BACKEND SETUP

1. Navigate to Backend

cd backend

2. Create Virtual Environment

python -m venv venv

3. Activate Virtual Environment

.\venv\Scripts\Activate.ps1

If activation is successful, the terminal should show:

(venv)

4. Install Backend Dependencies

pip install fastapi "uvicorn[standard]" sqlalchemy psycopg pydantic-settings python-dotenv python-multipart

These packages are used for:

  • fastapi → REST API framework
  • uvicorn[standard] → ASGI server
  • sqlalchemy → Database ORM
  • psycopg → PostgreSQL database driver
  • pydantic-settings → .env configuration
  • python-dotenv → Environment variable support
  • python-multipart → File uploads and multipart/form-data

5. Start FastAPI Development Server

python -m uvicorn app.main:app --reload

Backend will run at:

http://127.0.0.1:8000

6. API Documentation

Swagger UI:

http://127.0.0.1:8000/docs

ReDoc:

http://127.0.0.1:8000/redoc

7. Health Checks

API health:

GET /health

Database health:

GET /health/db

Expected responses:

{
  "status": "ok",
  "service": "Simple Digital Khata API"
}

and:

{
  "status": "ok",
  "database": "connected"
}

8. Backend Environment File

Create:

backend/.env

Example:

DATABASE_URL=postgresql+psycopg://postgres:YOUR_PASSWORD@localhost:5432/simpledigitalkhata

Never 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/simpledigitalkhata

9. Backend Project Structure

backend/
│
├── 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

10. Generate Requirements File

After installing all dependencies:

pip freeze > requirements.txt

This allows the backend environment to be reproduced later.

11. Run Backend Again

Whenever you open the project again:

cd backend
.\venv\Scripts\Activate.ps1
uvicorn app.main:app --reload

12. Backend Verification Checklist

BACKEND
[✓] 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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages