# lunar-arun/cat-vs-dog-classifier-resnet18-with-streamlit architecture

> Architecture diagram of the GitHub repository lunar-arun/cat-vs-dog-classifier-resnet18-with-streamlit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lunar-arun/cat-vs-dog-classifier-resnet18-with-streamlit
- Repository: https://github.com/lunar-arun/cat-vs-dog-classifier-resnet18-with-streamlit

## Overview

##### Project Type and Purpose
- This is a monolithic, single‐page Streamlit application for image classification (cats vs. dogs) using a pre‐trained ResNet18 model.
- The codebase bundles the UI, file‐upload logic, model‐loading/inference logic, and assets (model weights, test images) into one process.

##### File Structure Analysis
Top-level:
- README.md – app description & run instructions
- app.py – entrypoint; Streamlit app definition
- requirements.txt – Python dependencies (streamlit, torch, etc.)
packages/ directory (modular organization):
- model.py – code to load the ResNet18 architecture + weights (`dog_cat_classifier.pth`) and perform inference
- upload.py – file‐upload handlers and preprocessing logic
- page.py – layout and page‐navigation functions for Streamlit
- default.py – default parameter values and UI constants
- ResNet18_Model/ – stored model weights
- test-images/ – sample images for local testing

##### Key Insights from README
- The app uses Streamlit to serve a web UI that allows users to upload images.
- On upload, the ResNet18 model (loaded from a `.pth` file) classifies the image and displays the result.
- No separate backend server or external database—everything runs in‐process.

##### Main Components
a. User Interface Layer (Streamlit Frontend)
– Components: app.py + packages/page.py + packages/default.py
– Responsibilities: render upload widget, display classification results, handle user interactions.
b. File Upload & Preprocessing
– Component: packages/upload.py
– Responsibilities: accept the image, validate/resize/convert to tensor.
c. Model Inference Engine
– Component: packages/model.py
– Responsibilities: load ResNet18 architecture, load weights (`.pth`), run forward pass, output probabilities or labels.
d. Local Storage
– Model weights file (dog_cat_classifier.pth)
– Static test images (packages/test-images/)
e. Runtime Environment & Dependencies
– Python interpreter, virtual environment
– Libraries: Streamlit, PyTorch, torchvision, PIL, etc.

##### Interactions and Data Flow
1. User uploads an image via Streamlit UI →
2. Upload handler (packages/upload.py) preprocesses and sanitizes the image →
3. Preprocessed tensor passed to Model Inference Engine (packages/model.py) →
4. Model outputs a prediction (cat vs. dog) →
5. UI layer receives result and displays it to the user.

##### Architectural Patterns & Design Principles
- Modularization: separate modules for UI (page.py), upload logic (upload.py), model logic (model.py), and constants (default.py).
- Single‐process monolith: no microservices or external APIs.
- Dependency injection: configuration constants in default.py can be easily modified/tested.

##### Final Recommendations
a. High‐Level View: UI, Inference Engine, Storage
b. Detailed View: modules within the app (`page.py`, `upload.py`, `model.py`, `default.py`)
- Component names match file names for easy cross‐reference.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External User
    User["User"]:::external

    %% UI Layer
    subgraph "User Interface Layer"
        App["app.py"]:::ui
        Page["packages/page.py"]:::ui
        Default["packages/default.py"]:::ui
    end

    %% Upload & Preprocessing
    subgraph "File Upload & Preprocessing"
        Upload["packages/upload.py"]:::preprocess
    end

    %% Model Inference
    subgraph "Model Inference Engine"
        Model["packages/model.py"]:::inference
    end

    %% Local Storage
    subgraph "Local Storage"
        Weights["dog_cat_classifier.pth"]:::storage
        TestImages["packages/test-images/"]:::storage
    end

    %% Runtime & Dependencies
    subgraph "Runtime Environment & Dependencies"
        Req["requirements.txt"]:::deps
        Readme["README.md"]:::deps
    end

    %% Data Flows
    User -->|"opens UI"| App
    App -->|"render layout"| Page
    App -->|"load constants"| Default
    App -->|"upload file"| Upload
    Upload -->|"tensor"| Model
    Model -->|"prediction"| App
    Model -->|"load weights"| Weights
    TestImages -->|"sample images"| App

    %% Click Events
    click App "https://github.com/lunar-arun/cat-vs-dog-classifier-resnet18-with-streamlit/blob/main/app.py"
    click Page "https://github.com/lunar-arun/cat-vs-dog-classifier-resnet18-with-streamlit/blob/main/packages/page.py"
    click Default "https://github.com/lunar-arun/cat-vs-dog-classifier-resnet18-with-streamlit/blob/main/packages/default.py"
    click Upload "https://github.com/lunar-arun/cat-vs-dog-classifier-resnet18-with-streamlit/blob/main/packages/upload.py"
    click Model "https://github.com/lunar-arun/cat-vs-dog-classifier-resnet18-with-streamlit/blob/main/packages/model.py"
    click Weights "https://github.com/lunar-arun/cat-vs-dog-classifier-resnet18-with-streamlit/blob/main/packages/ResNet18_Model/dog_cat_classifier.pth"
    click TestImages "https://github.com/lunar-arun/cat-vs-dog-classifier-resnet18-with-streamlit/tree/main/packages/test-images/"
    click Req "https://github.com/lunar-arun/cat-vs-dog-classifier-resnet18-with-streamlit/blob/main/requirements.txt"
    click Readme "https://github.com/lunar-arun/cat-vs-dog-classifier-resnet18-with-streamlit/blob/main/README.md"

    %% Styles
    classDef ui fill:#cfe2f3,stroke:#0366d6;
    classDef preprocess fill:#d9ead3,stroke:#6aa84f;
    classDef inference fill:#d9ead3,stroke:#6aa84f;
    classDef storage fill:#ebebeb,stroke:#666666;
    classDef deps fill:#fef2c0,stroke:#d69f00;
    classDef external fill:#ffffff,stroke:#000000,stroke-dasharray: 5 5;
```
