Drop your sketch here
or
JPEG · PNG · WebP · Max 5MB
Release to upload
Your diagram will appear here
API Reference
Integrate Structura into your own app. One endpoint, multipart form data, JSON response.
POST /digitise
Accepts a whiteboard image and returns structured Mermaid code, a visual diagram, and raw JSON describing the extracted nodes and edges.
Want to explore interactively? Try the built-in Swagger UI →
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
file |
File | required | Image file — JPEG, PNG, or WebP. Max 5MB. |
Code Samples
curl -X POST https://structura-kw47.onrender.com/digitise \ -F "file=@/path/to/whiteboard.jpg"
import requests
with open("whiteboard.jpg", "rb") as f:
response = requests.post(
"https://structura-kw47.onrender.com/digitise",
files={"file": ("whiteboard.jpg", f, "image/jpeg")}
)
if response.status_code == 200:
data = response.json()
print("Mermaid code:")
print(data["mermaid"])
print(f"\nModel used: {data['model_used']}")
print(f"Nodes: {len(data['raw']['nodes'])}")
print(f"Edges: {len(data['raw']['edges'])}")
else:
print(f"Error {response.status_code}: {response.json()['detail']}")
const formData = new FormData();
formData.append("file", fileInput.files[0]);
const response = await fetch("https://structura-kw47.onrender.com/digitise", {
method: "POST",
body: formData,
});
if (response.ok) {
const data = await response.json();
console.log("Mermaid:", data.mermaid);
console.log("Model used:", data.model_used);
console.log("Nodes:", data.raw.nodes);
} else {
const err = await response.json();
console.error("Error:", err.detail);
}
200 — Success
{
"mermaid": "graph TD\n A[\"Start\"] --> B[\"Initialize\"]\n B --> C{\"Condition?\"}\n C -->|\"Yes\"| D[\"Process\"]\n C -->|\"No\"| E[\"End\"]",
"model_used": "gemini-2.5-flash",
"raw": {
"diagram_type": "flowchart",
"title": null,
"nodes": [
{ "id": "A", "label": "Start", "shape": "circle" },
{ "id": "B", "label": "Initialize", "shape": "rect" },
{ "id": "C", "label": "Condition?", "shape": "diamond" },
{ "id": "D", "label": "Process", "shape": "rect" },
{ "id": "E", "label": "End", "shape": "circle" }
],
"edges": [
{ "from": "A", "to": "B", "label": "", "style": "solid" },
{ "from": "B", "to": "C", "label": "", "style": "solid" },
{ "from": "C", "to": "D", "label": "Yes", "style": "solid" },
{ "from": "C", "to": "E", "label": "No", "style": "solid" }
]
}
}
Error Codes
| Code | Status | Meaning |
|---|---|---|
400 | Bad Request | Invalid file type or file exceeds 5MB |
429 | Too Many Requests | Rate limit exceeded — 10 requests per 60 seconds per IP |
500 | Internal Server Error | Extraction failed — JSON parse error or all models failed |
504 | Gateway Timeout | Gemini API timed out |
{
"detail": "File too large. Maximum size is 5MB"
}
POST /chemistry
Accepts a chemical formula or molecule name and returns a 2D structural diagram image, SMILES notation, and molecular metadata.
Want to explore interactively? Try the built-in Swagger UI →
Parameters
Accepts JSON body — not multipart form data like /digitise.
| Field | Type | Required | Description |
|---|---|---|---|
formula |
string | required | Chemical formula (e.g. H2O), common name (e.g. caffeine), or IUPAC name. Max 200 characters. |
style |
string | optional | Diagram style — "skeletal" (default) or "lewis". Skeletal shows bonds only with carbons implied. Lewis shows all atoms including hydrogens explicitly. |
Code Samples
# Skeletal diagram of caffeine
curl -X POST https://structura-kw47.onrender.com/chemistry \
-H "Content-Type: application/json" \
-d '{"formula": "caffeine", "style": "skeletal"}'
# Lewis diagram of water
curl -X POST https://structura-kw47.onrender.com/chemistry \
-H "Content-Type: application/json" \
-d '{"formula": "H2O", "style": "lewis"}'
import requests
import base64
response = requests.post(
"https://structura-kw47.onrender.com/chemistry",
json={"formula": "aspirin", "style": "skeletal"}
)
if response.status_code == 200:
data = response.json()
# Save the image
image_data = data["image"]
if image_data.startswith("data:image/png;base64,"):
png_bytes = base64.b64decode(image_data.split(",")[1])
with open("molecule.png", "wb") as f:
f.write(png_bytes)
print("Image saved to molecule.png")
print(f"SMILES: {data['smiles']}")
print(f"Model used: {data['model_used']}")
print(f"Formula: {data['metadata']['molecular_formula']}")
print(f"Weight: {data['metadata']['molecular_weight']}")
print(f"Description: {data['metadata']['description']}")
else:
print(f"Error {response.status_code}: {response.json()['detail']}")
const response = await fetch("https://structura-kw47.onrender.com/chemistry", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ formula: "glucose", style: "skeletal" }),
});
if (response.ok) {
const data = await response.json();
// Display the image
const img = document.createElement("img");
img.src = data.image;
document.body.appendChild(img);
console.log("SMILES:", data.smiles);
console.log("Model used:", data.model_used);
console.log("Metadata:", data.metadata);
} else {
const err = await response.json();
console.error("Error:", err.detail);
}
200 — Success
{
"image": "data:image/png;base64,iVBORw0KGgo...",
"smiles": "CN1C=NC2=C1C(=O)N(C(=O)N2C)C",
"model_used": "gemini-2.5-flash",
"metadata": {
"iupac_name": "1,3,7-trimethyl-2,3,6,7-tetrahydro-1H-purine-2,6-dione",
"common_name": "Caffeine",
"molecular_formula": "C8H10N4O2",
"molecular_weight": "194.19 g/mol",
"bond_count": 25,
"atom_count": 24,
"description": "Caffeine is a central nervous system stimulant found in coffee, tea, and many other beverages."
}
}
The image field is a base64-encoded PNG (or SVG fallback) — set it directly as an img src attribute to display it. The smiles field is a canonical SMILES string validated by RDKit.
Error Codes
| Code | Status | Meaning |
|---|---|---|
400 | Bad Request | Empty formula, formula exceeds 200 characters, or RDKit rejected the generated SMILES as invalid |
429 | Too Many Requests | Rate limit exceeded — 10 requests per 60 seconds per IP (shared with /digitise) |
500 | Internal Server Error | Gemini returned ambiguous or unrecognisable input, or all models failed |
Model Fallback Chain
Structura automatically tries multiple Gemini models if one is unavailable. You never need to specify a model — fallback is handled server-side.
How it works
Everything you need to get the best results from Structura — pipeline internals, supported formats, and tips from real usage.
Three-stage processing
Every image goes through three stages before you see a result. Understanding each stage helps you know why results vary and how to improve them.
The raw photo is cleaned up using OpenCV before anything else happens. This includes resizing large images, converting to grayscale, denoising with a Gaussian filter, and applying adaptive thresholding to make the diagram lines pop against the background. This stage is why Structura can handle badly-lit or slightly blurry photos.
The cleaned image is sent to Gemini Vision as a base64-encoded JPEG along with a structured prompt. The model identifies every shape (node), arrow (edge), label, and diagram type. It returns a strict JSON object with nodes and edges. If the primary model is unavailable, the system automatically falls back through the model chain.
The JSON is converted to valid Mermaid syntax. Each node shape maps to its Mermaid equivalent — rectangles become [ ], diamonds become { }, circles become ([ ]). Labels are sanitised to remove special characters that break Mermaid's parser. The output renders live in the browser using Mermaid.js, and is also available as copyable code or a downloadable .md file.
Supported formats
Structura works best with high-contrast hand-drawn diagrams. Here's what works well and what doesn't.
- Whiteboard photos (straight-on)
- Scanned hand-drawn flowcharts
- Napkin sketches with clear shapes
- Printed diagrams photographed
- Black marker on white background
- Simple flowcharts and process maps
- Mind maps with clear branches
- System architecture sketches
- Screenshots of digital diagrams
- Very dark or low-contrast photos
- Heavy glare on whiteboard surface
- Extremely messy or overlapping lines
- Diagrams with dense text labels
- Photos taken at steep angles
- Pencil sketches (too light)
- Complex UML with many subgraphs
Tips for best results
Small changes to how you draw and photograph your diagrams make a significant difference in extraction accuracy.
Using Mermaid diagrams
Mermaid is a widely supported diagram format. Once you've copied the code, you can use it in many places without any extra tools.
Chemistry — how it works
The Molecules feature follows a different pipeline from the diagram digitiser. Instead of image preprocessing, it starts with a text input and uses Gemini as a chemistry knowledge engine before handing off to RDKit for validated rendering.
Your input — whether a formula like C6H12O6, a common name like caffeine, or an IUPAC name — is sent to Gemini with a strict prompt asking for a canonical SMILES string plus molecular metadata. Gemini acts as a chemistry knowledge engine here, not a vision model.
The SMILES string from Gemini is passed to RDKit — an open-source cheminformatics library — which attempts to parse and validate it. If the SMILES is invalid or chemically impossible, RDKit rejects it and the request fails with a clear error rather than silently rendering a wrong structure. This validation step is critical because Gemini occasionally hallucinates SMILES for complex molecules.
RDKit computes 2D coordinates for the molecule and renders it as an SVG using its built-in drawing engine. For skeletal style, carbon atoms are implied at bond intersections. For Lewis style, all hydrogens are added explicitly before rendering, showing every atom in the molecule. The SVG is converted to PNG via cairosvg and returned as a base64 data URI.
What you can type
The chemistry endpoint accepts three types of input — all handled the same way internally.
- Molecular formulas — H2O, CH4, C6H12O6
- Common names — caffeine, aspirin, ethanol
- Drug names — ibuprofen, paracetamol
- Simple IUPAC names — ethanoic acid
- Neurotransmitters — dopamine, serotonin
- Amino acids — glycine, alanine
- Simple polymers — polyethylene unit
- Vitamins — vitamin C, vitamin D
- Very large molecules (500+ atoms)
- Complex natural products (taxol, vancomycin)
- Vague descriptions — "a painkiller"
- Mixtures — "seawater", "blood"
- Polymers as whole chains
- Ions without context — "Fe3+"
- Radicals and reaction intermediates
- Ambiguous abbreviations — "T" (thymine or threonine?)
Tips for best results
Using SMILES output
The SMILES string returned by Structura is validated by RDKit and can be used directly in a wide range of chemistry tools.
Known limitations
Structura works well on most diagrams but has known constraints worth understanding before you rely on it.
< > [ ] { } = +) are converted to plain English to keep the Mermaid output valid.Visualise any molecule
Type a chemical formula or name — get back a clean 2D structural diagram with bond information and molecular metadata.
Try: H2O, C6H12O6, caffeine, ethanol, aspirin
Your molecule will appear here
SMILES (Simplified Molecular Input Line Entry System) is a notation that describes molecular structure as a text string. Paste it into MolView for 3D view, PubChem for compound data, or Ketcher to edit interactively.