# likegecko/jlpt-daily-quiz architecture

> Architecture diagram of the GitHub repository likegecko/jlpt-daily-quiz, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/likegecko/jlpt-daily-quiz
- Repository: https://github.com/likegecko/jlpt-daily-quiz

## Overview

##### Main Components Identification

a) Frontend Layer:
- Client-side Pages (/app directory)
- UI Components (/components directory)
- Custom Hooks (/hooks directory)

b) Backend Layer:
- API Routes (/app/api directory)
- External Services Integration:
- Firebase (lib/firebase.ts)
- Resend Email Service (lib/resend.ts)

c) Data Layer:
- Static Data (public/words/n5.json)
- Quiz Generation System (utils/generate-quiz.ts)

**┌─ Client Layer ─────────────────────┐**
- Pages (/, /words/n5/[wordId])    │
- UI Components                    │
- Subscribe Popup                  │
- ┬───────────────────┘
- ↕
**┌─ API Layer ────┴───────────────────┐**
- Quiz API (/api/quizs)           │
- Subscribe API (/api/subscribe)   │
- Verification API                 │
- ┬───────────────────┘
- ↕
**┌─ Service Layer ┴───────────────────┐**
- Firebase Integration            │
- Resend Email Service           │
- ┬───────────────────┘
- ↕
**┌─ Data Layer ───┴───────────────────┐**
- N5 Words JSON                   │
- Quiz Generation Logic           │
- ┘

##### Component Relationships

- Client-to-API communication (REST/API routes)
- API-to-Service interactions
- Data flow between quiz generation and storage

##### Technical Stack Indicators

- Next.js 13+ (App Router)
- TypeScript
- Tailwind CSS
- Firebase
- Resend Email Service

##### Detailed Component Breakdown

For each major section, include:

Client Layer:
- Page Components
- Shared UI Components (buttons, cards, dialogs)
- Custom Hooks (useToast)

API Layer:
- Quiz Management
- Subscription Handling
- Email Verification

Service Layer:
- Firebase Configuration
- Email Service Setup

Data Layer:
- Static Word Data
- Quiz Generation Logic

##### Additional Notes

- The app's serverless architecture
- API route organization
- Component reusability
- Data flow for quiz generation and delivery

Remember to maintain a balance between detail and clarity, focusing on the architectural decisions that make this application unique, such as the daily quiz system and the subscription verification flow.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        MainPage["Main Page"]:::page
        WordDetail["Word Detail Page"]:::page
        RootLayout["Root Layout"]:::page
        
        subgraph UIComponents["UI Components"]
            direction TB
            QuizTemplate["Quiz Template"]:::component
            AppBar["App Bar"]:::component
            Footer["Footer"]:::component
            Spinner["Loading Spinner"]:::component
            
            subgraph SubscribeSystem["Subscribe System"]
                direction TB
                SubPopup["Subscribe Popup"]:::component
                SubForm["Subscribe Form"]:::component
                VerifyForm["Verification Form"]:::component
                Success["Success View"]:::component
                SubPopup --> SubForm
                SubPopup --> VerifyForm
                SubPopup --> Success
            end
        end
        
        CustomHooks["Custom Hooks (Toast)"]:::util
    end
    
    subgraph APILayer["API Layer"]
        QuizAPI["Quiz API"]:::api
        SubscribeAPI["Subscribe API"]:::api
        VerifyAPI["Verification API"]:::api
    end
    
    subgraph Services["Service Layer"]
        Firebase["Firebase"]:::service
        ResendEmail["Resend Email Service"]:::service
    end
    
    subgraph DataLayer["Data Layer"]
        N5Words["N5 Words JSON"]:::data
        QuizGen["Quiz Generation System"]:::util
        DailyQuiz["Daily Quiz Workflow"]:::automation
    end
    
    MainPage --> QuizAPI
    WordDetail --> N5Words
    SubForm --> SubscribeAPI
    VerifyForm --> VerifyAPI
    
    QuizAPI --> QuizGen
    QuizAPI --> ResendEmail
    SubscribeAPI --> Firebase
    SubscribeAPI --> ResendEmail
    VerifyAPI --> Firebase
    
    QuizGen --> N5Words
    DailyQuiz --> QuizGen
    
    %% Click Events
    click MainPage "https://github.com/likegecko/jlpt-daily-quiz/blob/main/app/page.tsx"
    click WordDetail "https://github.com/likegecko/jlpt-daily-quiz/blob/main/app/words/n5/[wordId]/page.tsx"
    click RootLayout "https://github.com/likegecko/jlpt-daily-quiz/blob/main/app/layout.tsx"
    click QuizTemplate "https://github.com/likegecko/jlpt-daily-quiz/blob/main/components/QuizTemplate.tsx"
    click AppBar "https://github.com/likegecko/jlpt-daily-quiz/blob/main/components/Appbar.tsx"
    click Footer "https://github.com/likegecko/jlpt-daily-quiz/blob/main/components/Footer.tsx"
    click Spinner "https://github.com/likegecko/jlpt-daily-quiz/blob/main/components/Spinner.tsx"
    click SubPopup "https://github.com/likegecko/jlpt-daily-quiz/blob/main/components/SubscribePopup/index.tsx"
    click SubForm "https://github.com/likegecko/jlpt-daily-quiz/blob/main/components/SubscribePopup/SubscribeForm.tsx"
    click VerifyForm "https://github.com/likegecko/jlpt-daily-quiz/blob/main/components/SubscribePopup/VerificationForm.tsx"
    click Success "https://github.com/likegecko/jlpt-daily-quiz/blob/main/components/SubscribePopup/Success.tsx"
    click CustomHooks "https://github.com/likegecko/jlpt-daily-quiz/blob/main/hooks/use-toast.ts"
    click QuizAPI "https://github.com/likegecko/jlpt-daily-quiz/blob/main/app/api/quizs/send/route.ts"
    click SubscribeAPI "https://github.com/likegecko/jlpt-daily-quiz/blob/main/app/api/subscribe/route.ts"
    click VerifyAPI "https://github.com/likegecko/jlpt-daily-quiz/blob/main/app/api/subscribe/verify/route.ts"
    click Firebase "https://github.com/likegecko/jlpt-daily-quiz/blob/main/lib/firebase.ts"
    click ResendEmail "https://github.com/likegecko/jlpt-daily-quiz/blob/main/lib/resend.ts"
    click N5Words "https://github.com/likegecko/jlpt-daily-quiz/blob/main/public/words/n5.json"
    click QuizGen "https://github.com/likegecko/jlpt-daily-quiz/blob/main/utils/generate-quiz.ts"
    click DailyQuiz "https://github.com/likegecko/jlpt-daily-quiz/blob/main/.github/workflows/daily-quiz.yml"
    
    %% Styling
    classDef page fill:#2563eb,color:white
    classDef component fill:#3b82f6,color:white
    classDef api fill:#22c55e,color:white
    classDef service fill:#f97316,color:white
    classDef data fill:#a855f7,color:white
    classDef util fill:#64748b,color:white
    classDef automation fill:#ef4444,color:white
```
