# xuanhuy10/dacn3 architecture

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

- Interactive diagram: https://gitdiagram.com/xuanhuy10/dacn3
- Repository: https://github.com/xuanhuy10/dacn3

## Overview

##### Project Type & Purpose
- This is a compact, Python-based computer‐vision classification tool for Vietnamese banknotes. It uses a small CNN model converted to ONNX and OpenCV DNN for inference. The codebase provides:
- A local CLI/classification entry point (main.py)
- An inference server (ocr_server.py)
- A Raspberry Pi client (raspberrypi_client.py)
- Utilities for preprocessing & model loading (utils.py)
- A test harness (ocr_test.py)

##### High-Level Architecture & Components
a. Model Storage
– classifier.onnx: pre-trained ONNX model file
b. Inference Engine & Library Layer
– utils.py: loads the ONNX model via OpenCV DNN, applies image preprocessing, postprocesses predictions
c. Server Layer
– ocr_server.py: exposes an HTTP (or lightweight RPC) endpoint; accepts image payloads, invokes utils → returns classification results
d. Client Layer
– raspberrypi_client.py: captures images on the Pi (via camera or file), sends requests to the OCR server, displays or logs results
e. Local CLI
– main.py: stand-alone script to classify images locally without network, invoking the same utils module
f. Test Layer
– ocr_test.py: validates end-to-end functionality of server + client + utils

##### Relationships & Data Flow
1. (Optional) Training Notebook → classifier.onnx (outside production scope)
2. Client (Raspberry Pi) or CLI → sends image data → OCR Server
3. OCR Server → calls utils.load_model() → utils.preprocess(image) → utils.infer() → utils.postprocess()
4. OCR Server → returns label/confidence → Client or CLI displays result

##### Architectural Patterns & Principles
- Modular Separation: inference logic (utils) is decoupled from transport (server vs CLI)
- Service-Oriented: OCR server acts as a microservice
- Single Responsibility: each script has a clear, narrow focus
- Model Abstraction: using ONNX for portability across platforms (desktop, Raspberry Pi)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Production"
        Camera["Camera"]:::compute
        Client["raspberrypi_client.py"]:::compute
        Server["ocr_server.py"]:::compute
        Utils["utils.py"]:::compute
        CLI["main.py"]:::compute
        C[(classifier.onnx)]:::artifact

        Camera --> Client
        Client -->|"HTTP POST /infer"| Server
        Server -->|"load_model() / preprocess()"| Utils
        Utils -->|"infer()"| C
        C --> Utils
        Utils -->|"postprocess()"| Server
        Server -->|"HTTP RESPONSE"| Client

        CLI -->|"Direct function call"| Utils
        Utils -->|"load_model() / preprocess()"| Utils
        Utils -->|"infer()"| C
        C --> Utils
        Utils -->|"postprocess()"| CLI
    end

    subgraph "Development" 
        Test["ocr_test.py"]:::dev
        Test --> Server
        Test --> Client
        Test --> Utils
    end

    click C "https://github.com/xuanhuy10/dacn3/blob/main/classifier.onnx"
    click Utils "https://github.com/xuanhuy10/dacn3/blob/main/utils.py"
    click Server "https://github.com/xuanhuy10/dacn3/blob/main/ocr_server.py"
    click Client "https://github.com/xuanhuy10/dacn3/blob/main/raspberrypi_client.py"
    click CLI "https://github.com/xuanhuy10/dacn3/blob/main/main.py"
    click Test "https://github.com/xuanhuy10/dacn3/blob/main/ocr_test.py"

    classDef compute fill:#c2f0c2,stroke:#333,stroke-width:1px
    classDef artifact fill:#add8e6,stroke:#333,stroke-width:1px
    classDef dev fill:#f0f0f0,stroke-dasharray:5 5,stroke:#333
```
