# jatin-mehra119/barcode-gen architecture

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

- Interactive diagram: https://gitdiagram.com/jatin-mehra119/barcode-gen
- Repository: https://github.com/jatin-mehra119/barcode-gen

## Overview

##### Project Type and Purpose
- This is a single-service, full-stack Streamlit web application whose sole purpose is to generate professional, print-ready Code128 barcodes in bulk for office/workplace operations.
- It has no separate database or external microservices; all logic runs in a single Python process, producing PDF output for printing.

##### File Structure
Top-level files:
- app.py – the Streamlit-based UI entrypoint
- utils.py – core business logic (barcode generation, labeling, PDF composition)
- requirements.txt – dependency listing (streamlit, python-barcode, Pillow, pandas)
- Dockerfile & .gitignore – containerization and VCS settings
- streamlit_barcode_app_backup.py – backup of main app, not part of main flow
- test_app.py, test_titles.py – automated tests for UI flows and title-label features
- test_app.py imports app.py UI functions; test_titles.py validates custom label logic

##### README for Additional Insights
- Streamlit for rapid office-friendly UI
- python-barcode + Pillow for Code128 image generation
- pandas for tabular input management
- Output: A4-sized PDF at 300 DPI, optimized for office printers

##### Main Components & Their Interactions
a. User Interface (Streamlit)
- Presents form for item numbers, quantities, titles
- Triggers “Generate” action
b. Business Logic (utils.py)
- Receives UI inputs
- Invokes python-barcode to generate barcode images
- Formats titles and aligns labels
- Uses Pillow to compose images into PDF pages
- Uses pandas if batch data operations are needed
c. Output Module
- Writes and returns a PDF buffer to Streamlit for download
- Uses Streamlit’s file‐download component
d. Testing Suite
- test_app.py validates that UI callbacks produce correct outputs
- test_titles.py ensures labeling logic correctness
e. Environment & Deployment
- Dockerfile encapsulates all dependencies
- requirements.txt pins library versions

##### Architectural Patterns and Design Principles
- Monolithic, layered architecture: UI layer → Business logic layer → Output layer
- Single responsibility modules: utils.py holds all generation logic, app.py handles only UI
- Test-driven design: tests verify each layer’s functionality
- Dependency injection pattern (passing parameters from UI to utils)

1. Streamlit UI Layer (app.py)
2. QR & Barcode Engine (python-barcode library)
3. Image Processing (Pillow)
4. Data Management (pandas)
5. PDF Assembly (utils.py subprocess)
6. Output Delivery (Streamlit download widget)
7. Test Harness (test_app.py & test_titles.py)
8. Docker Container (deployment boundary)
b. Relationships & Flow:
- UI → utils.py (input pass)
- utils.py → Barcode Engine & Pillow & pandas (library calls)
- Barcode Engine & Pillow → utils.py (image objects)
- utils.py → PDF Assembly → Streamlit Output
c. Architectural Patterns:
- Layered flow: top to bottom (UI → Logic → Libraries → Output)
- Single-process monolith with clear separation of concerns
d. Key Technologies:
- Python 3.7+ runtime
- Streamlit (UI)
- python-barcode (Code128 generation)
- Pillow (image composition)
- pandas (optional data handling)
- pytest (testing)
- Docker (deployment)

##### Diagramming Conventions
- Blue for UI (Streamlit)
- Green for Business Logic (utils.py)
- Orange for External Libraries (python-barcode, Pillow, pandas)
- Gray for Deployment (Docker)
- Purple for Testing

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Deployment Boundary
    subgraph "Docker Container" 
        direction TB
        %% UI Layer
        subgraph "UI Layer"
            Streamlit["Streamlit UI (app.py)"]:::ui
        end
        %% Business Logic Layer
        subgraph "Business Logic Layer"
            Logic["Business Logic (utils.py)"]:::logic
        end
        %% External Libraries
        subgraph "External Libraries"
            Barcode["python-barcode"]:::lib
            Pillow["Pillow"]:::lib
            Pandas["pandas"]:::lib
        end
        %% Output Module
        subgraph "Output Module"
            PDFAssembly["PDF Assembly"]:::logic
            Output["Streamlit Download Widget"]:::ui
        end
        %% Deployment Config
        subgraph "Deployment Config"
            DockerfileNode["Dockerfile"]:::deployment
            Req["requirements.txt"]:::deployment
            GitIgnore[".gitignore"]:::deployment
            Backup["streamlit_barcode_app_backup.py"]:::deployment
        end

        %% Internal Flows
        Streamlit -->|"input_data"| Logic
        Logic -->|"barcode_data"| Barcode
        Logic -->|"image_object"| Pillow
        Logic -->|"batch_data"| Pandas
        Barcode -->|"barcode_img"| Logic
        Pillow -->|"composed_img"| Logic
        Logic -->|"PDF buffer"| PDFAssembly
        PDFAssembly -->|"pdf_buffer"| Output
        Output -->|"file_download"| Streamlit
    end

    %% User Interaction
    User["User Browser"]:::external
    User -->|"interact"| Streamlit

    %% Test Harness
    subgraph "Tests"
        UItest["UI Test Harness (test_app.py)"]:::test
        LabelTest["Label Logic Test (test_titles.py)"]:::test
    end
    UItest -.->|"verify UI callbacks"| Streamlit
    LabelTest -.->|"validate logic"| Logic

    %% Click Events
    click Streamlit "https://github.com/jatin-mehra119/barcode-gen/blob/main/app.py"
    click Logic "https://github.com/jatin-mehra119/barcode-gen/blob/main/utils.py"
    click UItest "https://github.com/jatin-mehra119/barcode-gen/blob/main/test_app.py"
    click LabelTest "https://github.com/jatin-mehra119/barcode-gen/blob/main/test_titles.py"
    click DockerfileNode "https://github.com/jatin-mehra119/barcode-gen/tree/main/Dockerfile"
    click Req "https://github.com/jatin-mehra119/barcode-gen/blob/main/requirements.txt"
    click GitIgnore "https://github.com/jatin-mehra119/barcode-gen/blob/main/.gitignore"
    click Backup "https://github.com/jatin-mehra119/barcode-gen/blob/main/streamlit_barcode_app_backup.py"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#007ACC
    classDef logic fill:#DFFFD0,stroke:#2D8F00
    classDef lib fill:#FFE4B2,stroke:#D97706
    classDef external fill:#FFFFFF,stroke:#000000
    classDef test fill:#F0D0FF,stroke:#800080
    classDef deployment fill:#E0E0E0,stroke:#7C7C7C
```
