# dhananjay-97/survey_generator architecture

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

- Interactive diagram: https://gitdiagram.com/dhananjay-97/survey_generator
- Repository: https://github.com/dhananjay-97/survey_generator

## Overview

##### Project Type & Purpose
- The project is a full-stack application centered around automating survey generation using AI. It features both a user-friendly web interface (via app.py) and a REST API interface (via flask_api.py) for programmatically generating surveys.
- The application leverages Flask, OpenAI’s GPT-3/ChatGPT APIs, and Python-docx for outputting survey documents in DOCX format.

##### Key Architectural Components
a. Web Interface Component:
- Web UI served by app.py.
- “templates” directory (HTML files) and the “static” assets (CSS from static/css), which together build the interactive survey creation wizard.

b. REST API Component:
- REST API endpoints provided by flask_api.py.
- Similarity in application logic between the web UI and API – both reach the core survey generation logic.

c. Survey Generation Module:
- Core logic (e.g., survey_generator.py) responsible for processing inputs (from either the UI or API) and delegating survey generation.
- This module uses stored “prompts” (see directories prompts/prompts_chatgpt and prompts/prompts_gpt3) that supply JSON templates for various survey questions.

d. External Services and Dependencies:
- OpenAI API: Show the external dependency where both the UI and API components call the AI (GPT-3/ChatGPT) for content creation.
- Configuration Source: Represent config.ini as the configuration file storing keys (e.g., OpenAI API keys).

##### Relationships & Data Flow
- The Survey Generation Module then fetches relevant “prompt” content (from the prompts directories), processes the request, and communicates with the OpenAI API.
- After processing, the module uses Python-docx to generate the DOCX file and returns the survey:
- For Web UI: The response is rendered using HTML templates.
- For REST API: The survey is returned as a downloadable file or a response payload.

##### Architectural Patterns & Design Principles
- Separation of concerns: Differentiate between presentation (templates and static files), application logic (Flask routes in app.py and flask_api.py), and core processing (survey_generator and prompt repositories).
- Modularity: Highlight the use of external prompt files for flexibility in survey generation and ease of maintenance.
- Configuration management: Emphasize how configuration settings (like the OpenAI API key stored in config.ini) are centrally managed.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client (Browser/API Consumer)"]:::client

    subgraph "Web Entry"
        WebUI["Web UI (app.py)"]:::web
        Templates["Templates (HTML)"]:::web
        StaticFiles["Static Files (CSS)"]:::web
        WebUI -->|"contains"| Templates
        WebUI -->|"contains"| StaticFiles
    end

    RESTAPI["REST API (flask_api.py)"]:::api

    Client -->|"viaBrowser"| WebUI
    Client -->|"viaAPI"| RESTAPI

    subgraph "Backend Processing"
        SurveyGen["Survey Generation Module (survey_generator.py)"]:::core
        RESTAPI -->|"calls"| SurveyGen
        WebUI -->|"calls"| SurveyGen

        Config["Configuration (config.ini)"]:::config
        Config --- SurveyGen

        subgraph "Prompts"
            PromptsChatGPT["Prompts ChatGPT (JSON)"]:::core
            PromptsGPT3["Prompts GPT-3 (JSON)"]:::core
        end
        SurveyGen -->|"uses"| PromptsChatGPT
        SurveyGen -->|"uses"| PromptsGPT3

        ExternalAI["OpenAI API (External Service)"]:::external
        SurveyGen -->|"calls"| ExternalAI

        DOCX["DOCX Generation (python-docx)"]:::external
        SurveyGen -->|"generates"| DOCX
    end

    SurveyGen -->|"returnsHTML"| WebUI
    SurveyGen -->|"returnsDOCX"| RESTAPI

    click WebUI "https://github.com/dhananjay-97/survey_generator/blob/main/app.py"
    click Templates "https://github.com/dhananjay-97/survey_generator/tree/main/templates/"
    click StaticFiles "https://github.com/dhananjay-97/survey_generator/blob/main/static/css/style.css"
    click RESTAPI "https://github.com/dhananjay-97/survey_generator/blob/main/flask_api.py"
    click SurveyGen "https://github.com/dhananjay-97/survey_generator/blob/main/survey_generator.py"
    click PromptsChatGPT "https://github.com/dhananjay-97/survey_generator/tree/main/prompts/prompts_chatgpt/"
    click PromptsGPT3 "https://github.com/dhananjay-97/survey_generator/tree/main/prompts/prompts_gpt3/"
    click Config "https://github.com/dhananjay-97/survey_generator/blob/main/config.ini"

    classDef web fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef api fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef core fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef external fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef config fill:#E0E0E0,stroke:#000,stroke-width:2px;
    classDef client fill:#D3D3D3,stroke:#000,stroke-width:2px;
```
