# zanhne/requirement-generate-oop architecture

> Architecture diagram of the GitHub repository zanhne/requirement-generate-oop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zanhne/requirement-generate-oop
- Repository: https://github.com/zanhne/requirement-generate-oop

## Overview

##### Project Type and Purpose
- This is a full-stack web application built with a Python-Flask backend and a static HTML/CSS/JavaScript frontend.
- Purpose: generate detailed OOAD requirement descriptions on demand using the Google Gemini LLM (via Langchain) and present them in a user-friendly UI with PDF export.

##### File Structure
- Top-level files:
- main.py – Flask application entry point
- requirements.txt, .env.example – dependency and environment configuration
- README.md, LICENSE – project documentation
- app/ directory – backend code, organized by layered/domain structure:
- __init__.py – app creation, configuration, dependency injection
- domain/
– controller/RequirementController.py (Presentation layer: HTTP request → Service)
– service/RequirementService.py (Business logic layer: prompt construction & AI call)
◦ external/gemini/boundary (IGemini interface)
◦ external/gemini/adapter (GeminiAdapter implementation)
◦ external/gemini/structure (Pydantic model for LLM JSON output)
– DTO/DTO.py (Input DTO, validation)
– entity/entity.py (Business entities, prompt builder)
– enum/enum.py (Domain enums)
– prompt_template_example.txt (Prompt template resource)
- static/ (CSS & JS for client-side UI + jsPDF export)
- templates/generate.html (Jinja2 template for UI)
- No database: the only external dependency is the Google Gemini service.

##### README Insights
- Architectural principles: Layered (Controller–Service–Domain–Adapter), SOLID (SRP, DIP), GRASP, Adapter pattern for external AI integration, Builder pattern for prompt composition.
- Technologies: Flask, Flask-CORS, python-dotenv, Pydantic, Langchain Google GenAI, jsPDF on client.

