# ricartesamuel/cassaco-scan architecture

> Architecture diagram of the GitHub repository ricartesamuel/cassaco-scan, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ricartesamuel/cassaco-scan
- Repository: https://github.com/ricartesamuel/cassaco-scan

## Overview

##### Project type and purpose
- Cassaco Scan is a single-page web application (SPA) that runs entirely in the browser.
- It captures or uploads an image of a menu, performs OCR on that image with Tesseract.js, and then sends the extracted text to the OpenAI GPT-4 API to receive a structured JSON response.
- There is no custom backend server; Node.js is used only for local development, build and CSS processing.

##### File structure
- Root
- index.html: entry point / UI skeleton
- package.json, postcss.config.js, tailwind.config.js: build and CSS pipeline configs
- assets/: static images (logo)
- src/
– app.js: main application logic (UI event handling, OCR invocation, API calls)
– util.js: helper functions (e.g., image preprocessing, fetch wrappers)
– styles.css: Tailwind-based styling
- Dist (not shown above but mentioned in README) contains the compiled CSS for production.

##### Key architectural insights from README
- Front-end technologies: HTML, CSS (Tailwind + PostCSS), vanilla JS
- OCR engine: Tesseract.js running in the client
- External AI service: OpenAI GPT-4 API via HTTPS
- Local dev: Node.js + npm for “npm run dev” and “npm run build”

a. Main components
- Browser / Client
- UI Layer (HTML + CSS + JS)
- OCR Engine (Tesseract.js library)
- OpenAI GPT-4 API (external service)
- Build Pipeline (Node.js, PostCSS, Tailwind CSS, dev server)
b. Relationships & interactions
1. User opens index.html in browser
2. UI layer loads app.js, styles.css
3. User clicks “Take Photo” or “Upload Image” → browser camera/File API
4. app.js passes image blob to Tesseract.js → OCR text
5. app.js formats text and POSTs to OpenAI API endpoint → receives JSON metadata
6. UI displays JSON; user may copy or reset
c. Architectural patterns / design principles
– Client-centric processing: all business logic and OCR run in the browser
– External API integration: thin client uses fetch() for AI calls
– Build pipeline separated from runtime: dev/build with Node.js, production ship static files
d. Key technologies
– Tailwind CSS & PostCSS (style preprocessing)
– Tesseract.js (in-browser OCR)
– OpenAI REST API (GPT-4)
– Vanilla JS modules (app.js, util.js)

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser["Browser / Client"]:::client

    subgraph "UI Layer"
        HTML["index.html"]:::client
        AppJS["app.js\n(Business Logic)"]:::client
        StylesCSS["styles.css"]:::client
    end

    subgraph "Utilities"
        Util["util.js\n(Helpers)"]:::client
    end

    subgraph "OCR Engine"
        Tesseract["Tesseract.js"]:::client
    end

    OpenAI["OpenAI GPT-4 API"]:::external

    subgraph "Build Pipeline"
        Package["package.json"]:::tooling
        PostCSS["postcss.config.js"]:::tooling
        TailwindCFG["tailwind.config.js"]:::tooling
    end

    Assets["Static Assets\n(assets/)"]:::client

    Browser --> HTML
    HTML --> AppJS
    HTML --> StylesCSS
    HTML --> Assets
    AppJS --> Tesseract
    Tesseract --> AppJS
    AppJS --> Util
    Util --> OpenAI
    OpenAI --> AppJS
    Package --> StylesCSS
    PostCSS --> StylesCSS
    TailwindCFG --> StylesCSS

    click Browser "https://github.com/ricartesamuel/cassaco-scan/blob/main/index.html"
    click HTML "https://github.com/ricartesamuel/cassaco-scan/blob/main/index.html"
    click AppJS "https://github.com/ricartesamuel/cassaco-scan/blob/main/src/app.js"
    click StylesCSS "https://github.com/ricartesamuel/cassaco-scan/blob/main/src/styles.css"
    click Util "https://github.com/ricartesamuel/cassaco-scan/blob/main/src/util.js"
    click OpenAI "https://github.com/ricartesamuel/cassaco-scan/blob/main/src/app.js"
    click Package "https://github.com/ricartesamuel/cassaco-scan/blob/main/package.json"
    click PostCSS "https://github.com/ricartesamuel/cassaco-scan/blob/main/postcss.config.js"
    click TailwindCFG "https://github.com/ricartesamuel/cassaco-scan/blob/main/tailwind.config.js"
    click Assets "https://github.com/ricartesamuel/cassaco-scan/tree/main/assets/"

    classDef client fill:#cce5ff,stroke:#004085,color:#004085;
    classDef external fill:#d4edda,stroke:#155724,color:#155724;
    classDef tooling fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
```
