# albertlnz/plt2img architecture

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

- Interactive diagram: https://gitdiagram.com/albertlnz/plt2img
- Repository: https://github.com/albertlnz/plt2img

## Overview

##### Project Type and Purpose
- This is a full-stack web application that lets users paste or upload Matplotlib (and related Python library) code and receive a rendered image in return.
- The frontend is built with Astro (JavaScript/TypeScript) and serves a single-page interface.
- The backend is a Python microservice (Flask-style server) packaged in a Docker container.

##### File Structure Analysis
- Top level:
- astro.config.mjs, package.json, tsconfig.json → Astro configuration and frontend build
- public/ → Static assets served by the frontend
- src/
– src/pages, src/components, src/layouts → Astro pages, UI components, and layout
– src/styles → CSS modules for each component
– src/backend/ → Python server code, Dockerfile, requirements.txt
- No persistent database—images are generated on-the-fly.

##### Key README Insights
- Frontend runs on port 4321 (Astro dev server)
- Backend runs on port 5000 inside a Docker container
- The frontend fetch URL must be configured in src/components/App.astro
- Supported libs: Matplotlib, NumPy, Pandas, Seaborn, SciPy, Sympy

##### Components
a. Main Components
- User’s Browser (UI)
- Astro Frontend (dev/build server)
- Pages (index.astro)
- Components (PromptArea, ResultArea, Header, Footer, Ad components)
- CSS and SVG assets
- HTTP/API Layer (fetch call in App.astro)
- Python Backend Service (server.py in Docker)
- Request handler
- Code execution pipeline (Matplotlib + supporting libs)
- Response generator (PNG/SVG image)
- Docker Container (encapsulates backend)
- Static Hosting/CDN for frontend assets (optional production detail)

b. Relationships and Interactions
1) Browser loads Astro-generated HTML/CSS/JS.
2) User pastes code into PromptArea → click “Generate”.
3) Frontend sends HTTP POST to backend endpoint (e.g., /generate).
4) Python server receives code → invokes Matplotlib, NumPy, etc.
5) Generated image returned as binary or base64 payload.
6) Frontend ResultArea displays the returned image.

c. Architectural Patterns & Principles
- Separation of concerns: UI vs. code-execution service.
- Single API endpoint for image generation.
- Containerization: backend runs in an isolated Docker environment.
- Static vs. dynamic content separation: Astro builds static assets, Python handles dynamic code.

