This is the backend service for the IoT-Lock system, acting as the middle layer between:
- Raspberry Pi (IoT device) → captures faces / events
- Mobile App (React Native) → receives notifications, manages access
- Backend (FastAPI + PostgreSQL) → handles APIs, face recognition, notifications, and database
IOT-LOCK-BACKEND/
│── .gitignore
│── requirements.txt
│── README.md
│── alembic.ini # (if using migrations)
│
├── app/
│ ├── main.py # FastAPI entrypoint (server)
│ │
│ ├── api/ # REST API endpoints
│ ├── core/ # configs, logger, security
│ ├── db/ # database models + session
│ ├── ml/ # ML models (face detection)
│ │ ├── face_recog.py # prediction functions
│ │ ├── train_faces.py # training script
│ │ └── data/ # trained models (face_trained.yml, people.npy)
│ ├── notifications/ # push notification logic
│ └── schemas/ # Pydantic request/response models
│
├── migrations/ # Alembic migration scripts
├── tests/ # Unit tests
└── venv/ # Local virtual environment (not pushed to git)
git clone https://github.com/Eahtasham/iot-lock-backend.git
cd iot-lock-backendpython -m venv venvActivate it:
-
Windows (PowerShell)
.\venv\Scripts\activate
-
Linux/Mac
source venv/bin/activate
pip install -r requirements.txtuvicorn app.main:app --reload👉 Server will start at: http://127.0.0.1:8000
- Training script:
app/ml/train_faces.py - Trained data: stored in
app/ml/data/face_trained.ymlandpeople.npy - Prediction: handled by
app/ml/face_recog.py
To train model:
python app/ml/train_faces.py-
ORM: SQLAlchemy + Alembic
-
Connection settings are inside
app/core/config.py -
Run migrations:
alembic upgrade head
- Located in
app/notifications/ - Will use Firebase Cloud Messaging (FCM) to push alerts to the mobile app
Run unit tests with:
pytest- REST API endpoints for device, auth, visits, notifications
- Face detection pipeline integration
- Push notification triggers
- DB migrations with Alembic
- Deployment (Docker + server)
✅ With this setup, any team member can:
- Clone repo
- Setup venv + install requirements
- Train ML model (optional)
- Run FastAPI with
uvicorn - Start contributing 🚀