Frontend Types Documentation
This document provides comprehensive documentation for all TypeScript type definitions, interfaces, and type utilities in the STO Education Platform frontend.Types Overview
The application uses TypeScript extensively for type safety, with centralized type definitions that ensure consistency across components, services, and utilities.Type Categories
1. Education System Types
EducationSystem
id: Unique identifier for the education systemname: Display name of the education system
EducationGrade
id: Unique identifier for the gradeeducation_system_id: Foreign key to EducationSystemname: Display name of the grade (e.g., “Grade 10”, “A-Level”)
EducationTerm
id: Unique identifier for the termname: Display name of the term (e.g., “Fall 2024”, “Spring 2025”)
2. Subject and Course Types
Subject
id: Unique identifier for the subjectname: Display name of the subject (e.g., “Mathematics”, “Physics”)
TeacherSubject
id: Unique identifier for the teacher subjectsubject_id: Foreign key to Subjecteducation_system_id: Foreign key to EducationSystemeducation_grade_id: Foreign key to EducationGradesubject: Nested subject informationeducation_system: Nested education system informationeducation_grade: Nested education grade information
TeacherSubjectResponse
Course
id: Unique identifier for the coursetitle: Course titlecost: Course price in EGPrating: Optional average rating (0-5)ratings_count: Optional number of ratingssessions_count: Number of sessions in the coursesession_duration: Duration of each session in minutesteacher: Nested teacher informationeducation_system: Nested education system informationeducation_grade: Nested education grade informationsubject: Nested subject information
3. User and Profile Types
Profile
id: Unique identifier for the profilefirst_name: User’s first namelast_name: User’s last namegender: User’s genderemail: User’s email addressmobile: User’s mobile numbercountry: User’s countryregion: User’s region/statecity: User’s cityprofile_image: Optional profile image URLeducation_system: Optional nested education systemeducation_grade: Optional nested education grade
SignUpFormData
email: User’s email addresspassword: User’s passwordconfirmPassword: Password confirmationfirstName: User’s first namelastName: User’s last namemobile: User’s mobile numbereducationSystemId: Optional education system selectioneducationGradeId: Optional education grade selectioncountry: User’s countryregion: User’s region/statecity: User’s cityuserType: Type of user accountgender: User’s gendernationality: Optional nationality
4. Session and Attendance Types
SessionType
id: Unique identifier for the session typename: Display name of the session type (e.g., “Live Class”, “Office Hours”)
5. Teacher Mark Scheme Types
TeacherMarkScheme
id: Unique identifier for the mark schemesubject_id: Foreign key to Subjectexam_category: Type of exam (AL = A-Level, IGCSE = IGCSE)paper_year: Year of the exam paperpaper_season: Season of the exam (‘w’ = Winter, ‘s’ = Summer, ‘m’ = March)paper_category: Category of the paperoriginal_filename: Original filename of the uploaded filefile_url: URL to the mark scheme filefile_size: Size of the file in bytesteacher_explanation: Teacher’s explanation of the mark schemeteacher_notes: Optional additional notesis_public: Whether the mark scheme is publicis_approved: Whether the mark scheme is approvedcreated_at: Creation timestampupdated_at: Last update timestamp
TeacherMarkSchemePurchase
id: Unique identifier for the purchasestudent_id: Foreign key to student profileteacher_mark_scheme_id: Foreign key to TeacherMarkSchemeorder_id: Foreign key to order recordpurchase_date: Date of purchaseamount_paid: Amount paid for the mark schemecurrency: Currency of payment (default: EGP)payment_status: Status of the paymentaccess_expires_at: Optional access expiration datecreated_at: Creation timestampupdated_at: Last update timestamp
TeacherMarkSchemeWithPurchase
is_purchased: Whether the current user has purchased this schemepurchase_details: Details of the purchase if applicable
TeacherMarkSchemePaymentRequest
teacher_mark_scheme_id: ID of the mark scheme to purchaseamount: Amount to paycurrency: Optional currency (defaults to EGP)student_id: ID of the purchasing student
TeacherMarkSchemePaymentResponse
success: Whether the payment request was successfulpayment_url: Optional URL for payment processingorder_id: Optional order ID for trackingerror: Optional error message
Type Utilities and Helpers
1. Union Types
User Types
Gender Types
Payment Status Types
Exam Category Types
Paper Season Types
2. Utility Types
Partial Profile
Required Course Fields
Optional Mark Scheme Fields
3. Generic Types
API Response
Paginated Response
Form State
Type Guards
1. User Type Guards
2. Payment Type Guards
3. Course Type Guards
Type Validation
1. Runtime Type Checking
2. Type Assertions
Type Documentation Standards
1. Interface Documentation
2. Generic Type Documentation
3. Union Type Documentation
Type Best Practices
1. Naming Conventions
- Interfaces: PascalCase (e.g.,
UserProfile) - Types: PascalCase (e.g.,
UserType) - Enums: PascalCase (e.g.,
PaymentStatus) - Generic Parameters: Single uppercase letter (e.g.,
T,K,V)
2. Type Organization
- Group Related Types: Keep related types together
- Use Extensions: Extend interfaces when appropriate
- Avoid Any: Minimize use of
anytype - Use Union Types: Use union types for variants
3. Type Safety
- Strict Mode: Use strict TypeScript configuration
- Type Guards: Implement runtime type checking
- Validation: Validate data at runtime
- Error Handling: Handle type errors gracefully
Future Type Enhancements
1. Planned Features
- Advanced Generics: More sophisticated generic types
- Template Literal Types: String manipulation types
- Conditional Types: Advanced conditional type logic
- Mapped Types: Dynamic type generation
2. Type System Improvements
- Better Error Messages: Enhanced TypeScript error messages
- Type Inference: Improved automatic type inference
- Performance: Better TypeScript compilation performance
- Tooling: Enhanced TypeScript tooling support
3. Developer Experience
- Auto-completion: Better IDE auto-completion
- Type Hints: Enhanced type hints and suggestions
- Documentation: Better type documentation
- Testing: Type-level testing utilities