d. Key Technologies
- Astro (frontend framework)
- TypeScript/JavaScript, CSS modules, SVG assets
- Python 3.x, Matplotlib, NumPy, Pandas, Seaborn, SciPy, Sympy
- Docker (for backend isolation)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (Astro)" 
        direction TB
        FC[Astro Config]:::frontend
        FC --- PG
        PG[Package & TS Config]:::frontend

        subgraph "Pages & Layouts"
            direction TB
            P1[index.astro]:::frontend
            P2[index.css]:::frontend
            L1[Layout.astro]:::frontend
        end

        subgraph "Components"
            direction TB
            C1[App Component]:::frontend
            C2[Header Component]:::frontend
            C3[Footer Component]:::frontend
            C4[PromptArea Component]:::frontend
            C5[ResultArea Component]:::frontend
            C6[AdVertical Component]:::frontend
            C7[AdMiddle Component]:::frontend
        end

        subgraph "Assets & Styles"
            direction TB
            A1[public/]:::frontend
            A2[SVG Coffee]:::frontend
            A3[SVG GitHub]:::frontend
            S1[app.css]:::frontend
            S2[header.css]:::frontend
            S3[footer.css]:::frontend
            S4[promptArea.css]:::frontend
            S5[resultArea.css]:::frontend
            S6[adVertical.css]:::frontend
        end

        subgraph "Env & Docs"
            direction TB
            E1[.env.example]:::infra
            D1[README.md]:::infra
            D2[demo_video_sd.mp4]:::infra
        end

    end

    %% Backend Layer
    subgraph "Backend (Python/Docker)" 
        direction TB
        DC[Dockerfile]:::backend
        RQ[requirements.txt]:::backend
        SP[server.py]:::backend

        subgraph "Execution Engine"
            direction TB
            LIB1[Matplotlib]:::libs
            LIB2[NumPy]:::libs
            LIB3[Pandas]:::libs
            LIB4[Seaborn]:::libs
            LIB5[SciPy]:::libs
            LIB6[Sympy]:::libs
        end

        DC -->|build| SP
        SP -->|imports| LIB1
        SP --> LIB2
        SP --> LIB3
        SP --> LIB4
        SP --> LIB5
        SP --> LIB6
    end

    %% User Interaction Flow
    Browser["User's Browser"]:::infra
    DevServer["Astro Dev Server (port 4321)"]:::infra
    Browser -->|loads frontend| DevServer
    DevServer -->|serves Pages| P1
    P1 --> C1
    C4 -->|user input| C1
    C1 -->|POST /generate| SP
    SP -->|returns image| C5
    C5 -->|display image| Browser

    %% Classes
    classDef frontend fill:#D0E8FF,stroke:#333,stroke-width:1px;
    classDef backend fill:#D0FFD0,stroke:#333,stroke-width:1px;
    classDef libs fill:#F0F0F0,stroke:#666,stroke-dasharray: 2 2;
    classDef infra fill:#E8E8E8,stroke:#333,stroke-width:1px;

    %% Click Events
    click FC "https://github.com/albertlnz/plt2img/blob/master/astro.config.mjs"
    click PG "https://github.com/albertlnz/plt2img/blob/master/package.json"
    click PG "https://github.com/albertlnz/plt2img/blob/master/tsconfig.json"
    click A1 "https://github.com/albertlnz/plt2img/tree/master/public/"
    click A2 "https://github.com/albertlnz/plt2img/blob/master/src/assets/svgs/Coffee.astro"
    click A3 "https://github.com/albertlnz/plt2img/blob/master/src/assets/svgs/GitHub.astro"
    click P1 "https://github.com/albertlnz/plt2img/blob/master/src/pages/index.astro"
    click P2 "https://github.com/albertlnz/plt2img/blob/master/src/pages/index.css"
    click L1 "https://github.com/albertlnz/plt2img/blob/master/src/layouts/Layout.astro"
    click C1 "https://github.com/albertlnz/plt2img/blob/master/src/components/App.astro"
    click C2 "https://github.com/albertlnz/plt2img/blob/master/src/components/Header.astro"
    click C3 "https://github.com/albertlnz/plt2img/blob/master/src/components/Footer.astro"
    click C4 "https://github.com/albertlnz/plt2img/blob/master/src/components/PromptArea.astro"
    click C5 "https://github.com/albertlnz/plt2img/blob/master/src/components/ResultArea.astro"
    click C6 "https://github.com/albertlnz/plt2img/blob/master/src/components/AdVertical.astro"
    click C7 "https://github.com/albertlnz/plt2img/blob/master/src/components/AdMiddle.astro"
    click S1 "https://github.com/albertlnz/plt2img/blob/master/src/styles/app.css"
    click S2 "https://github.com/albertlnz/plt2img/blob/master/src/styles/header.css"
    click S3 "https://github.com/albertlnz/plt2img/blob/master/src/styles/footer.css"
    click S4 "https://github.com/albertlnz/plt2img/blob/master/src/styles/promptArea.css"
    click S5 "https://github.com/albertlnz/plt2img/blob/master/src/styles/resultArea.css"
    click S6 "https://github.com/albertlnz/plt2img/blob/master/src/styles/adVertical.css"
    click E1 "https://github.com/albertlnz/plt2img/blob/master/.env.example"
    click D1 "https://github.com/albertlnz/plt2img/blob/master/README.md"
    click D2 "https://github.com/albertlnz/plt2img/blob/master/demo_video_sd.mp4"
    click DC "https://github.com/albertlnz/plt2img/tree/master/src/backend/Dockerfile"
    click RQ "https://github.com/albertlnz/plt2img/blob/master/src/backend/requirements.txt"
    click SP "https://github.com/albertlnz/plt2img/blob/master/src/backend/server.py"
```
