# nikhil-2x/quiz-application architecture

> Architecture diagram of the GitHub repository nikhil-2x/quiz-application, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nikhil-2x/quiz-application
- Repository: https://github.com/nikhil-2x/quiz-application

## Overview

1. This is a Flutter client application for a quiz product, with one shared Dart codebase targeting mobile, desktop, and web. The repository contains only the frontend; the backend service and Firebase project configuration live outside the repo.

2. The app starts in `lib/main.dart`, which is responsible for app bootstrap and Firebase initialization before the UI is shown. From there, the widget tree drives the full quiz flow and theming.

3. The core UX is organized into four screens under `lib/screens`: `home_screen.dart`, `quiz_screen.dart`, `result_screen.dart`, and `analysis_screen.dart`. These represent the main state transitions: enter user name, take the quiz, review results, and inspect AI-generated analysis.

4. `lib/screens/quiz_screen.dart` is the central orchestration point. It manages question progression, answer checking, wrong-answer behavior, and when to call external services for hints or completion analysis.

5. Data is modeled explicitly in `lib/models` using `question.dart`, `answered_question.dart`, and `quiz_attempt.dart`. These models form the boundary between Firestore documents, in-memory quiz state, and attempt history shown to the user.

6. Persistence is handled through `lib/services/firebase_service.dart`, which reads quiz questions from the Firestore `questions` collection and writes completed runs to `quiz_attempts`. Firestore is the app’s primary data source for content and history, not just a cache.

7. AI-related behavior is isolated in `lib/services/ai_api_service.dart`. The app calls a deployed external backend for two functions: requesting a hint after the first wrong answer, and requesting a performance report after the quiz finishes.

8. The README-defined flow is a two-system integration: Firestore provides quiz content and attempt storage, while the backend API provides dynamic AI responses. The Flutter client sits in the middle and coordinates both based on user actions.

9. `lib/widgets/hint_dialog.dart` is a focused UI boundary for presenting AI hints, keeping the hint interaction separate from the main quiz screen logic.

10. `lib/screens/result_screen.dart` is the post-quiz aggregation layer: it shows score results, recent attempts, and an entry point for AI analysis. This screen likely consumes both Firestore history and backend analysis output.

11. Platform directories under `android`, `ios`, `macos`, `windows`, `linux`, and `web` are standard Flutter host shells. They provide native launch/configuration glue, but the application logic remains in `lib/`.

12. Secrets and environment-specific Firebase values are externalized through `secrets.json` / `--dart-define-from-file`, which means the app is environment-configured at build time rather than hardcoding credentials in source.

13. Testing is light and centered on Flutter’s default widget test harness in `test/widget_test.dart`, suggesting the architecture is currently product-focused with minimal automated domain coverage.

14. The important architecture boundary is therefore: Flutter UI and client state in this repo, Firestore as the quiz datastore, and an external AI backend as a stateless service for hints and analysis.

