# rizkyyanuark/sudoku-puzzle-solver architecture

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

- Interactive diagram: https://gitdiagram.com/rizkyyanuark/sudoku-puzzle-solver
- Repository: https://github.com/rizkyyanuark/sudoku-puzzle-solver

## Overview

##### Main Components
- Frontend/UI:
- Represented by files like index.html, static/styles.css, and the JavaScript in js/scripts.js.
- This component is responsible for capturing user inputs (image upload/camera capture) and displaying results (original, processed image, and solved board).
- Backend/Server:
- Centered around the Flask application in app.py.
- Acts as the mediator between the frontend and the processing logic.
- Processing & Utility Modules:
- Found in the util directory (main.py, process.py, sudoku_solver.py) which house the image processing routines (using OpenCV), puzzle processing, and the solving algorithm.
- Machine Learning Model:
- Contained within the models folder (my_model.h5) and used for digit recognition from the processed images.
- Additional Documentation & Resources:
- The Classification directory with educational materials (a PDF and notebook) and the material folder containing images (sudoku.png) and demo content.
- Deployment & Configuration:
- Files such as Dockerfile, .dockerignore, cloudbuild.yaml, and the requirements.txt indicate how the system is containerized and built.

##### Relationships and Data Flow
- User → Frontend: Users interact with the index.html UI by uploading an image or using the camera.
- Frontend → Backend (app.py): The client (via HTML/JS) sends image data to the Flask server.
- Backend → Utility Functions:
- The server calls functions in util/process.py to perform image pre-processing (e.g., grid detection).
- It then uses util/sudoku_solver.py for the puzzle solving logic (backtracking algorithm).
- Backend → ML Model: During processing, the backend loads the CNN model from models/my_model.h5 to perform digit recognition.
- Backend → Frontend: After processing and solving, the server sends back the processed images and results for display.
- Deployment: Dockerfile, cloudbuild.yaml, and related configs indicate containerization and cloud build steps.

##### Architectural Patterns & Technologies
- MVC or Layered Architecture: The frontend (View) is separated from the backend logic (Controller/Model), while utility modules encapsulate domain-specific logic.
- Full-Stack Separation: Clearly separate client-side interactions from server-side processing.
- Integration of Image Processing and ML: Represent the flow where the image is pre-processed and then fed into the ML model followed by puzzle-solving – demonstrating the sequential pipeline design.

##### Detailed Step-by-Step Approach for the Engineer
a. Start by mapping out the client side:
- That this layer handles the user interface and interaction.
- App.py and indicate how it receives requests from the UI.
c. Break out the processing modules:
d. “Deployment & Configuration” area:
- Dockerfile, cloudbuild.yaml, and related config files to indicate containerization and continuous delivery setup.

## Diagram (Mermaid)

```mermaid
flowchart TD
    user("User"):::external

    subgraph "Frontend/UI"
        index_html("index.html"):::frontend
        styles("static/styles.css"):::frontend
        scripts("js/scripts.js"):::frontend
    end

    subgraph "Flask Backend"
        flask_backend("app.py"):::backend
    end

    subgraph "Processing & Utility Modules"
        img_process("Image Processing Module<br/>(util/process.py)"):::processing
        sudoku_solver("Sudoku Solver Module<br/>(util/sudoku_solver.py)"):::processing
        main_util("Utility/Main Module<br/>(util/main.py)"):::processing
        ml_model("Digit Recognition Model<br/>(models/my_model.h5)"):::ml
    end

    subgraph "Deployment & Configuration"
        dockerfile("Dockerfile"):::deployment
        dockerignore(".dockerignore"):::deployment
        cloudbuild("cloudbuild.yaml"):::deployment
        requirements("requirements.txt"):::deployment
    end

    subgraph "Documentation & Educational Resources"
        classification("Classification"):::documentation
    end

    %% Data Flow Arrows
    user -->|"ImageUpload/CameraInput"| index_html
    index_html -->|"SendImageData"| flask_backend
    flask_backend -->|"PreProcessImage"| img_process
    img_process -->|"DigitRecognition"| ml_model
    flask_backend -->|"SolvePuzzle"| sudoku_solver
    flask_backend -->|"Orchestrate"| main_util
    flask_backend -->|"ReturnResults"| index_html

    %% Deployment Connections
    dockerfile ---|"Containerized"| flask_backend
    cloudbuild ---|"BuildPipeline"| flask_backend

    %% Click Events
    click index_html "https://github.com/rizkyyanuark/sudoku-puzzle-solver/blob/dev/index.html"
    click styles "https://github.com/rizkyyanuark/sudoku-puzzle-solver/blob/dev/static/styles.css"
    click scripts "https://github.com/rizkyyanuark/sudoku-puzzle-solver/blob/dev/js/scripts.js"
    click flask_backend "https://github.com/rizkyyanuark/sudoku-puzzle-solver/blob/dev/app.py"
    click img_process "https://github.com/rizkyyanuark/sudoku-puzzle-solver/blob/dev/util/process.py"
    click sudoku_solver "https://github.com/rizkyyanuark/sudoku-puzzle-solver/blob/dev/util/sudoku_solver.py"
    click main_util "https://github.com/rizkyyanuark/sudoku-puzzle-solver/blob/dev/util/main.py"
    click ml_model "https://github.com/rizkyyanuark/sudoku-puzzle-solver/blob/dev/models/my_model.h5"
    click classification "https://github.com/rizkyyanuark/sudoku-puzzle-solver/tree/dev/Classification"
    click dockerfile "https://github.com/rizkyyanuark/sudoku-puzzle-solver/tree/dev/Dockerfile"
    click dockerignore "https://github.com/rizkyyanuark/sudoku-puzzle-solver/blob/dev/.dockerignore"
    click cloudbuild "https://github.com/rizkyyanuark/sudoku-puzzle-solver/blob/dev/cloudbuild.yaml"
    click requirements "https://github.com/rizkyyanuark/sudoku-puzzle-solver/blob/dev/requirements.txt"

    %% Styles
    classDef external fill:#ffebcd,stroke:#333,stroke-width:2px;
    classDef frontend fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef backend fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef processing fill:#f4a460,stroke:#333,stroke-width:2px;
    classDef ml fill:#ffb6c1,stroke:#333,stroke-width:2px;
    classDef deployment fill:#d3d3d3,stroke:#333,stroke-width:2px;
    classDef documentation fill:#dda0dd,stroke:#333,stroke-width:2px;
```
