How 0xvish/tatvascan works
Project type and purpose
• This is a full-stack, web-based application (“TatvaScan”) that lets users upload or capture an image in the browser, uses Tesseract.js to perform OCR on the image, and sends the extracted ingredients to a Java Servlet backend. The backend calls the Gemini LLM API to analyze ingredient safety/allergens, then returns rich Markdown-formatted results to the UI.
File structure
• Top-level files:
• Dockerfile, .dockerignore, .gitignore – containerization/dev-ops
• pom.xml – Maven project descriptor for build and dependencies
• README.md, documents/ – documentation
• src/main/java/com/vish/tatvascan/GeminiServlet.java – the single servlet handling API calls
• src/main/webapp/index.jsp – main entrypoint UI
• src/main/webapp/WEB-INF/web.xml – servlet mapping and deployment descriptor
• Packaging: everything is assembled into a WAR and deployed on Apache Tomcat
Key insights from the README
• Frontend: HTML/JSP + Bootstrap + JavaScript libraries (Tesseract.js for OCR, Marked.js for Markdown rendering)
• Backend: Java Servlet (GeminiServlet) running on Tomcat
• LLM Integration: calls Gemini API using environment variable TATVASCAN_GEMINI_API_KEY
• Build & Deploy: Maven → target/tatvascan.war → Tomcat webapps/
Main components
a. User’s Browser (Client)
• index.jsp UI
• JavaScript modules: Tesseract.js (OCR), Marked.js (Markdown)
b. Web Server / Servlet Container
• Apache Tomcat hosting our WAR
• web.xml + GeminiServlet
c. Backend Service
• GeminiServlet processes HTTP POST requests
• Ingredient sanitization, Markdown formatting
d. External API
• Gemini LLM API (requires API key via env var)
e. Build & Deployment
• Maven (pom.xml) → .war
• Dockerfile (optional container)
Relationships and data flows
1. User uploads/captures image → Browser
2. Browser invokes Tesseract.js → extracts text
3. Extracted text → JavaScript POST to /GeminiServlet
4. GeminiServlet receives text → sanitizes → calls Gemini API over HTTPS
5. Gemini returns analysis → Servlet wraps as JSON/HTML → response
6. Browser receives response → renders with Marked.js
Architectural patterns & design principles
• MVC-style separation: JSP view, Java Servlet controller, no persistent model but intermediate data objects
• Client-heavy OCR (privacy & speed): OCR runs entirely in-browser
• Thin backend: delegates intelligence to external LLM service
• Environment-based configuration: API key via system env var
Detailed elements to capture
• index.jsp (entrypoint)
• Tesseract.js OCR module
• Marked.js renderer
• web.xml servlet mapping
• GeminiServlet.java business logic
• System env var TATVASCAN_GEMINI_API_KEY
• Maven (pom.xml) → target/tatvascan.war
• Tomcat webapps folder
• External Gemini LLM API