a. Main Components
- Client Browser
– UI Layer: HTML/CSS/Vanilla JS, jsPDF for PDF export
– Interacts via HTTP/Fetch API
- Backend Flask App
– Presentation Layer: RequirementController
– Service Layer: RequirementService
– Domain Layer: DTO, Entity (Information, RequirementPromptBuilder), Enum
– External Integration Layer: IGemini boundary & GeminiAdapter
– Configuration: .env for GEMINI_API_KEY
- External Service
– Google Gemini LLM (via Langchain’s ChatGoogleGenerativeAI)
b. Relationships & Data Flow
1. User requests page → Browser loads generate.html + static assets.
2. On “Generate” click, JS → HTTP POST `/generate` with user input or random flag.
3. Flask RequirementController receives request → calls RequirementService.
4. RequirementService builds prompt via RequirementPromptBuilder (reads template file).
5. Service calls IGemini interface → GeminiAdapter invokes Google Gemini through Langchain.
6. Gemini returns JSON → parsed by Pydantic model (RequirementStructure).
7. Service assembles result DTO → Controller returns JSON response.
8. Browser JS renders the result and offers jsPDF export.
c. Architectural Patterns & Principles
- Layered architecture for separation of concerns
- Adapter pattern for AI provider abstraction (IGemini ↔ GeminiAdapter)
- Builder pattern in prompt composition (RequirementPromptBuilder)
- SOLID: SRP in each class, DIP in Service depending on IGemini interface
d. Key Technologies / Libraries
- Flask (+ Flask-CORS)
- Langchain & langchain-google-genai
- Pydantic (data validation & JSON parsing)
- python-dotenv (environment config)
- Vanilla JS + jsPDF (client-side PDF generation)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (Browser)"
        UI["generate.html"]:::client
        CSS["CSS (generate.css)"]:::client
        JS["JavaScript + jsPDF (generate.js)"]:::client
    end

    %% Server Layer
    subgraph "Server (Flask App)"
        Main["main.py"]:::entry
        ConfigEnv[".env.example"]:::config
        Requirements["requirements.txt"]:::config
        subgraph "Controllers"
            Controller["RequirementController"]:::controller
        end
        subgraph "Services"
            IReqService["IRequirementService"]:::serviceInterface
            ReqService["RequirementService"]:::service
        end
        subgraph "Domain"
            DTO["DTO"]:::domain
            Entity["RequirementPromptBuilder\n(Entity)"]:::domain
            Enum["Enums"]:::domain
            Template["prompt_template_example.txt"]:::resource
        end
        subgraph "External Integration"
            IGemini["IGemini"]:::boundary
            Adapter["GeminiAdapter «Adapter»"]:::adapter
            Structure["RequirementStructure\n(Pydantic)"]:::structure
        end
    end

    %% External Service
    GoogleLLM["Google Gemini LLM"]:::external

    %% Data Flows
    UI -->|"loads"| CSS
    UI -->|"loads"| JS
    JS -->|"POST /generate"| Controller
    Controller -->|"calls"| ReqService
    ReqService -->|"depends on"| IReqService
    IReqService -->|"implemented by"| Adapter
    ReqService -->|"builds prompt via"| Entity
    Entity -->|"reads template"| Template
    ReqService -->|"calls"| IGemini
    IGemini -->|"uses adapter"| Adapter
    Adapter -->|"invokes via Langchain"| GoogleLLM
    GoogleLLM -->|"returns JSON"| Structure
    Structure -->|"parsed by"| ReqService
    ReqService -->|"returns DTO"| Controller
    Controller -->|"responds JSON"| JS
    Main -->|"creates app / config"| Controller
    Main -->|"loads env"| ConfigEnv
    Main -->|"requires deps"| Requirements

    %% Click Events
    click Main "https://github.com/zanhne/requirement-generate-oop/blob/main/main.py"
    click ConfigEnv "https://github.com/zanhne/requirement-generate-oop/blob/main/.env.example"
    click Requirements "https://github.com/zanhne/requirement-generate-oop/blob/main/requirements.txt"
    click Controller "https://github.com/zanhne/requirement-generate-oop/blob/main/app/domain/controller/RequirementController.py"
    click ReqService "https://github.com/zanhne/requirement-generate-oop/blob/main/app/domain/service/RequirementService.py"
    click IReqService "https://github.com/zanhne/requirement-generate-oop/blob/main/app/domain/service/interface/IRequirementService.py"
    click IGemini "https://github.com/zanhne/requirement-generate-oop/blob/main/app/domain/service/external/gemini/boundary/gemini_boundary.py"
    click Adapter "https://github.com/zanhne/requirement-generate-oop/blob/main/app/domain/service/external/gemini/boundary/gemini_adapter.py"
    click Structure "https://github.com/zanhne/requirement-generate-oop/blob/main/app/domain/service/external/gemini/structure/structure.py"
    click DTO "https://github.com/zanhne/requirement-generate-oop/blob/main/app/domain/DTO/DTO.py"
    click Entity "https://github.com/zanhne/requirement-generate-oop/blob/main/app/domain/entity/entity.py"
    click Template "https://github.com/zanhne/requirement-generate-oop/blob/main/app/domain/entity/prompt_template_example.txt"
    click Enum "https://github.com/zanhne/requirement-generate-oop/blob/main/app/domain/enum/enum.py"
    click CSS "https://github.com/zanhne/requirement-generate-oop/blob/main/app/static/css/generate.css"
    click JS "https://github.com/zanhne/requirement-generate-oop/blob/main/app/static/js/generate.js"
    click UI "https://github.com/zanhne/requirement-generate-oop/blob/main/app/templates/generate.html"

    %% Styles
    classDef client fill:#D0E6FF,stroke:#0366D6,color:#0366D6;
    classDef controller fill:#E2F0D9,stroke:#228C22,color:#228C22;
    classDef service fill:#E2F0D9,stroke:#2E8B57,color:#2E8B57;
    classDef serviceInterface fill:#E2F0D9,stroke:#006400,color:#006400;
    classDef domain fill:#F0FFF0,stroke:#228B22,color:#228B22;
    classDef resource fill:#FFF8DC,stroke:#DAA520,color:#DAA520;
    classDef boundary fill:#F5FFF5,stroke:#008000,color:#008000;
    classDef adapter fill:#F0FFF0,stroke:#006400,color:#006400;
    classDef structure fill:#FFEFD5,stroke:#FF8C00,color:#FF8C00;
    classDef config fill:#F5F5F5,stroke:#696969,color:#696969;
    classDef entry fill:#F5F5F5,stroke:#808080,color:#808080;
    classDef external fill:#FFE5E5,stroke:#DC143C,color:#DC143C;
```
