Skip to content

samarth-verma-dev/Vigil-X

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Vigil-X: Smart Campus Access Control System

A Firebase-based access control system for campus security featuring QR code scanning, face-based device binding, role-based authentication, and gate-specific access policies.

πŸ—οΈ Project Structure

sau-vigil/
β”œβ”€β”€ backend/                    # Firebase backend
β”‚   β”œβ”€β”€ functions/             # Cloud Functions
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ index.ts       # Functions entry point
β”‚   β”‚   β”‚   β”œβ”€β”€ scan.ts        # QR scanning logic
β”‚   β”‚   β”‚   β”œβ”€β”€ qr.ts          # QR generation
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.ts        # Authentication
β”‚   β”‚   β”‚   β”œβ”€β”€ guard.ts       # Guard decisions
β”‚   β”‚   β”‚   β”œβ”€β”€ parcels.ts     # Parcel management
β”‚   β”‚   β”‚   β”œβ”€β”€ visitors.ts    # Visitor sessions
β”‚   β”‚   β”‚   β”œβ”€β”€ face.ts        # Face embedding (NEW)
β”‚   β”‚   β”‚   β”œβ”€β”€ seed.ts        # Database seeding
β”‚   β”‚   β”‚   └── middleware/    # Validation middleware
β”‚   β”‚   β”œβ”€β”€ package.json
β”‚   β”‚   └── tsconfig.json
β”‚   β”œβ”€β”€ firebase.json          # Firebase config
β”‚   β”œβ”€β”€ firestore.rules        # Security rules
β”‚   └── firestore.indexes.json # Database indexes
β”‚
β”œβ”€β”€ vigilx/                    # Frontend Expo app
β”‚   β”œβ”€β”€ app/                   # Expo Router screens
β”‚   β”‚   β”œβ”€β”€ (auth)/           # Authentication screens
β”‚   β”‚   β”‚   β”œβ”€β”€ login.tsx
β”‚   β”‚   β”‚   └── face-capture.tsx  # Face registration (NEW)
β”‚   β”‚   β”œβ”€β”€ (student)/        # Student screens
β”‚   β”‚   β”‚   └── qr.tsx        # QR display
β”‚   β”‚   β”œβ”€β”€ (faculty)/        # Faculty screens
β”‚   β”‚   β”‚   └── qr.tsx
β”‚   β”‚   β”œβ”€β”€ (guard)/          # Guard screens
β”‚   β”‚   β”‚   └── scanner.tsx   # QR scanner
β”‚   β”‚   β”œβ”€β”€ (worker)/         # Worker screens (NEW)
β”‚   β”‚   β”‚   └── qr.tsx
β”‚   β”‚   └── (visitor)/        # Visitor screens
β”‚   β”œβ”€β”€ services/             # API & Firebase services
β”‚   β”‚   β”œβ”€β”€ firebase.ts       # Firebase initialization
β”‚   β”‚   └── api.ts            # API service layer
β”‚   β”œβ”€β”€ context/              # React context
β”‚   β”‚   └── AuthContext.tsx   # Auth state management
β”‚   β”œβ”€β”€ components/           # Reusable components
β”‚   β”œβ”€β”€ constants/            # App constants
β”‚   β”œβ”€β”€ hooks/                # Custom hooks
β”‚   β”œβ”€β”€ assets/               # Images, fonts
β”‚   β”œβ”€β”€ package.json
β”‚   └── tsconfig.json
β”‚
β”œβ”€β”€ docs/                      # Documentation
β”‚   β”œβ”€β”€ API.md                # API documentation
β”‚   β”œβ”€β”€ ARCHITECTURE.md       # System architecture
β”‚   β”œβ”€β”€ DEPLOYMENT.md         # Deployment guide
β”‚   β”œβ”€β”€ SECURITY.md           # Security considerations
β”‚   └── TESTING.md            # Testing guide
β”‚
β”œβ”€β”€ .kiro/                    # Kiro spec files
β”‚   └── specs/
β”‚       └── firebase-backend-integration/
β”‚           β”œβ”€β”€ design.md
β”‚           β”œβ”€β”€ requirements.md
β”‚           └── tasks.md
β”‚
└── README.md                 # This file

πŸš€ Features

Core Features

  • QR Code Access Control: Time-limited QR codes with HMAC signatures
  • Face-Based Device Binding: 128-dimensional face embeddings using face-api.js
  • Role-Based Authentication: Student, Faculty, Guard, Worker, Visitor roles
  • Gate-Specific Behavior: Different UI/logic for main gate vs hostel gates
  • Offline Mode: Cached QR codes valid for 5 minutes
  • Worker Subcategories: Mess workers (main gate only), Maintenance workers (all gates)
  • Sub-2-Second Scans: Optimized for fast entry processing
  • Parcel Management: Delivery notifications and tracking

Security Features

  • HMAC-SHA256 signature verification
  • 60-second QR expiry
  • Face embedding verification
  • Device binding
  • Role-based Firestore security rules
  • Privacy-preserving embeddings (not reversible to photos)

πŸ“‹ Prerequisites

  • Node.js 18+
  • Firebase CLI: npm install -g firebase-tools
  • Expo CLI: npm install -g expo-cli
  • Firebase project (dev and production)

