# yanstu/subjectthree architecture

> Architecture diagram of the GitHub repository yanstu/subjectthree, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yanstu/subjectthree
- Repository: https://github.com/yanstu/subjectthree

## Overview

##### Project type and purpose
- This is a single‑page application (SPA) built with Vue 3 and TypeScript, served via Vite.
- Purpose: a “科目三灯光模拟考试系统” – a driving‑test lighting simulation quiz to help learners practice and review exam points.

##### File structure
- Top‑level:
- index.html – SPA host page
- assets/ – images referenced in README (static assets)
- src/ – application source code
- ├── main.ts – Vue app bootstrap
- ├── App.vue – root component
- ├── views/ – page‐level view components (WelcomeView, QuizView, ResultView)
- ├── components/ – reusable UI pieces (QuizHeader, QuizOption, QuizFeedback)
- ├── stores/ – Pinia state store (quiz.ts)
- ├── composables/ – custom hook (useTimer.ts)
- └── data/ – static question bank (questions.ts)
- Config files: tsconfig.json, vite.config.ts, package.json

##### README for additional insights
- Key features: random question order, timer, answer explanation, responsive design
- Tech stack: Vue 3, TypeScript, Vite, Pinia

a. Main components
- Browser/Client (SPA)
- index.html + Vite dev server (or production static hosting)
- Bundler: Vite+Rollup build pipeline
- Application layers inside SPA:
1) Presentation layer (Vue components & views)
2) State management (Pinia store)
3) Business logic (composable: timer)
4) Data layer (static question data)
- External services: None (static asset hosting only)

b. Relationships & interactions
- Browser loads index.html -> boots main.ts -> mounts App.vue
- App.vue routes to WelcomeView → QuizView → ResultView based on state
- Views render child components (QuizHeader, QuizOption, QuizFeedback)
- Components dispatch actions or read state from Pinia (quiz store)
- Pinia store pulls raw questions from data/questions.ts, shuffles sequence
- useTimer composable invoked by QuizView to manage countdown and emits events to store
- User answers flow: Component → Store (record answer) → Component displays feedback
- At end, store computes score and ResultView presents results

c. Architectural patterns & design principles
- Modular single‑page architecture
- MVC‑like separation:
- Views = “V” (views/ + components/)
- Store = “M” (Pinia)
- Actions & composable = “C” (logic)
- Composability: composable hooks for cross‑cutting concerns (timer)
- Static resource layer for test data

d. Key technologies & frameworks
- Vue 3 (component system, reactive)
- TypeScript (static typing)
- Vite (bundler & dev server)
- Pinia (store)
- Optional: external hosting (Netlify, GitHub Pages) for static assets

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build & Deploy Layer
    subgraph "Build & Deploy"
        VITE["Vite Config"]:::infra
        BUNDLE["Production Bundle"]:::infra
        HOST["Static Host"]:::infra
    end

    HOST -->|serves| INDEX["index.html"]:::infra
    VITE -->|bundles| BUNDLE
    BUNDLE -->|deployed to| HOST

    %% Browser & Entry
    INDEX -->|load| MAIN["src/main.ts"]:::infra
    MAIN -->|mount| APP["App.vue"]:::presentation

    %% Presentation Layer
    subgraph "Presentation Layer"
        subgraph "Views"
            WV["WelcomeView"]:::presentation
            QV["QuizView"]:::presentation
            RV["ResultView"]:::presentation
        end
        subgraph "Components"
            QH["QuizHeader"]:::presentation
            QO["QuizOption"]:::presentation
            QF["QuizFeedback"]:::presentation
        end
    end

    %% Logic Layer
    subgraph "Logic Layer"
        STORE["Quiz Store"]:::logic
        TIMER["useTimer (composable)"]:::logic
    end

    %% Data Layer
    subgraph "Data Layer"
        QUESTIONS["questions.ts"]:::data
        ASSETS["assets/"]:::data
    end

    %% Component Interactions
    APP -->|"routes to"| WV
    APP -->|"routes to"| QV
    APP -->|"routes to"| RV

    QV -->|uses| QH
    QV -->|uses| QO
    QV -->|uses| QF

    WV -->|reads| STORE
    QV -->|reads/writes| STORE
    RV -->|reads| STORE

    STORE -->|imports| QUESTIONS
    QV -->|invokes| TIMER
    TIMER -->|emits events to| STORE

    WV -->|"displays images from"| ASSETS
    QV -->|"displays images from"| ASSETS

    %% Click Events
    click INDEX "https://github.com/yanstu/subjectthree/blob/master/index.html"
    click VITE "https://github.com/yanstu/subjectthree/blob/master/vite.config.ts"
    click MAIN "https://github.com/yanstu/subjectthree/blob/master/src/main.ts"
    click APP "https://github.com/yanstu/subjectthree/blob/master/src/App.vue"
    click WV "https://github.com/yanstu/subjectthree/blob/master/src/views/WelcomeView.vue"
    click QV "https://github.com/yanstu/subjectthree/blob/master/src/views/QuizView.vue"
    click RV "https://github.com/yanstu/subjectthree/blob/master/src/views/ResultView.vue"
    click QH "https://github.com/yanstu/subjectthree/blob/master/src/components/QuizHeader.vue"
    click QO "https://github.com/yanstu/subjectthree/blob/master/src/components/QuizOption.vue"
    click QF "https://github.com/yanstu/subjectthree/blob/master/src/components/QuizFeedback.vue"
    click STORE "https://github.com/yanstu/subjectthree/blob/master/src/stores/quiz.ts"
    click TIMER "https://github.com/yanstu/subjectthree/blob/master/src/composables/useTimer.ts"
    click QUESTIONS "https://github.com/yanstu/subjectthree/blob/master/src/data/questions.ts"
    click ASSETS "https://github.com/yanstu/subjectthree/tree/master/assets/"

    %% Styles
    classDef presentation fill:#D0E8FF,stroke:#0366D6,stroke-width:2px
    classDef logic fill:#DFF5E1,stroke:#2E8B57,stroke-width:2px
    classDef data fill:#FFE8A1,stroke:#D99400,stroke-width:2px
    classDef infra fill:#F0F0F0,stroke:#666666,stroke-width:1px,stroke-dasharray: 2 2
```
