This documentation is structured to enable AI-assisted recreation of the complete application. Key implementation details are organized in a logical flow:
- System Setup: Dependencies and initial configuration
- Core Components: Server, client, and mobile implementations
- Data Structures: Schemas and file formats
- Integration Points: API endpoints and data flow
- Business Logic: Substitution algorithms and processing
A comprehensive teacher substitution management system with web and mobile interfaces that handles teacher absences, substitute assignments, and notifications through an automated process.
-
CSV File Processing
- System reads two primary CSV files:
- timetable_file.csv: Contains regular class schedules
- Substitude_file.csv: Contains substitute teacher information
- Files are processed using CSV parser with error handling
- Data is normalized and stored in JSON format
- System reads two primary CSV files:
-
Teacher Data Processing
interface Teacher {
id: number;
name: string;
phoneNumber: string | null;
isSubstitute: boolean;
variations?: string[]; // Different name spellings
}- Name normalization removes titles (Sir, Miss, etc.)
- Handles multiple name variations using Levenshtein distance
- Deduplicates teacher entries
- Stores in total_teacher.json
- Schedule Management
interface Schedule {
id: number;
day: string;
period: number;
teacherId: number;
className: string;
}- Validates day names and period numbers
- Stores class schedules by day
- Handles period configurations
- Maintains teacher-class assignments
- Absence Handling
interface Absence {
id: number;
teacherId: number;
date: string;
substituteId: number | null;
reason?: string;
status: 'pending' | 'approved' | 'completed';
}- Records teacher absences
- Triggers substitute assignment process
- Maintains absence history
- absent_teachers.json: Currently absent teachers
- assigned_teacher.json: Substitute assignments
- class_schedules.json: Class timetables
- total_teacher.json: All teacher records
- period_config.json: Period timing settings
- sms_history.json: Notification logs
-
Main Server (index.ts)
- Express.js setup
- Route registration
- Authentication setup
- Initial data loading
-
CSV Handler (csv-handler.ts)
- Processes timetable_file.csv
- Processes Substitude_file.csv
- Validates data format
- Normalizes teacher names
-
Storage System (storage.ts)
- In-memory data management
- File-based persistence
- CRUD operations for all entities
-
Substitute Manager (substitute-manager.ts)
- Auto-assignment algorithm
- Workload balancing
- Conflict prevention
- Assignment history tracking
-
Dashboard
- Displays absent teachers
- Shows today's substitutions
- Quick action buttons
- Real-time updates
-
Teacher Management
- Teacher profiles
- Attendance tracking
- Schedule viewing
- Contact management
-
Substitution Interface
- Manual assignment
- Auto-assignment triggers
- Assignment review
- Schedule conflicts
-
Core Features
- Offline capability
- Push notifications
- Quick attendance marking
- Schedule viewing
-
Data Sync
- Local SQLite storage
- Periodic server sync
- Conflict resolution
- Cache management
CREATE TABLE teachers (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
phone_number TEXT,
is_substitute BOOLEAN,
variations TEXT
);CREATE TABLE schedules (
id INTEGER PRIMARY KEY,
day TEXT NOT NULL,
period INTEGER NOT NULL,
teacher_id INTEGER,
class_name TEXT,
FOREIGN KEY (teacher_id) REFERENCES teachers(id)
);CREATE TABLE absences (
id INTEGER PRIMARY KEY,
teacher_id INTEGER,
date TEXT NOT NULL,
substitute_id INTEGER,
status TEXT,
FOREIGN KEY (teacher_id) REFERENCES teachers(id),
FOREIGN KEY (substitute_id) REFERENCES teachers(id)
);POST /api/login
Body: { username: string, password: string }
Response: { token: string, user: User }
GET /api/user
Headers: { Authorization: string }
Response: UserGET /api/teachers
Response: Teacher[]
POST /api/teachers
Body: { name: string, phoneNumber?: string, isSubstitute: boolean }
Response: Teacher
GET /api/teacher-schedule/:teacherId
Response: Schedule[]POST /api/absences
Body: { teacherId: number, date: string }
Response: Absence
GET /api/absences
Response: Absence[]
POST /api/auto-assign-substitutes
Response: { assignments: Assignment[], warnings: string[] }function normalizeTeacherName(name: string): string {
return name
.toLowerCase()
.replace(/(sir|miss|mr|ms|mrs|sr|dr)\.?\s*/gi, '')
.replace(/[^a-z\s-]/g, '')
.trim()
.split(/\s+/)
.filter(part => part.length > 1)
.sort()
.join(' ');
}- Get absent teachers for the day
- Find available substitutes
- Check substitute workload
- Consider class compatibility
- Avoid period conflicts
- Assign and notify
- Read CSV timetable
- Validate day and period
- Map teachers to classes
- Store in structured format
- Handle schedule conflicts
- Setup Project Structure
mkdir -p server/src client/src mobile/src data
npm init -y- Install Dependencies
{
"dependencies": {
"express": "^4.18.2",
"csv-parser": "^3.0.0",
"date-fns": "^2.30.0",
"react": "^18.2.0",
"react-native": "^0.72.0",
"typescript": "^5.0.0"
}
}- Initialize Database Files
touch data/total_teacher.json
touch data/absent_teachers.json
touch data/assigned_teacher.json- Configure TypeScript
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}- Start Implementation
- Set up Express server
- Create React frontend
- Implement data processing
- Add authentication
- Build mobile app
- Data Validation
npm run test:dataValidates CSV files and data structures
- Substitute Assignment
npm run test:assignTests auto-assignment algorithm
- API Testing
npm run test:apiValidates API endpoints
- Server Setup
- Port: 5000
- Host: 0.0.0.0
- Environment: Production
- Data Migration
- Backup CSV files
- Validate JSON storage
- Check file permissions
- Mobile Build
- Configure environment
- Build APK/IPA
- Test offline mode
- Data Protection
- File permissions
- Data encryption
- Secure storage
- Authentication
- JWT tokens
- Session management
- Password hashing
- API Security
- Rate limiting
- Input validation
- Error handling
- System Overview
- Core Data Flow
- File Structure and Purpose
- Database Schema
- API Endpoints
- Data Processing Algorithms
- Implementation Steps
- Testing Instructions
- Deployment Guide
- Security Considerations
- Introduction
- System Architecture
- Features
- Setup Instructions
- Detailed Component Guide
- API Documentation
- Mobile App
- Data Structures
- File Organization
- Development Guide
- Troubleshooting
The Teacher Substitution Management System is a comprehensive solution for educational institutions to manage teacher absences and substitute assignments efficiently. It provides real-time tracking, automated assignments, and instant notifications.
- Automate substitute teacher assignments
- Reduce administrative workload
- Ensure minimal disruption to classes
- Track attendance and substitution history
- Enable real-time schedule management
- Provide mobile access for teachers
- Reduced manual coordination
- Improved response time
- Better resource utilization
- Enhanced communication
- Data-driven decision making
- Frontend: React 18 with TypeScript
- Backend: Node.js 16+ with Express
- Mobile: React Native with Expo
- Database: File-based JSON storage
- SMS Integration: Multiple provider support
- State Management: TanStack Query
- Styling: Tailwind CSS
-
Web Application (client/)
- React SPA
- Real-time updates
- Responsive design
- Role-based access
-
Server (server/)
- Express API
- File-based storage
- Authentication system
- SMS integration
-
Mobile App (mobile/)
- React Native
- Offline support
- Push notifications
- Quick actions
-
Shared Types (shared/)
- TypeScript interfaces
- Validation schemas
- Utility types
- Teacher profiles with contact info
- Availability tracking
- Schedule management
- Specialization tracking
- History maintenance
- Contact preferences
- Quick absence recording
- Multiple day handling
- Absence categories
- Documentation upload
- History tracking
- Pattern analysis
- Intelligent matching algorithm
- Workload balancing
- Conflict prevention
- Preference consideration
- Real-time assignment
- Manual override options
- SMS alerts
- Custom templates
- Delivery tracking
- Bulk messaging
- Read receipts
- History logging
- Visual timetable
- Period configuration
- Conflict detection
- Schedule export
- Calendar integration
- Quick adjustments
- Absence patterns
- Substitution stats
- Teacher workload
- System usage
- SMS delivery
- Performance metrics
Node.js 16+
npm or yarn
Git- Clone the repository
- Install dependencies:
npm install- Configure environment:
- SMS provider setup
- Server port (default: 5000)
- Admin account creation
- File permissions
- Logging setup
Required CSV files:
-
timetable_file.csv: Class schedules
- Format: Day,Period,Teacher,Class
- Example: Monday,1,John Doe,10A
-
Substitude_file.csv: Substitute details
- Format: Name,Phone,Availability
- Example: Jane Smith,+1234567890,M/W/F
-
Admin Setup
- Create admin account
- Configure SMS templates
- Set up period timings
- Define school schedule
-
System Checks
- Verify file permissions
- Test SMS delivery
- Check file paths
- Validate schedules
Features:
- Secure authentication
- Role-based access
- Password recovery
- Session management
- Activity logging
- Security measures
Components:
- Absent teacher count
- Today's assignments
- Quick actions menu
- Notification center
- System status
- Recent activities
Features:
- Profile management
- Schedule viewing
- Contact updates
- Availability setting
- History tracking
- Document upload
Features:
- Quick recording
- Duration setting
- Document attachment
- History viewing
- Pattern analysis
- Bulk operations
Features:
- Auto assignment
- Manual override
- History tracking
- Preference setting
- Conflict checking
- Workload balancing
Features:
- Timetable view
- Period management
- Conflict handling
- Export options
- Quick edits
- Calendar sync
Features:
- SMS configuration
- Period timing
- System preferences
- User management
- Backup options
- Log viewing
POST /api/login
Body: { username, password }
Response: { token, user }
GET /api/user
Headers: { Authorization }
Response: { user }
POST /api/logout
Headers: { Authorization }
Response: { success }
GET /api/teachers
Response: Teacher[]
POST /api/teachers
Body: { name, phone, isSubstitute }
Response: Teacher
GET /api/teacher-schedule/:teacherName
Response: Schedule[]
GET /api/absences
Response: Absence[]
POST /api/absences
Body: { teacherId, date }
Response: Absence
GET /api/get-absent-teachers
Response: AbsentTeacher[]
POST /api/auto-assign-substitutes
Response: Assignment[]
GET /api/substitute-assignments
Response: Assignment[]
POST /api/reset-assignments
Response: { success }
GET /api/schedule/:day
Response: Schedule[]
POST /api/schedule
Body: { day, periods }
Response: Schedule
GET /api/period-config
Response: PeriodConfig[]
cd mobile
npm install-
Attendance Marking
- Quick mark
- Offline support
- Batch upload
- History view
-
Schedule Viewing
- Daily view
- Weekly view
- Quick search
- Offline access
-
Substitute Assignment
- Accept/reject
- View details
- Contact info
- Directions
-
Push Notifications
- Assignment alerts
- Schedule changes
- System updates
- Reminders
interface Teacher {
id: number;
name: string;
phoneNumber: string;
isSubstitute: boolean;
specializations?: string[];
availability?: string[];
preferences?: {
maxClassesPerDay: number;
preferredClasses: string[];
};
}interface Schedule {
id: number;
day: string;
period: number;
teacherId: number;
className: string;
subject?: string;
room?: string;
}interface Absence {
id: number;
teacherId: number;
date: string;
substituteId: number | null;
reason?: string;
documentation?: string[];
status: 'pending' | 'approved' | 'completed';
}interface SMSConfig {
provider: string;
apiKey: string;
senderId: string;
templates: {
assignment: string;
reminder: string;
urgent: string;
};
retryConfig: {
attempts: number;
delay: number;
};
}data/
├── absent_teachers.json # Current absences
├── assigned_teacher.json # Substitute assignments
├── class_schedules.json # Class-wise schedules
├── day_schedules.json # Day-wise schedules
├── period_config.json # Period timings
├── teacher_schedules.json # Teacher timetables
├── total_teacher.json # All teachers
├── users.json # User accounts
└── sms_history.json # Message logs
-
Code Style
- Follow TypeScript guidelines
- Use async/await
- Implement error handling
- Add proper logging
-
File Organization
- Group by feature
- Separate concerns
- Use clear naming
- Maintain hierarchy
-
Error Handling
- Graceful failures
- User feedback
- Error logging
- Recovery options
-
Performance
- Optimize queries
- Cache results
- Batch operations
- Lazy loading
- Secure file storage
- Access control
- Data encryption
- Regular backups
- Token-based auth
- Session management
- Password policies
- Role enforcement
- Rate limiting
- Input validation
- Error masking
- CORS policy
-
File Access
- Check permissions
- Verify paths
- Monitor storage
- Handle locks
-
SMS Delivery
- Verify credentials
- Check balance
- Monitor status
- Handle failures
-
Assignment Failures
- Validate data
- Check conflicts
- Review logs
- Manual override
-
Mobile Sync
- Check connectivity
- Verify cache
- Handle conflicts
- Force refresh
For detailed implementation information, refer to the source code in the respective directories.