I want a see a full stack preview
- User
I want a see a full stack preview
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
I want a see a full stack preview
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Great! Below is a full-stack preview of an Invoice Parsing Application, showing how the components interact and what the code would look like from frontend to backend to parsing service.
We'll walk through:
App.jsximport React, { useState } from "react";
import axios from "axios";
function App() {
const [file, setFile] = useState(null);
const [invoiceData, setInvoiceData] = useState(null);
const handleUpload = async () => {
const formData = new FormData();
formData.append("invoice", file);
try {
const res = await axios.post("http://localhost:3001/api/upload", formData);
setInvoiceData(res.data);
} catch (err) {
console.error("Error uploading invoice:", err);
}
};
return (
<div style={{ padding: "40px" }}>
<h2>📄 Invoice Parser</h2>
<input type="file" onChange={(e) => setFile(e.target.files[0])} />
<button onClick={handleUpload}>Upload Invoice</button>
{invoiceData && (
<div style={{ marginTop: "20px" }}>
<h3>Parsed Data:</h3>
<pre>{JSON.stringify(invoiceData, null, 2)}</pre>
</div>
)}
</div>
);
}
export default App;
server.jsconst express = require("express");
const multer = require("multer");
const axios = require("axios");
const path = require("path");
const app = express();
const upload = multer({ dest: "uploads/" });
// Forward uploaded file to Python parser
app.post("/api/upload", upload.single("invoice"), async (req, res) => {
try {
const filePath = path.resolve(req.file.path);
const response = await axios.post("http://localhost:5000/parse", { file: filePath });
res.json(response.data);
} catch (error) {
console.error("Parsing error:", error.message);
res.status(500).json({ error: "Failed to parse invoice" });
}
});
app.listen(3001, () => console.log("Backend running on http://localhost:3001"));
parser.pyfrom flask import Flask, request, jsonify
import pytesseract
from PIL import Image
import spacy
app = Flask(__name__)
# Load custom NLP model for invoices
nlp = spacy.load("./models/invoice_parser_model")
@app.route("/parse", methods=["POST"])
def parse_invoice():
file_path = request.json["file"]
raw_text = pytesseract.image_to_string(Image.open(file_path))
# Extract entities using spaCy
doc = nlp(raw_text)
extracted = {
"invoice_number": None,
"date": None,
"total_amount": None
}
for ent in doc.ents:
if ent.label_ in extracted:
extracted[ent.label_] = ent.text
return jsonify(extracted)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
schema.sqlCREATE TABLE IF NOT EXISTS invoices (
id SERIAL PRIMARY KEY,
invoice_number VARCHAR(100),
date DATE,
total_amount DECIMAL(12, 2),
file_path TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
You can use pg or sequelize to insert parsed data into this table after parsing.
docker-compose.ymlversion: "3"
services:
frontend:
build: ./invoice-parser-frontend
ports:
- "3000:3000"
volumes:
- ./invoice-parser-frontend:/app
- /app/node_modules
backend:
build: ./invoice-parser-backend
ports:
- "3001:3001"
depends_on:
- parser
parser:
build: ./invoice-parser-service
ports:
- "5000:5000"
INVOICE #: INV-12345
DATE: 2025-04-01
TOTAL AMOUNT: $899.99
{
"invoice_number": "INV-12345",
"date": "2025-04-01",
"total_amount": "$899.99"
}
invoice-parser-app/
├── docker-compose.yml
│
├── invoice-parser-frontend/
│ ├── App.jsx
│ └── package.json
│
├── invoice-parser-backend/
│ ├── server.js
│ └── package.json
│
└── invoice-parser-service/
├── parser.py
└── models/invoice_parser_model/
Start all services:
docker-compose up --build
Open frontend:
http://localhost:3000
Upload an invoice image (PNG/JPG/PDF), see parsed JSON output!
pdf2image and Tesseract.Would you like me to generate a full downloadable template with all the files included? Or do you want a version that supports PDFs and multi-language invoices?