File size: 7,419 Bytes
2a17081
 
 
 
 
 
 
 
 
 
 
afdd8ce
 
 
 
 
 
 
 
 
 
 
 
1269f33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
afdd8ce
1269f33
afdd8ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e058d03
afdd8ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1269f33
afdd8ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e058d03
afdd8ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1269f33
afdd8ce
1269f33
afdd8ce
 
 
 
1269f33
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
---
title: QuizFlash - AI-Powered Quiz Generation
emoji: πŸŽ“
colorFrom: blue
colorTo: purple
sdk: docker
pinned: false
license: mit
app_port: 3000
---

# QuizFlash πŸš€

An intelligent quiz generation platform powered by AI that creates customizable educational questions from any source material.

## Features

- **Multiple Question Types**: Support for multiple choice, cloze (fill-in-the-blank), grammar check, reading comprehension, and essay questions
- **AI-Powered Generation**: Uses OpenAI GPT-4 to generate high-quality, educational questions
- **Configurable Parameters**: Each question type has customizable difficulty levels and specific parameters
- **Source Material Support**: Generate questions based on your own text content
- **Real-time Question Bank**: Build and manage a collection of generated questions
- **Modern UI**: Clean, responsive interface built with Next.js and Tailwind CSS

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

## System Architecture

```mermaid
graph TD
    A["πŸ”§ Question Config<br/>(questionConfig.ts)"] --> B["πŸ“‹ Parameter Form<br/>(QuestionParameterForm)"]
    B --> C["πŸŽ›οΈ Parameter Input<br/>(ParameterInput)"]
    C --> D["πŸ‘€ User Input<br/>(UI Interaction)"]
    D --> E["πŸ“Š Parameters Object<br/>(QuestionParameters)"]
    
    E --> F["🎯 Question Type<br/>Selection"]
    F --> G["πŸ“ Source Material<br/>(Optional)"]
    
    E --> H["πŸš€ Generate Question<br/>(API Call)"]
    G --> H
    
    H --> I["πŸ€– AI Generation<br/>(OpenAI API)"]
    
    I --> J["πŸ“„ Prompt Templates<br/>(prompt-management.ts)"]
    J --> K["πŸ”„ Template Rendering<br/>(renderTemplate)"]
    K --> L["πŸ“€ Final Prompt<br/>(to AI Model)"]
    
    L --> M["🧠 AI Processing<br/>(GPT-4 Mini)"]
    M --> N["πŸ“‹ Zod Schema<br/>Validation"]
    N --> O["βœ… Structured Response<br/>(JSON Object)"]
    
    O --> P["πŸ’Ύ Question Bank<br/>(State Management)"]
    P --> Q["🎴 Question Card<br/>(UI Component)"]
    
    Q --> R["πŸ‘οΈ User Display<br/>(Question Bank UI)"]
    
    subgraph "Configuration Layer"
        A
        B
        C
    end
    
    subgraph "User Interaction Layer"
        D
        E
        F
        G
    end
    
    subgraph "API Processing Layer"
        H
        I
        J
        K
        L
    end
    
    subgraph "AI Generation Layer"
        M
        N
        O
    end
    
    subgraph "Display Layer"
        P
        Q
        R
    end
    
    style A fill:#e1f5fe
    style J fill:#fff3e0
    style Q fill:#f3e5f5
    style M fill:#e8f5e8
```

### Flow Description

#### 1. Configuration Layer
- **Question Config**: Abstract configuration system that defines parameter schemas for each question type
- **Parameter Form**: Dynamically renders form fields based on the configuration
- **Parameter Input**: Reusable input components (select, range, input, checkbox)

#### 2. User Interaction Layer
- **User Input**: Users interact with dynamically generated parameter forms
- **Parameters Object**: Collects user preferences (difficulty, number of options, etc.)
- **Question Type Selection**: Users choose from available question types
- **Source Material**: Optional text input to provide context for questions

#### 3. API Processing Layer
- **Generate Question**: API endpoint processes the generation request
- **Prompt Templates**: Pre-defined, configurable templates for each question type
- **Template Rendering**: Dynamic substitution of user parameters into prompt templates
- **Final Prompt**: Complete, contextualized prompt ready for AI processing

#### 4. AI Generation Layer
- **AI Processing**: OpenAI GPT-4 Mini generates questions based on the prompt
- **Zod Schema Validation**: Ensures AI responses match expected structure
- **Structured Response**: Clean, validated JSON object containing question data

#### 5. Display Layer
- **Question Bank**: State management for storing and organizing generated questions
- **Question Card**: UI components for rendering individual questions
- **User Display**: Final question bank interface with selection and management features

### Key Architecture Benefits

- **πŸ”§ Configurable**: Adding new question types requires only configuration changes
- **♻️ Reusable**: Components work across all question types
- **πŸ›‘οΈ Type-Safe**: Full TypeScript support throughout the entire flow
- **πŸ“¦ Modular**: Clean separation of concerns between layers
- **πŸš€ Scalable**: Easy to extend with new features and question types

## Tech Stack

- **Frontend**: Next.js 14, React, TypeScript, Tailwind CSS
- **AI Integration**: OpenAI GPT-4 Mini, Vercel AI SDK
- **Validation**: Zod schema validation
- **Styling**: Tailwind CSS with dark mode support
- **State Management**: React hooks and context

## Project Structure

```
src/
β”œβ”€β”€ app/                    # Next.js App Router
β”‚   β”œβ”€β”€ api/               # API routes
β”‚   β”‚   β”œβ”€β”€ chat/         # Chat functionality
β”‚   β”‚   β”œβ”€β”€ generate-question/ # Single question generation
β”‚   β”‚   └── generate-quiz/ # Multiple question generation
β”‚   └── page.tsx          # Main application page
β”œβ”€β”€ components/            # React components
β”‚   β”œβ”€β”€ QuestionParameterForm.tsx  # Dynamic parameter form
β”‚   └── ParameterInput.tsx         # Reusable input components
β”œβ”€β”€ types/                 # TypeScript type definitions
β”‚   β”œβ”€β”€ quiz.ts           # Core quiz types
β”‚   └── questionConfig.ts # Configuration types and schemas
└── prompts/              # AI prompt templates
    └── prompt-management.ts # Question generation prompts
```

## Adding New Question Types

Thanks to the abstract configuration system, adding new question types is incredibly simple:

1. Add configuration to `src/types/questionConfig.ts`:
```typescript
'your-new-type': {
  id: 'your-new-type',
  parameters: [
    {
      key: 'difficulty',
      label: 'Difficulty Level',
      type: 'select',
      defaultValue: 'intermediate',
      options: [
        { value: 'beginner', label: 'Beginner' },
        { value: 'intermediate', label: 'Intermediate' },
        { value: 'advanced', label: 'Advanced' },
      ],
    },
    // Add more parameters as needed
  ],
}
```

2. That's it! No component modifications required. The UI will automatically render the appropriate form fields.

## Learn More

To learn more about the technologies used:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API
- [Vercel AI SDK](https://sdk.vercel.ai/docs) - AI integration toolkit
- [OpenAI API](https://platform.openai.com/docs) - AI model documentation
- [Tailwind CSS](https://tailwindcss.com/docs) - utility-first CSS framework

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.