Main entry points: [`lib/screens/quiz_screen.dart`](https://github.com/nikhil-2x/quiz-application/blob/main/lib/screens/quiz_screen.dart) (Quiz), [`lib/screens/result_screen.dart`](https://github.com/nikhil-2x/quiz-application/blob/main/lib/screens/result_screen.dart) (Results), [`lib/main.dart`](https://github.com/nikhil-2x/quiz-application/blob/main/lib/main.dart) (App entry), [`lib/services/firebase_service.dart`](https://github.com/nikhil-2x/quiz-application/blob/main/lib/services/firebase_service.dart) (Firestore service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Flutter client"]
  node_entry["App entry<br/>bootstrap<br/>[main.dart]"]
  node_home["Home<br/>screen<br/>[home_screen.dart]"]
  node_quiz["Quiz<br/>screen<br/>[quiz_screen.dart]"]
  node_result["Results<br/>screen<br/>[result_screen.dart]"]
  node_analysis["Analysis<br/>screen"]
  node_hint["Hint dialog<br/>ui-boundary<br/>[hint_dialog.dart]"]
  node_question_model["Question<br/>model<br/>[question.dart]"]
  node_answered_model["Answered question<br/>model"]
  node_attempt_model["Quiz attempt<br/>model<br/>[quiz_attempt.dart]"]
  node_firebase[("Firestore service<br/>data service")]
  node_ai["AI API service<br/>backend client"]
end

subgraph group_platform["Platform shells"]
  node_platforms{{"Host apps<br/>runtime shells"}}
end

subgraph group_config["Build config"]
  node_test["Widget test<br/>test harness<br/>[widget_test.dart]"]
  node_secrets["Secrets config<br/>build config"]
end

node_entry -->|"boots on"| node_platforms
node_entry -->|"shows"| node_home
node_entry -->|"initializes"| node_firebase
node_home -->|"starts"| node_quiz
node_quiz -->|"loads"| node_question_model
node_quiz -->|"tracks"| node_answered_model
node_quiz -->|"reads/writes"| node_firebase
node_quiz -->|"requests hint"| node_ai
node_quiz -->|"opens"| node_hint
node_quiz -->|"completes"| node_result
node_result -->|"shows"| node_attempt_model
node_result -->|"loads history"| node_firebase
node_result -->|"requests analysis"| node_ai
node_result -->|"opens"| node_analysis
node_firebase -->|"maps"| node_question_model
node_firebase -->|"persists"| node_attempt_model
node_test -->|"smokes"| node_entry
node_secrets -->|"configures"| node_entry

click node_entry "https://github.com/nikhil-2x/quiz-application/blob/main/lib/main.dart"
click node_home "https://github.com/nikhil-2x/quiz-application/blob/main/lib/screens/home_screen.dart"
click node_quiz "https://github.com/nikhil-2x/quiz-application/blob/main/lib/screens/quiz_screen.dart"
click node_result "https://github.com/nikhil-2x/quiz-application/blob/main/lib/screens/result_screen.dart"
click node_analysis "https://github.com/nikhil-2x/quiz-application/blob/main/lib/screens/analysis_screen.dart"
click node_hint "https://github.com/nikhil-2x/quiz-application/blob/main/lib/widgets/hint_dialog.dart"
click node_question_model "https://github.com/nikhil-2x/quiz-application/blob/main/lib/models/question.dart"
click node_answered_model "https://github.com/nikhil-2x/quiz-application/blob/main/lib/models/answered_question.dart"
click node_attempt_model "https://github.com/nikhil-2x/quiz-application/blob/main/lib/models/quiz_attempt.dart"
click node_firebase "https://github.com/nikhil-2x/quiz-application/blob/main/lib/services/firebase_service.dart"
click node_ai "https://github.com/nikhil-2x/quiz-application/blob/main/lib/services/ai_api_service.dart"
click node_test "https://github.com/nikhil-2x/quiz-application/blob/main/test/widget_test.dart"
click node_secrets "https://github.com/nikhil-2x/quiz-application/blob/main/secrets.json.example"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_home,node_quiz,node_result,node_analysis,node_hint,node_question_model,node_answered_model,node_attempt_model,node_firebase,node_ai toneBlue
class node_platforms toneAmber
class node_test,node_secrets toneMint
```

## Components

### Flutter client

Shared Dart application logic and UI under lib/.

- [App entry](https://github.com/nikhil-2x/quiz-application/blob/main/lib/main.dart): bootstrap · Starts the app and initializes Firebase before UI render. · `lib/main.dart`
- [Home](https://github.com/nikhil-2x/quiz-application/blob/main/lib/screens/home_screen.dart): screen · Collects user name and begins the quiz flow. · `lib/screens/home_screen.dart`
- [Quiz](https://github.com/nikhil-2x/quiz-application/blob/main/lib/screens/quiz_screen.dart): screen · Central quiz orchestration: progression, scoring, wrong-answer handling, and service calls. · `lib/screens/quiz_screen.dart`
- [Results](https://github.com/nikhil-2x/quiz-application/blob/main/lib/screens/result_screen.dart): screen · Shows score summary, recent attempts, and entry points to analysis. · `lib/screens/result_screen.dart`
- [Analysis](https://github.com/nikhil-2x/quiz-application/blob/main/lib/screens/analysis_screen.dart): screen · Displays AI-generated performance analysis after completion. · `lib/screens/analysis_screen.dart`
- [Hint dialog](https://github.com/nikhil-2x/quiz-application/blob/main/lib/widgets/hint_dialog.dart): ui-boundary · Dedicated UI for presenting AI hints without cluttering quiz flow. · `lib/widgets/hint_dialog.dart`
- [Question](https://github.com/nikhil-2x/quiz-application/blob/main/lib/models/question.dart): model · Firestore-backed quiz question model. · `lib/models/question.dart`
- [Answered question](https://github.com/nikhil-2x/quiz-application/blob/main/lib/models/answered_question.dart): model · In-memory record of a question plus the user's answer and correctness. · `lib/models/answered_question.dart`
- [Quiz attempt](https://github.com/nikhil-2x/quiz-application/blob/main/lib/models/quiz_attempt.dart): model · Persistent attempt history shown in results and stored in Firestore. · `lib/models/quiz_attempt.dart`
- [Firestore service](https://github.com/nikhil-2x/quiz-application/blob/main/lib/services/firebase_service.dart): data service · Reads questions from Firestore and writes completed quiz attempts. · `lib/services/firebase_service.dart`
- [AI API service](https://github.com/nikhil-2x/quiz-application/blob/main/lib/services/ai_api_service.dart): backend client · Calls the external backend for hints and completion analysis. · `lib/services/ai_api_service.dart`

### Platform shells

Native host projects for mobile, desktop, and web runtime launch.

- **Host apps**: runtime shells · Native and web launch shells that embed the shared Flutter codebase.

### Build config

Environment-specific and test-time repository boundaries.

- [Widget test](https://github.com/nikhil-2x/quiz-application/blob/main/test/widget_test.dart): test harness · Default Flutter widget test coverage with minimal domain-specific automation. · `test/widget_test.dart`
- [Secrets config](https://github.com/nikhil-2x/quiz-application/blob/main/secrets.json.example): build config · Externalized Firebase and environment values supplied at build time. · `secrets.json.example`

## Connections

- App entry → Host apps: boots on · The shared Flutter app runs inside platform-specific shells.
- App entry → Home: shows · App bootstrap leads into the home screen.
- App entry → Firestore service: initializes · Firebase setup happens before the UI flow starts.
- Home → Quiz: starts · User name entry begins the quiz session.
- Quiz → Question: loads · Questions are materialized from Firestore content.
- Quiz → Answered question: tracks · Selected answers are accumulated as quiz state.
- Quiz → Firestore service: reads/writes · Quiz screen pulls questions and persists completed attempts.
- Quiz → AI API service: requests hint · First wrong answer can trigger an AI hint request.
- Quiz → Hint dialog: opens · Hints are presented through a dedicated dialog boundary.
- Quiz → Results: completes · Quiz completion transitions to the results screen.
- Results → Quiz attempt: shows · Results summarize stored attempt history.
- Results → Firestore service: loads history · Recent attempts come from Firestore.
- Results → AI API service: requests analysis · Post-quiz analysis is fetched from the external backend.
- Results → Analysis: opens · Analysis screen is entered from results.
- Firestore service → Question: maps · Firestore documents are converted into question models.
- Firestore service → Quiz attempt: persists · Completed runs are stored as quiz attempt documents.
- Widget test → App entry: smokes · Default widget test exercises the app harness.
- Secrets config → App entry: configures · Build-time values feed Firebase initialization and runtime setup.
