How zanhne/requirement-generate-oop works
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)