πŸ› οΈ Setup

Backend Setup

  1. Navigate to backend directory:
cd backend
  1. Install dependencies:
cd functions
npm install
  1. Configure Firebase:
firebase login
firebase use --add  # Select your Firebase project
  1. Set environment variables:
firebase functions:config:set \
  qr.secret="your-hmac-secret-key" \
  app.region="asia-south1"
  1. Deploy Firestore rules and indexes:
firebase deploy --only firestore:rules,firestore:indexes
  1. Deploy Cloud Functions:
firebase deploy --only functions
  1. Seed database (optional):
# Call the seedDatabase function via HTTP or Firebase console

Frontend Setup

  1. Navigate to vigilx directory:
cd vigilx
  1. Install dependencies:
npm install
  1. Download face-api.js models:
# Download models from https://github.com/justadudewhohacks/face-api.js-models
# Place in vigilx/assets/models/
  1. Configure Firebase:
  • Update vigilx/services/firebase.ts with your Firebase config
  1. Start development server:
npx expo start

πŸ—„οΈ Database Schema

Collections

users

{
  uid: string
  name: string
  email: string
  role: "student" | "faculty" | "visitor" | "worker" | "guard"
  workerType?: "mess" | "maintenance" | "other"
  status: string
  permissions: {
    gates: string[]  // For workers
  }
  deviceId?: string
  faceEmbedding?: boolean
  photoURL?: string  // Firebase Storage URL
  fcmToken?: string
}

face_embeddings

{
  uid: string  // Document ID
  embedding: number[]  // 128-dimensional vector
  createdAt: Timestamp
  deviceId: string
}

logs

{
  logId: string
  userId: string
  userName: string
  userRole: string
  gateId: string
  gateName: string
  timestamp: Timestamp
  systemDecision: "ALLOW" | "DENY" | "PENDING"
  guardDecision?: "ALLOW" | "DENY"
  flags: string[]
  deviceId: string
  faceVerified?: boolean
}

pending_scans

{
  logId: string
  userId: string
  gateId: string
  guardId: string
  expiresAt: Timestamp
  createdAt: Timestamp
}

parcels

{
  parcelId: string
  studentId: string
  description: string
  guardId: string
  status: "pending" | "collected"
  createdAt: Timestamp
  collectedAt?: Timestamp
}

gates

{
  gateId: string
  name: string
  type: "main" | "hostel"
  location: string
}

πŸ” Security

Photo Storage

  • User Photos: Stored in Firebase Storage at user-photos/{uid}.jpg
  • Access: Public read (for guard display), authenticated write
  • Purpose: Displayed to guards during QR scans

Face Embeddings

  • Storage: Firestore collection face_embeddings/{uid}
  • Format: 128-dimensional normalized vector (face-api.js)
  • Privacy: Not reversible to original photo
  • Access: Owner read/write only
  • Purpose: Device binding verification

QR Codes

  • Signature: HMAC-SHA256 with secret key
  • Expiry: 60 seconds
  • Offline Cache: Max 5 minutes
  • Verification: Constant-time comparison

πŸ§ͺ Testing

Run backend tests:

cd backend/functions
npm test

Run frontend tests:

cd vigilx
npm test

See docs/TESTING.md for detailed testing guide.

πŸ“š Documentation

🚦 Gate-Specific Behavior

Main Gate

  • Students: Auto-allowed, minimal info displayed (name + photo only)
  • Others: Pending decision, full details displayed, guard approval required

Hostel Gates

  • All Users: Full details always displayed
  • Decision: ALLOW/DENY/PENDING based on permissions
  • Guard: Can approve/deny pending scans

πŸ‘₯ Worker Roles

Mess Worker

  • Access: Main gate only
  • Permissions: permissions.gates = ["main-gate"]

Maintenance Worker

  • Access: Main gate + all hostel gates
  • Permissions: permissions.gates = ["main-gate", "hostel-gate-1", "hostel-gate-2", ...]

Other Worker

  • Access: Custom gate list
  • Permissions: Configured per worker

πŸ“± Offline Mode

  • QR Display: Works offline with cached QR (max 5 minutes)
  • QR Scanning: Requires network connectivity (no offline scanning)
  • Auto-Refresh: QR refreshes automatically when network restored
  • Indicator: Visual "Offline Mode" indicator shown to user

πŸ”„ API Endpoints

Cloud Functions

  • POST /scanQR - Scan QR code at gate
  • POST /generateQR - Generate QR code for user
  • POST /guardDecision - Submit guard decision for pending scan
  • POST /uploadFaceEmbedding - Upload face embedding and photo
  • POST /createParcel - Create parcel for student
  • POST /collectParcel - Mark parcel as collected
  • POST /createVisitorSession - Create visitor pass
  • POST /validateVisitor - Validate visitor QR

See docs/API.md for detailed API documentation.

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Write tests
  5. Submit a pull request

πŸ“„ License

[MIT License]

πŸ‘¨β€πŸ’» Authors

[Team-Logical Error]

About

Smart, scalable access control system with QR authentication, role-based access control, and face recognition, designed for campuses and secure environments.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors