# ratna-babu/jntuk-question-bank-solver architecture

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

- Interactive diagram: https://gitdiagram.com/ratna-babu/jntuk-question-bank-solver
- Repository: https://github.com/ratna-babu/jntuk-question-bank-solver

## Overview

##### Project Type and Purpose
- The project is a full-stack web application built with Next.js 13+ and React.
- Its purpose is to allow users to upload a PDF of a question bank, extract questions, generate detailed answers using Google’s Generative AI (Gemini), and finally produce an answer PDF.
- The process involves handling file uploads, PDF text extraction (using pdf-parse), AI integration, and generating downloadable PDFs.

##### Analyzing the File Structure
- The top-level “app” directory indicates use of Next.js 13’s App Router. Here you have:
- Pages (e.g., app/page.js – the home page for file upload)
- API routes (under app/api/):
▸ app/api/extract-questions/route.js – handles question extraction from PDFs.
▸ app/api/generate-answers/route.js – calls the Gemini API to generate detailed answers.
- Other directories like "components" (e.g., ErrorBoundary.js) and configuration files under "app/config" (e.g., answerFormat.js, fakeanswer.js) that provide settings for the operations.
- The “public” folder contains static assets including a generated answers PDF, suggesting that the output is served statically post-generation.

##### Key Components & Their Relationships
- Frontend (Next.js/React UI):
- Provides the user interface – upload button, progress feedback, and a link to download the generated PDF.
- Consumes API endpoints for question extraction and answer generation.
- Backend (Next.js API Routes):
- Endpoint for extracting questions from the uploaded PDF.
- Endpoint for generating answers with Google Generative AI.
- PDF Processing Module:
- Uses the pdf-parse library to extract text/questions from the PDF.
- AI Integration:
- Connects to Google Generative AI (Gemini) for generating detailed answers. This integration is critical as it drives the answer generation logic.
- File/Asset Management:
- Uploaded PDFs are processed.
- Generated answer PDFs are stored in the “public” directory to be easily served.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The file structure neatly divides UI components, API endpoints, configuration, and static assets.
- Modular API Endpoints: Clearly split between extraction and answer generation.
- External API Integration: The system depends on an external AI API which is modular and can be replaced or updated independently.
- Use of Next.js best practices: Leveraging file-based routing for APIs and components within the “app” directory.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        C("Client Browser"):::client
    end

    subgraph "Frontend (Next.js/React UI)"
        FP1("Home Page (File Upload)"):::frontend
        FP2("PDF Processing Page"):::frontend
        FP3("Error Boundary"):::frontend
    end

    subgraph "Backend API"
        BE1("Extract Questions API"):::backend
        BE2("Generate Answers API"):::backend
        CFG1("Config: answerFormat.js"):::backend
        CFG2("Config: fakeanswer.js"):::backend
    end

    PDF("PDF Processing Module (pdf-parse)"):::pdf
    AI("Google Generative AI (Gemini)"):::ai
    FS("File Storage (Generated Answers PDF)"):::storage

    C -->|"PDF_Upload"| FP1
    FP1 -->|"Upload_PDF"| BE1
    BE1 -->|"Extract_Text"| PDF
    BE1 -->|"Trigger_Answer_Generation"| BE2
    BE2 -->|"Call_Gemini_API"| AI
    BE2 -->|"Store_PDF"| FS
    BE2 -->|"Use_Answer_Format"| CFG1
    BE2 -->|"Fallback_Logic"| CFG2
    FS -->|"Download_PDF"| C

    click FP1 "https://github.com/ratna-babu/jntuk-question-bank-solver/blob/WorkingMain/app/page.js"
    click FP2 "https://github.com/ratna-babu/jntuk-question-bank-solver/blob/WorkingMain/app/pdf-process/page.jsx"
    click FP3 "https://github.com/ratna-babu/jntuk-question-bank-solver/blob/WorkingMain/app/components/ErrorBoundary.js"
    click BE1 "https://github.com/ratna-babu/jntuk-question-bank-solver/blob/WorkingMain/app/api/extract-questions/route.js"
    click BE2 "https://github.com/ratna-babu/jntuk-question-bank-solver/blob/WorkingMain/app/api/generate-answers/route.js"
    click CFG1 "https://github.com/ratna-babu/jntuk-question-bank-solver/blob/WorkingMain/app/config/answerFormat.js"
    click CFG2 "https://github.com/ratna-babu/jntuk-question-bank-solver/blob/WorkingMain/app/config/fakeanswer.js"
    click FS "https://github.com/ratna-babu/jntuk-question-bank-solver/blob/WorkingMain/public/generated_answers.pdf"

    classDef client fill:#FFFACD,stroke:#333,stroke-width:2px;
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef pdf fill:#E0E0E0,stroke:#333,stroke-width:2px;
    classDef ai fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef storage fill:#FFDAB9,stroke:#333,stroke-width:2px;
```
