Spaces:
Running
Running
Application Architecture
1. Core Technology Stack
This application is a modern, lightweight single-page application (SPA) built with:
- React 19: The core UI library. We leverage React's component-based architecture and hooks (
useState,useMemo) for managing state and logic. - TypeScript: For static typing, which improves code quality, maintainability, and developer experience by catching errors early.
- Unicode for Math: All mathematical notation is handled using standard Unicode characters directly within the content. This approach removes external dependencies and simplifies the rendering pipeline.
- CSS-in-JS (via Style Objects): All styling is colocated within a single TypeScript file (
src/styles/appStyles.ts). This approach provides typed styles and avoids the need for a separate CSS pipeline, simplifying the build process. - No Build Step: The project uses import maps in
index.htmlto load React from a CDN. This allows for rapid development without a complex bundler like Webpack or Vite.
2. Project Structure
The project is organized into a logical and scalable structure:
/
βββ docs/ # Documentation files (pedagogy, architecture, etc.)
βββ src/ # Application source code
β βββ components/ # Reusable React components
β β βββ Calculator.tsx # Interactive worksheet component
β β βββ ContentPage.tsx # Renders the basic layout for a content slide
β β βββ ContentRenderer.tsx # Renders different types of content (text, list, formula)
β β βββ ProgressBar.tsx # Visual progress indicator
β β βββ Quiz.tsx # Multiple-choice quiz component
β β βββ SlideRenderer.tsx # Dynamically renders the correct slide type
β βββ data/ # Static data, including slide content
β β βββ slides.ts # The core content of the lesson
β βββ styles/ # Styling definitions
β β βββ appStyles.ts # Centralized CSS-in-JS style objects
β βββ App.tsx # Main application component, manages state
βββ index.html # The entry point of the application
βββ index.tsx # Renders the React root
βββ metadata.json # Application metadata
3. State Management
Application state is managed using a minimalist approach suitable for the app's scope:
- Global State (
App.tsx): The mainAppcomponent holds the primary piece of state:step, an integer representing the current slide index. - Local State (
components/*): Components manage their own internal state. For example,Calculator.tsxusesuseStateto track user inputs and submission status, andQuiz.tsxuses it to track the selected answer. This encapsulation keeps components self-contained and easy to reason about.
4. Component-Based Design
The application's architecture is highly modular and follows best practices for component design.
App.tsx: The top-level component that orchestrates the UI. It manages navigation between slides and passes the current slide's data down to theSlideRenderer.SlideRenderer.tsx: A crucial component that acts as a router. It inspects thetypeproperty of the current slide's data and renders the appropriate layout and components (ContentPage,Quiz,Calculator).ContentRenderer.tsx: A central component responsible for interpreting thecontentarray from the slide data. It dynamically renders paragraphs, lists, and formulas containing Unicode math and HTML.ContentPage.tsx: This component is a pure layout component. It renders the slide's title and subtitle and then delegates all block-level content rendering to theContentRenderer.- Interactive Components (
Quiz,Calculator): These are specialized components responsible for rendering interactive elements. They handle their own state and logic.
5. Data Flow
The application follows a clean, unidirectional data flow and features a highly structured data model.
- Data Model (
slides.ts): Theslides.tsfile is the single source of truth. TheSlideDatainterface uses a unifiedcontentarray. Each slide's content is an array ofContentItemobjects. Each object has atype(e.g.,'paragraph','list','formula') and the corresponding data. Mathematical notation is stored directly as Unicode strings. - Data Propagation: The main
Appcomponent reads fromslidesDatabased on the currentstep. - Props Drilling: The relevant slide data object is passed down as props from
ApptoSlideRenderer, which then passes it to the appropriate layout and content components.
This architecture makes the application predictable, maintainable, and easy to debug.