# nithin1729s/kannada-cnn architecture

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

- Interactive diagram: https://gitdiagram.com/nithin1729s/kannada-cnn
- Repository: https://github.com/nithin1729s/kannada-cnn

## Overview

##### Main components
- Model Training & Evaluation Component:
- CNN Model: This is built using TensorFlow/Keras.
- Jupyter Notebook: Located in the notebooks directory, which was used for training and evaluation of the model (e.g., Kannada_CNN.ipynb).
- The saved model file (backend/model/full_model.h5): Represents the trained CNN that’s loaded later for inference.

- Backend Component:
- FastAPI Service: Located within the backend/api directory (main.py, __init__.py). This API serves endpoints for predictions by loading and deploying the CNN model.
- Dependencies for the backend are listed in backend/requirements.txt.

- Frontend Component:
- Next.js Application: Found under the frontend directory including the pages (page.tsx), layout, and drawing components (CanvasDrawing.tsx).
- UI Components: Various React or TypeScript components (e.g., button.tsx) to construct the drawing interface.
- Utility libraries: Under frontend/lib.
- Configuration files for Tailwind CSS, ESLint, and Next.js indicate modern web design and development practices.

##### Inter-component relationships and interactions
- Data Flow:
- User Interaction: On the frontend, a user draws a Kannada letter on a canvas.
- API Request: The drawn image is transmitted from the Next.js frontend to the FastAPI backend.
- Model Inference: The backend then loads the pre-trained CNN (full_model.h5) and performs prediction.
- Response Delivery: The prediction result is sent back to the frontend where it is displayed.

- Training Pipeline:
- The CNN model training is performed offline (via Jupyter Notebook) and the resulting model file saved is later used by the API backend for inference.

##### Architectural and design principles
- Separation of Concerns: The project clearly separates model training (offline, notebook-based) from model inference (handled by FastAPI), and further decouples user-interface concerns (Next.js) from the service layer.
- Modern Web Tech Stack: Use of Next.js and Tailwind indicates a component-based approach and responsive UI practices.
- Deployment Considerations: Use of configuration and dependency files (package.json, requirements.txt) suggests that building a pipeline for CI/CD and deployment is straightforward.

##### Relevant technologies and frameworks
- Backend: Python, FastAPI, Uvicorn server.
- Model Training: TensorFlow, Keras (with data augmentation, CNN layers, and callbacks).
- Frontend: Next.js (React framework), TypeScript, Tailwind CSS.
- Additional Tools: Jupyter Notebook for training experiments, configuration files (ESLint, PostCSS) for ensuring code quality and styling.

##### Practical steps for the principal software engineer
- Document data flows: indicate that the trained model (full_model.h5) is loaded by the FastAPI backend which processes image inference requests coming from the Next.js frontend.
- You include all files or directories that represent configuration (such as the various JSON and config files in the frontend) as supporting components for building, linting, or styling.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User
    user["User"]:::external

    %% Model Training Phase
    subgraph "Model Training Phase"
        direction TB
        nb["Jupyter Notebook (Training)"]:::training
        cnn["CNN Model (full_model.h5)"]:::training
    end

    %% Backend API
    subgraph "Backend API"
        direction TB
        api_init["FastAPI Init (__init__.py)"]:::backend
        api_main["FastAPI Endpoint (main.py)"]:::backend
        dep["Dependencies (requirements.txt)"]:::backend
        api_init --> api_main
    end

    %% Frontend Application
    subgraph "Frontend Application"
        direction TB
        ui["Next.js Application (layout.tsx, page.tsx)"]:::frontend
        cd["CanvasDrawing Component"]:::frontend
        btn["Button Component"]:::frontend
        utils["Utility Libraries (utils.ts)"]:::frontend
        config["Configurations (next.config.js, tailwind.config.ts, .eslintrc.json, postcss.config.js, package.json, package-lock.json)"]:::frontend
        ui --> cd
        ui --> btn
        ui --> utils
        ui --> config
    end

    %% Data Flow Connections
    user -->|"draws"| cd
    cd -->|"APIRequest"| api_main
    api_main -->|"PredictionResponse"| cd
    nb -->|"trainedModel"| cnn
    cnn -->|"loadedForInference"| api_main

    %% Click Events
    click cnn "https://github.com/nithin1729s/kannada-cnn/blob/master/backend/model/full_model.h5"
    click nb "https://github.com/nithin1729s/kannada-cnn/blob/master/notebooks/Kannada_CNN.ipynb"
    click api_main "https://github.com/nithin1729s/kannada-cnn/blob/master/backend/api/main.py"
    click api_init "https://github.com/nithin1729s/kannada-cnn/blob/master/backend/api/__init__.py"
    click dep "https://github.com/nithin1729s/kannada-cnn/blob/master/backend/requirements.txt"
    click ui "https://github.com/nithin1729s/kannada-cnn/blob/master/frontend/app/page.tsx"
    click cd "https://github.com/nithin1729s/kannada-cnn/blob/master/frontend/components/CanvasDrawing.tsx"
    click btn "https://github.com/nithin1729s/kannada-cnn/blob/master/frontend/components/ui/button.tsx"
    click utils "https://github.com/nithin1729s/kannada-cnn/blob/master/frontend/lib/utils.ts"
    click config "https://github.com/nithin1729s/kannada-cnn/blob/master/frontend/next.config.js"

    %% Styles
    classDef training fill:#ffcccc,stroke:#990000,stroke-width:2px;
    classDef backend fill:#ccffcc,stroke:#009900,stroke-width:2px;
    classDef frontend fill:#ccccff,stroke:#000099,stroke-width:2px;
    classDef external fill:#ffffcc,stroke:#999900,stroke-width:2px;
```
