Skip to main content

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

Purpose: Represents educational systems (e.g., British, American, Egyptian) Usage: Used in course creation, teacher profiles, and student enrollment Fields:
  • id: Unique identifier for the education system
  • name: Display name of the education system

EducationGrade

Purpose: Represents grade levels within education systems Usage: Used for course categorization and student level matching Fields:
  • id: Unique identifier for the grade
  • education_system_id: Foreign key to EducationSystem
  • name: Display name of the grade (e.g., “Grade 10”, “A-Level”)

EducationTerm

Purpose: Represents academic terms or semesters Usage: Used for course scheduling and academic planning Fields:
  • id: Unique identifier for the term
  • name: Display name of the term (e.g., “Fall 2024”, “Spring 2025”)

2. Subject and Course Types

Subject

Purpose: Represents academic subjects Usage: Used throughout the application for course categorization Fields:
  • id: Unique identifier for the subject
  • name: Display name of the subject (e.g., “Mathematics”, “Physics”)

TeacherSubject

Purpose: Represents teacher’s subject expertise with related data Usage: Used in teacher profiles and course matching Fields:
  • id: Unique identifier for the teacher subject
  • subject_id: Foreign key to Subject
  • education_system_id: Foreign key to EducationSystem
  • education_grade_id: Foreign key to EducationGrade
  • subject: Nested subject information
  • education_system: Nested education system information
  • education_grade: Nested education grade information

TeacherSubjectResponse

Purpose: Represents teacher subjects with array responses from database Usage: Used when database returns multiple related records Fields: Same as TeacherSubject but with arrays for related data

Course

Purpose: Represents course information with related data Usage: Used throughout the application for course display and management Fields:
  • id: Unique identifier for the course
  • title: Course title
  • cost: Course price in EGP
  • rating: Optional average rating (0-5)
  • ratings_count: Optional number of ratings
  • sessions_count: Number of sessions in the course
  • session_duration: Duration of each session in minutes
  • teacher: Nested teacher information
  • education_system: Nested education system information
  • education_grade: Nested education grade information
  • subject: Nested subject information

3. User and Profile Types

Profile

Purpose: Represents user profile information Usage: Used throughout the application for user data display Fields:
  • id: Unique identifier for the profile
  • first_name: User’s first name
  • last_name: User’s last name
  • gender: User’s gender
  • email: User’s email address
  • mobile: User’s mobile number
  • country: User’s country
  • region: User’s region/state
  • city: User’s city
  • profile_image: Optional profile image URL
  • education_system: Optional nested education system
  • education_grade: Optional nested education grade

SignUpFormData

Purpose: Represents user registration form data Usage: Used in registration forms and validation Fields:
  • email: User’s email address
  • password: User’s password
  • confirmPassword: Password confirmation
  • firstName: User’s first name
  • lastName: User’s last name
  • mobile: User’s mobile number
  • educationSystemId: Optional education system selection
  • educationGradeId: Optional education grade selection
  • country: User’s country
  • region: User’s region/state
  • city: User’s city
  • userType: Type of user account
  • gender: User’s gender
  • nationality: Optional nationality

4. Session and Attendance Types

SessionType

Purpose: Represents types of sessions Usage: Used for session categorization and scheduling Fields:
  • id: Unique identifier for the session type
  • name: Display name of the session type (e.g., “Live Class”, “Office Hours”)

5. Teacher Mark Scheme Types

TeacherMarkScheme

Purpose: Represents teacher-created mark schemes for exam papers Usage: Used in the teacher mark scheme marketplace Fields:
  • id: Unique identifier for the mark scheme
  • subject_id: Foreign key to Subject
  • exam_category: Type of exam (AL = A-Level, IGCSE = IGCSE)
  • paper_year: Year of the exam paper
  • paper_season: Season of the exam (‘w’ = Winter, ‘s’ = Summer, ‘m’ = March)
  • paper_category: Category of the paper
  • original_filename: Original filename of the uploaded file
  • file_url: URL to the mark scheme file
  • file_size: Size of the file in bytes
  • teacher_explanation: Teacher’s explanation of the mark scheme
  • teacher_notes: Optional additional notes
  • is_public: Whether the mark scheme is public
  • is_approved: Whether the mark scheme is approved
  • created_at: Creation timestamp
  • updated_at: Last update timestamp

TeacherMarkSchemePurchase

Purpose: Represents student purchases of teacher mark schemes Usage: Used for purchase tracking and access control Fields:
  • id: Unique identifier for the purchase
  • student_id: Foreign key to student profile
  • teacher_mark_scheme_id: Foreign key to TeacherMarkScheme
  • order_id: Foreign key to order record
  • purchase_date: Date of purchase
  • amount_paid: Amount paid for the mark scheme
  • currency: Currency of payment (default: EGP)
  • payment_status: Status of the payment
  • access_expires_at: Optional access expiration date
  • created_at: Creation timestamp
  • updated_at: Last update timestamp

TeacherMarkSchemeWithPurchase

Purpose: Extends TeacherMarkScheme with purchase information Usage: Used when displaying mark schemes with purchase status Fields: Inherits all TeacherMarkScheme fields plus:
  • is_purchased: Whether the current user has purchased this scheme
  • purchase_details: Details of the purchase if applicable

TeacherMarkSchemePaymentRequest

Purpose: Represents payment request for teacher mark scheme Usage: Used in payment processing flow Fields:
  • teacher_mark_scheme_id: ID of the mark scheme to purchase
  • amount: Amount to pay
  • currency: Optional currency (defaults to EGP)
  • student_id: ID of the purchasing student

TeacherMarkSchemePaymentResponse

Purpose: Represents response from payment request Usage: Used for handling payment responses Fields:
  • success: Whether the payment request was successful
  • payment_url: Optional URL for payment processing
  • order_id: Optional order ID for tracking
  • error: 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 any type
  • 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