A real-time Snell library occupancy monitoring and prediction platform that leverages simulated IoT sensor data, machine learning, and conversational AI to provide intelligent insights about space availability at Snell Library.
nuk-ai transforms how students interact with library spaces by providing real-time occupancy data, predictive analytics, and an intelligent chat interface.
Note
While the core architecture and capabilities are production-ready, the current implementation uses simulated sensor data for demonstration purposes. This approach is inspired by real-world implementations like UCL's occupancy detection system and validated room occupancy datasets.
graph TB
subgraph "Frontend (Next.js)"
UI[User Interface]
end
subgraph "External Services"
Sensor_Data[Sensor Readings]
end
subgraph "Backend (FastAPI)"
API_Router[API Router]
Occupancy_Service[Occupancy Service]
Chat_Service[Chat Service]
Prediction_Model[ML Prediction Model]
end
subgraph "Data Layer"
Supabase[(Supabase Database)]
Model_Storage[Model Storage]
end
subgraph "External Services"
Gemini[Gemini AI Model]
end
UI --> API_Router
API_Router --> Occupancy_Service
API_Router --> Chat_Service
Chat_Service --> Gemini
Chat_Service --> Prediction_Model
Occupancy_Service --> Supabase
Prediction_Model --> Model_Storage
Prediction_Model --> Supabase
Sensor_Data --> Supabase
- Next.js App Router for modern routing patterns
- Tailwind CSS v4 Utility-first CSS framework
- Radix UI Components Accessible, unstyled UI primitives with ARIA compliance and keyboard navigation
- FastAPI Modern Python web framework with type validation and async support
- Supabase (PostgreSQL) Managed infrastructure
- Prophet (Meta) Time series forecasting with minimal hyperparameter tuning required
- Google Gemini API Natural language understanding and tool integration capabilities
- Render Cloud platform hosting both backend and frontend
- Single FastAPI server serving both API endpoints and static Next.js frontend
- Web service automatically builds from GitHub repository
- Scheduled cron job for sensor data simulation every 5 minutes
The application is deployed as a unified service on Render with the following components:
-
FastAPI Backend
- Serves API endpoints at
/api/*for occupancy data and chat functionality - Runs on Python 3.11 with dependencies specified in
backend/requirements.txt - Connects to Supabase for data storage and retrieval
- Serves API endpoints at
-
Next.js Frontend
- Built as a static export and served by the FastAPI application
- Frontend assets are served at
/_nextpath - The main application is served at the root path
/
-
Data Simulation
- Scheduled cron job executes
backend/scripts/generate_data.pyevery 5 minutes - Simulates IoT sensor data based on time-of-day occupancy patterns
- Inserts generated readings directly into Supabase
- Scheduled cron job executes
-
Unified Deployment
- Single service handles both API requests and serves the frontend
- Environment variables configured in Render's dashboard
- Automatic deployments triggered by pushes to the main branch
The system uses a hierarchical structure to organize data.
- floors: Library floor definitions (4 floors)
- zones: Spatial divisions within floors (9 zones per floor in 3x3 grid)
- sensors: Individual IoT devices (~16-17 sensors per zone)
- sensor_readings: Time-series data (timestamp, sensor_id, status, temperature)
The platform tracks library occupancy through SIMULATED temperature-based IoT sensors detecting human presence (30-35°C for occupied seats vs 20-21°C ambient). Data is pushed to the database every 5 minutes courtesy of a cron job.
The system aggregates historical sensor readings to train Prophet models that forecast future occupancy patterns. These trained models are serialized and stored in Supabase Storage, where they're dynamically loaded to serve real-time predictions through the FastAPI endpoints whenever users query future availability.
The conversational interface processes natural language queries about library availability, intelligently integrating real-time occupancy data with contextual information. The system generates visual heatmaps directly within chat responses to illustrate floor-by-floor occupancy patterns.
-
Heatmap Visualizations
- Color-coded occupancy levels using an intuitive green-to-red gradient where green indicates low density and red shows high occupancy zones 3x3 grid layout that directly mirrors the physical floor plan, enabling students to quickly identify their target zone location
- Real-time updates that refresh automatically as new sensor data arrives every 5 minutes
- Interactive navigation allowing users to click between floors and expand views for detailed zone-level information
-
Capacity Metrics:
- Overall library utilization percentage displayed prominently to show general availability at a glance
- Floor-by-floor breakdowns providing granular capacity data for students with specific floor preferences
- Responsive design ensuring consistent functionality across desktop, tablet, and mobile devices for on-the-go checking
The backend/scripts/generate_data.py script creates realistic data as will be generated by an IoT device. The device in question will be placed beneath every table and detect temperature changes due to the presence/absence of people.
cd backend
python scripts/generate_data.py # Runs a single simulation cycle-
Backend Setup:
cd backend ./setup.sh # Creates virtual environment and installs dependencies source venv/bin/activate python main.py # Starts the FastAPI server at http://localhost:8000
-
Client Development:
cd client npm install npm run dev # Starts Next.js dev server at http://localhost:3000
The application uses a unified deployment model on Render:
-
Automated Data Generation:
- A Render cron job executes
python backend/scripts/generate_data.pyevery 5 minutes - This simulates IoT sensor readings and inserts them into Supabase
- The occupancy probability varies based on time-of-day and day-of-week patterns
- A Render cron job executes
-
CI/CD Pipeline:
- Pushing to the main branch triggers automatic deployment on Render
- Build process:
- Installs Python dependencies from
backend/requirements.txt - Installs Node.js and npm packages from
client/package.json - Builds the Next.js frontend
- Starts the FastAPI server which serves both API endpoints and frontend
- Installs Python dependencies from
Required environment variables for deployment:
SUPABASE_URL: Supabase project URLSUPABASE_KEY: Supabase service role API keyGEMINI_API_KEY: Google Gemini API key for chat functionalityDATABASE_URL: PostgreSQL connection string (if using direct DB access)
- LSTM networks for complex temporal patterns
- Student ID card system connection
- Library catalog synchronization
- Push notifications for space availability
- Location-based services for other halls/spaces
Built by Parthiv Menon, Jovin Nicholas, Aditya Ayyappan for Hack NUACM 2025.
