A contactless biometric entry/exit system for metro stations, featuring Face Recognition and Bluetooth Low Energy (BLE) beacon detection.
- Dual-Factor Auth: Face Verification (Dlib) + BLE Signal (Phone as Beacon).
- Contactless Entry: No tapping required; just walk through.
- Auto-Fare Calculation: Fare calculated based on Entry and Exit stations (Distance-based).
- Master Controller: Real-time dashboard for station managers (Revenue, Traffic, Alerts).
- Mobile App: React Native (Expo) app for identity management, wallet top-up, and trip history.
graph TD
User[📱 Mobile App] -->|WebSocket| API[Backend API]
User -->|BLE Beacon| Gate[Gate Hardware]
subgraph "Station Hardware"
Gate -->|Camera| CV[Face Rec Engine]
Gate -->|BLE| CV
CV -->|API Key| API
end
subgraph "Cloud / Server"
API -->|Read/Write| DB[(Supabase SQL)]
API -->|Vector Search| Chroma[(ChromaDB)]
Master[🖥️ Master Controller] -->|Stats| API
end
- Python 3.9+
- Node.js 16+ (for App)
- Supabase Account (PostgreSQL)
- Hardware: Webcam + ESP32 (for BLE) (Optional: can be simulated)
Run the following SQL in your Supabase SQL Editor to set up the tables:
-- 1. Profiles (Users)
CREATE TABLE public.profiles (
id uuid NOT NULL,
full_name text,
wallet_balance integer DEFAULT 100,
face_url text,
cypher_id text UNIQUE,
is_flagged boolean DEFAULT false,
created_at timestamp with time zone NOT NULL DEFAULT timezone('utc'::text, now()),
is_enrolled boolean DEFAULT false,
CONSTRAINT profiles_pkey PRIMARY KEY (id)
);
-- 2. Stations (Metadata)
CREATE TABLE public.stations (
id integer NOT NULL DEFAULT nextval('stations_id_seq'::regclass),
name text NOT NULL,
status text DEFAULT 'ACTIVE'::text,
CONSTRAINT stations_pkey PRIMARY KEY (id)
);
-- 3. Trips (History)
CREATE TABLE public.trips (
id uuid NOT NULL DEFAULT gen_random_uuid(),
user_id uuid,
station_name text,
entry_time timestamp with time zone DEFAULT timezone('utc'::text, now()),
exit_time timestamp with time zone,
exit_station text,
fare_charged integer DEFAULT 0,
access_granted boolean DEFAULT true,
status text DEFAULT 'COMPLETED'::text,
CONSTRAINT trips_pkey PRIMARY KEY (id),
CONSTRAINT trips_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.profiles(id)
);
-- Note: Enable RLS (Row Level Security) if deploying to production!cd backend
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txtConfiguration (.env in root):
Create a .env file in the project root:
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SERVICE_KEY=your-service-role-keycd app
npm install
npx expo start- Scan the QR code with Expo Go (Android/iOS).
To make your backend reachable from the internet (for the mobile app):
cloudflared tunnel run --url http://localhost:8000 backendYou will need 3 Terminal Windows:
Authentication, User Management, and Trip Logic.
cd backend
uvicorn main:app --reload --port 8000Real-time stats API. (The UI is now hosted separately).
# In project root
uvicorn master:app --reload --port 8001👉 Open Live Dashboard: https://metro-dashboard-eight.vercel.app/
Simulates the physical gate hardware (Camera + BLE).
To run Exit Gate:
# In project root
source backend/venv/bin/activate
python3 exit.pyTo run Entry Gate:
- Edit
config.py: SetGATE_MODE = "ENTRY" - Run:
# In project root
source backend/venv/bin/activate
python3 main.pyControls hardware settings for the Python scripts.
SERIAL_PORT: Path to ESP32 (e.g.,/dev/cu.usbserial...orCOM3)CAMERA_INDEX: webcam ID (0 or 1)GATE_MODE: "ENTRY" or "EXIT"STATION_NAME: Name of the station (must matchFARE_TABLEinbackend/main.py)
- Gate API Key: Hardcoded in
backend/main.pyand scripts asgk_live_xxxxxxxxxxxxxx. Update this for production. - Supabase Keys: Managed via
.env.
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /gate/access |
Entry gate logic (Check Balance, Record Entry) | Gate Key |
| POST | /gate/exit |
Exit gate logic (Calc Fare, Deduct, Close Trip) | Gate Key |
| GET | /profile |
Get user profile & balance | User JWT |
| GET | /trips |
Get user trip history | User JWT |
| WS | /ws/capture/... |
Face Enrollment Stream | None |
- Camera not opening? Check
config.py→CAMERA_INDEX. - Serial Error? Check if ESP32 is plugged in and
SERIAL_PORTis correct. - "User not found"? Ensure the user is Enrolled in the App and has a
cypher_id. - Supabase Error? Verify
SUPABASE_URLandSUPABASE_SERVICE_KEYin.env.
Built with ❤️ for Metro Gate Systems