# suraj-5556/cat_vs_dog_classifer architecture

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

- Interactive diagram: https://gitdiagram.com/suraj-5556/cat_vs_dog_classifer
- Repository: https://github.com/suraj-5556/cat_vs_dog_classifer

## Overview

##### Project type and purpose
- This is a lightweight ML‐powered web application built with Streamlit. It serves a pre-trained CNN model (cat_dog_model.keras) to classify user-uploaded images as cats or dogs in real time. The Jupyter notebook (cnn_source.ipynb) and dataset link support offline model training.

##### File structure
- .devcontainer/ : Defines a VS Code dev container (container.json) for consistent dev environment.
- README.md : Describes the app’s purpose and tech stack.
- requirements.txt : Lists Python dependencies (streamlit, tensorflow/keras, pillow, etc.).
- cat_vs_dog.py : Entry point—Streamlit app that loads the model, handles uploads, runs inference, and displays results.
- cat_dog_model.keras : Serialized CNN model used at runtime.
- cnn_source.ipynb : Notebook used for data exploration, model architecture design, training, and saving the model.
- dataset link : External pointer (e.g., Kaggle) to the raw image dataset.

##### README for additional insights
- Confirms that Streamlit is used for the front end (UI) and that inference is real-time.
- Implies TensorFlow/Keras as the model framework.

##### Main components and interactions
a. User Interface (Streamlit App)
- Component: cat_vs_dog.py running inside a Streamlit server.
- Responsibility: accepts image uploads, displays confidence scores, and shows classification.
b. Model Inference Service
- Component: TensorFlow/Keras runtime inside the same process or a separate microservice.
- Loads cat_dog_model.keras, applies image preprocessing (resize, normalize), and performs predict().
c. Model Storage
- Component: Persistent storage (local file system or blob storage) holding cat_dog_model.keras.
d. Training Pipeline (offline)
- Component: Jupyter notebook (cnn_source.ipynb) plus dataset fetched via “dataset link.”
- Workflow: Load images → preprocess → define and train CNN → serialize model to cat_dog_model.keras.
e. Development Environment
- Component: .devcontainer config ensuring consistent dependencies in Docker/VS Code.

##### Architectural patterns and design principles
- Separation of concerns: distinct “training” vs. “inference” workflows.
- Single-page application: Streamlit handles both front end and back end logic.
- Model versioning: store the .keras file separately so it can be swapped or updated without changing app code.
- Containerization/dev container: ensures reproducible environment for contributors.

##### Key diagramming recommendations
- Both the runtime (inference) and development (training, environment) contexts for completeness.
- Keep it simple: focus on the four or five core blocks (User, Streamlit App, Inference, Model Storage, Training Notebook) and their interactions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Online Inference
    User["User Browser"]:::user
    subgraph "Online Inference"
        Streamlit["Streamlit Server (cat_vs_dog.py)"]:::app
        Inference["TF/Keras Inference"]:::inference
        ModelStorage["cat_dog_model.keras"]:::storage
    end

    %% Offline Training
    subgraph "Offline Training Pipeline"
        Dataset["Raw Image Dataset (external)"]:::dataset
        Notebook["cnn_source.ipynb (Training Notebook)"]:::training
    end

    %% Development Environment
    subgraph "Development Environment"
        DevContainer[".devcontainer/devcontainer.json"]:::dev
        Requirements["requirements.txt"]:::config
        README["README.md"]:::docs
    end

    %% Data Flows - Inference
    User -->|"upload image"| Streamlit
    Streamlit -->|"predict(image)"| Inference
    Inference -->|"load model at startup"| ModelStorage
    Inference -->|"return prediction + confidence"| Streamlit
    Streamlit -->|"display result"| User

    %% Data Flows - Training
    Dataset -->|"load images"| Notebook
    Notebook -->|"serialize model"| ModelStorage

    %% Dev Environment Links
    DevContainer --> Requirements
    DevContainer --> README

    %% Click Events
    click Streamlit "https://github.com/suraj-5556/cat_vs_dog_classifer/blob/main/cat_vs_dog.py"
    click ModelStorage "https://github.com/suraj-5556/cat_vs_dog_classifer/blob/main/cat_dog_model.keras"
    click Notebook "https://github.com/suraj-5556/cat_vs_dog_classifer/blob/main/cnn_source.ipynb"
    click Dataset "https://github.com/suraj-5556/cat_vs_dog_classifer/tree/main/dataset link"
    click DevContainer "https://github.com/suraj-5556/cat_vs_dog_classifer/blob/main/.devcontainer/devcontainer.json"
    click Requirements "https://github.com/suraj-5556/cat_vs_dog_classifer/blob/main/requirements.txt"
    click README "https://github.com/suraj-5556/cat_vs_dog_classifer/blob/main/README.md"

    %% Styles
    classDef user fill:#AEDFFF,stroke:#0366d6,color:#000
    classDef app fill:#D0E8FF,stroke:#0366d6,color:#000
    classDef inference fill:#C6F6D5,stroke:#00A000,color:#000
    classDef storage fill:#E2E8F0,stroke:#4A5568,color:#000
    classDef training fill:#FEF3C7,stroke:#D69E2E,color:#000
    classDef dataset fill:#FEF3C7,stroke:#D69E2E,color:#000
    classDef dev fill:#B2F5EA,stroke:#319795,color:#000
    classDef config fill:#E9D8FD,stroke:#6B46C1,color:#000
    classDef docs fill:#FFF5F7,stroke:#D53F8C,color:#000
```
