Directory Structure
Complete project organization
MR_BunkManager/
├── app/ # Expo Router navigation
│ ├── (auth)/ # Authentication screens
│ │ ├── login.tsx # Email/password + Google login
│ │ ├── signup.tsx # User registration
│ │ ├── email-verification.tsx # Email verification flow
│ │ ├── forgot-password.tsx # Password reset
│ │ └── _layout.tsx # Auth group layout
│ ├── (onboarding)/ # Onboarding flow
│ │ └── index.tsx # Profile setup wizard
│ ├── (tabs)/ # Main app tabs
│ │ ├── index.tsx # Dashboard/home
│ │ ├── timetable.tsx # Class schedule
│ │ ├── attendance.tsx # Attendance tracking
│ │ ├── groups.tsx # Study groups
│ │ ├── profile.tsx # User profile
│ │ └── _layout.tsx # Tab navigator
│ ├── note/[id].tsx # Dynamic: Note detail
│ ├── user/[id].tsx # Dynamic: User profile
│ ├── create-note.tsx # Note creation
│ └── _layout.tsx # Root layout
│
├── src/ # Source code
│ ├── hooks/ # Custom React hooks (2 files)
│ │ ├── useResponsive.ts # Responsive design utilities
│ │ └── index.ts # Hook exports
│ ├── components/ # React components (15+ files)
│ ├── screens/ # Screen implementations (13 files)
│ ├── services/ # Business logic (17 files)
│ │ ├── ocrService.ts # OCR.space API integration
│ │ ├── timetableParserService.ts # AI timetable parsing
│ ├── store/ # Zustand stores (5 files)
│ ├── types/ # TypeScript definitions (3 files)
│ └── config/ # Configuration (2 files)
│
├── backend/ # Node.js server
│ ├── src/
│ │ ├── index.js # Express server (1106 lines)
│ │ ├── sendNotification.js # Notification logic
│ │ └── driveUpload.js # Google Drive API
│ ├── config/
│ │ └── firebase.js # Admin SDK
│ └── cron-service/ # Scheduled tasks
│
└── docs/ # Documentation
Backend Server Analysis
Line-by-line breakdown of the Express server
backend/src/index.js Express.js 1106 lines
Main Express server handling push notifications, file uploads, and deep links. All times in IST (Asia/Kolkata).
| Lines | Purpose |
|---|---|
1-30 | Module imports (express, cors, helmet, multer, firebase) |
31-46 | Environment config (PORT, APP_ENV, TIMEZONE) |
47-70 | Multer file upload config (50MB limit, image/PDF filter) |
71-106 | Middleware stack (Helmet, CORS, JSON parser, rate limiting) |
107-135 | Firebase init and IST time utilities |
136-206 | POST /save-token - Push token registration |
207-263 | DELETE /delete-token - Token removal |
264-320 | POST /send-notification - User notifications |
321-476 | POST /notify-group-members - Group activity alerts |
477-526 | POST /notify-followers - New note alerts |
527-575 | POST /send-notification-all - Broadcast |
576-646 | Daily and class reminder endpoints |
647-710 | Token retrieval endpoints |
711-862 | File upload routes (Google Drive, Catbox.moe) |
863-1035 | GET /note/:noteId - Deep link HTML handler |
1036-1106 | Error handlers, 404, server startup |
Services Layer Analysis
Business logic and Firebase operations
groupsService.ts TypeScript 719 lines
Handles all group operations including CRUD, member management, real-time messaging, and notifications.
| Lines | Method | Purpose |
|---|---|---|
35-79 | createGroup() | Create group with creator as admin |
84-104 | getGroup() | Fetch single group by ID |
109-139 | getPublicGroups() | List public groups (client-side sort) |
144-173 | getUserGroups() | Get user's joined groups |
178-205 | subscribeToMyGroups() | Real-time group subscription |
288-320 | addMember() | Add user to group + increment count |
325-345 | removeMember() | Remove user + decrement count |
410-451 | sendMessage() | Send chat message + update activity |
488-516 | subscribeToMessages() | Real-time message listener |
680-715 | notifyGroupMembers() | Push notifications to members |
authService.ts TypeScript
Firebase authentication operations including email/password and Google Sign-In.
| Method | Description |
|---|---|
signUp(email, password, displayName) | Create account + send verification email |
signIn(email, password) | Email/password authentication |
signInWithGoogle() | OAuth via Google Sign-In |
sendVerificationEmail() | Resend email verification |
resetPassword(email) | Password reset email |
signOut() | Log out current user |
chatService.ts TypeScript
Groq API integration for BunkBot AI assistant with context injection.
| Feature | Description |
|---|---|
| Model | Llama 4 Maverick (meta-llama/llama-4-maverick-17b-128e-instruct) |
| Temperature | 0.7 |
| Max Tokens | 2048 |
| Context | Attendance data, timetable, user preferences |
| Image Support | Base64 image analysis |
| Quick Prompts | Pre-defined attendance-related questions |
Component Analysis
Key React Native components
ChatBot.tsx React Native 793 lines
AI chat interface with multi-conversation support, voice input, and image attachments.
| Lines | Feature |
|---|---|
7-49 | Imports (React, RN Paper, Expo modules) |
65-82 | State declarations (chats, messages, input, etc.) |
84-97 | Speech recognition event handlers |
99-122 | toggleRecording() - Voice input control |
134-146 | useEffect hooks (load, save, scroll) |
152-196 | Chat management (switch, create, delete) |
197-214 | Drawer animation functions |
216-254 | Image picker (camera/gallery) |
255-319 | handleSend() - Main message handler |
348-625 | JSX render (header, messages, input, drawer) |
626-793 | StyleSheet definitions |
Custom Hooks
Reusable React hooks for common functionality
useResponsive.ts TypeScript
Provides responsive design utilities with breakpoints for mobile, tablet, desktop, and large desktop screens.
| Export | Type | Description |
|---|---|---|
BREAKPOINTS | Object | Screen width breakpoints (xs: 0, sm: 375, md: 768, lg: 1024, xl: 1280, xxl: 1536) |
useResponsive() | Hook | Returns responsive values and utility functions |
| Return Value | Type | Description |
|---|---|---|
isMobile | boolean | Screen width < 768px |
isTablet | boolean | Screen width 768-1023px |
isDesktop | boolean | Screen width 1024-1279px |
isLargeDesktop | boolean | Screen width >= 1280px |
isWeb | boolean | Platform.OS === 'web' |
responsive() | Function | Returns value based on screen size |
spacing() | Function | Responsive spacing multiplier |
fontSize() | Function | Responsive font size multiplier |
containerPadding | number | Responsive container padding |
contentMaxWidth | number | Responsive max content width |
State Management
Zustand stores for reactive state
authStore.ts Zustand 77 lines
Authentication state with Firebase observer and push notification registration.
| State | Type | Purpose |
|---|---|---|
user | User | null | Firebase User object |
loading | boolean | Auth loading state |
initialized | boolean | Has auth been checked |
pushToken | string | null | Device push token |
| Action | Description |
|---|---|
setUser(user) | Set current user |
initializeAuth() | Start Firebase auth listener |
refreshUser() | Force refresh from Firebase |
Other Stores
| Store | State | Purpose |
|---|---|---|
networkStore | isOnline, lastOnlineTime | Connectivity monitoring |
themeStore | isDarkMode, mode | Theme preference (light/dark/system) |
notesStore | likedNotes, savedNotes | Note interaction cache |
groupsStore | groups, messages, unreadCounts | Groups and chat state |
Type Definitions
TypeScript interfaces
Core Types
// types/user.ts
interface UserProfile {
uid: string;
displayName: string;
email: string;
photoURL?: string;
college: string;
course: string;
department: string;
semester: string;
rollNumber: string;
section?: string;
minimumAttendance: number;
onboardingCompleted: boolean;
}
// types/notes.ts
type NoteContentType = 'text' | 'pdf' | 'image' | 'link';
interface Note {
id: string;
authorId: string;
authorName: string;
title: string;
description?: string;
contentType: NoteContentType;
content: string;
fileUrl?: string;
tags: string[];
isPublic: boolean;
likesCount: number;
commentsCount: number;
savesCount: number;
createdAt: Date;
updatedAt: Date;
}
// types/groups.ts
interface Group {
id: string;
name: string;
description: string;
category: 'study' | 'project' | 'social' | 'general';
isPrivate: boolean;
members: string[];
memberCount: number;
lastActivity?: Date;
}
interface GroupMessage {
id: string;
groupId: string;
userId: string;
userName: string;
message: string;
fileUrl?: string;
createdAt: Date;
}
OCR & Timetable Extraction
Image text extraction and AI parsing services
ocrService.ts TypeScript 141 lines
OCR (Optical Character Recognition) service using OCR.space API. Extracts text from images supporting multiple formats and both web and native platforms.
| Lines | Function | Purpose |
|---|---|---|
1-11 | Imports & Config | Platform, expo-file-system/next, API URL/Key |
16-37 | getImageMimeType() | Detect MIME type from URI or base64 prefix |
44-140 | extractTextFromImage() | Main OCR extraction function |
64-66 | Base64 handling | Direct base64 data URI support |
67-90 | File URI handling | Native file:// and content:// URIs using File class |
91-93 | URL handling | HTTP/HTTPS image URLs |
102-126 | API Response | Parse OCR.space JSON response |
// Key features:
- OCR Engine 2 (advanced recognition)
- Table detection enabled
- Auto-scale for better accuracy
- Supports: JPG, PNG, GIF, WebP, BMP, TIFF
timetableParserService.ts TypeScript
AI-powered service that parses OCR-extracted text into structured TimetableEntry objects using Groq API (Llama 4 Maverick model).
| Feature | Description |
|---|---|
| Model | Llama 4 Maverick (meta-llama/llama-4-maverick-17b-128e-instruct) |
| Temperature | 0.1 (low for structured output) |
| Max Tokens | 4096 |
| Output Format | JSON array of TimetableEntry objects |
| Day Normalization | Converts Mon/Tue/etc. to full day names |
| Time Normalization | Converts to HH:MM 24-hour format |
// Extracts from OCR text:
- Subject name and code
- Day of week
- Start and end times
- Class type (lecture/lab/tutorial)
- Faculty name (if present)
- Room/Location (if present)
Service Summary
All 17 services and their responsibilities
| Service | File | Purpose |
|---|---|---|
| Auth | authService.ts | Firebase auth operations |
| Firestore | firestoreService.ts | User profile, timetable, subjects |
| Chat | chatService.ts | Groq AI integration |
| Chat Storage | chatStorageService.ts | Chat history persistence |
| OCR | ocrService.ts | OCR.space image text extraction |
| Timetable Parser | timetableParserService.ts | AI parsing of OCR text to timetable |
| Notes | notesService.ts | Notes CRUD, feed, search |
| Groups | groupsService.ts | Groups, members, real-time chat |
| Social | socialService.ts | Likes, comments, saves |
| Follow | followService.ts | Follow/unfollow, suggestions |
| Notification | notificationService.ts | Push token registration |
| Cache | cacheService.ts | AsyncStorage caching |
| Offline Queue | offlineQueueService.ts | Offline operation queue |
| Image Upload | imageUploadService.ts | Catbox.moe uploads |
| File Upload | fileUploadService.ts | Upload coordination |
| Google Drive | googleDriveService.ts | Google Drive API |
| Gemini | geminiService.ts | Alternative AI service |