How shy742/shubh_sawariya works
Project type and purpose
• This is a full-stack web application (“BRM Financial Analyzer”) built with Flask (Python) on the backend and plain HTML/CSS/JavaScript (D3.js) on the frontend.
File structure
• Top-level files/directories
– app.py: main Flask application and HTTP API endpoints
– check_env.py: ensures required env vars (GOOGLE_API_KEY) are present
– cors_middleware.py: Flask middleware for handling CORS
– gunicorn_config.py, Procfile, render.yaml, runtime.txt, .buildpacks: deployment/config for Render.com and Gunicorn
– index.html, script.js, styles.css: static frontend assets
– requirements.txt: Python dependencies (Flask, PyPDF2, python-dotenv, etc.)
– test_api_key.py: unit test for env var validation
– .env, .gitignore: local dev config
• Patterns & architectural hints
– Monolithic service combining API server + static asset hosting
– Middleware pattern for CORS and environment checks
– Single codebase, no separate “frontend” microservice
Insights from README
• Backend: Flask handles file upload, PDF parsing, AI calls
• AI integration: Google Gemini AI for data extraction
• Visualization: D3-Sankey in script.js
• Deploy on Render.com with env vars
a. Main components
1. Client Browser (UI)
• index.html + script.js + styles.css
• D3.js for Sankey rendering and chat widget
2. Flask API Server
• Endpoints:
– /upload → handles PDF uploads
– /sankey-data → returns processed financial flows
– /chat → proxies chat queries to AI
• Middleware: CORS, env validation
• PDF processing: PyPDF2
3. External Service
• Google Gemini AI (via HTTPS REST API)
4. Infrastructure / Deployment
• Gunicorn WSGI server (gunicorn_config.py)
• Render.com (render.yaml, Procfile, .buildpacks)
b. Relationships & data flows
1. User uploads PDF via browser UI → HTTP POST to Flask
2. Flask → PyPDF2 extracts raw text/data
3. Flask → Google Gemini AI for semantic financial extraction
4. Gemini returns structured JSON → Flask formats for Sankey
5. Flask → JSON response → browser
7. Chat UI: browser sends query → Flask → Gemini → browser
c. Architectural patterns & principles
– Monolithic API + static asset server
– Layered pattern: Presentation (UI) → API layer → Service layer (PDF, AI)
– Middleware for cross-cutting concerns (CORS, config validation)
– Third-party service integration
d. Key technologies & libraries
– Flask, Gunicorn, python-dotenv, PyPDF2
– D3.js (D3-Sankey) for visualizations
– Render.com for hosting
– Google Gemini AI as external ML service
• Break the system into: Browser UI, Flask API, PDF Parser, AI Service, Deployment infra
• Interactions: upload → parse → AI call → JSON → rendering
• Technologies on each component
• Environment/configuration pieces (dotenv, gunicorn, Render) are noted in the infra section