# sagnikdatta2k6/noto-ai-app architecture

> Architecture diagram of the GitHub repository sagnikdatta2k6/noto-ai-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sagnikdatta2k6/noto-ai-app
- Repository: https://github.com/sagnikdatta2k6/noto-ai-app

## Overview

##### Project type and purpose
- This is a desktop “full-stack” Python application with a Kivy/KivyMD GUI (“frontend”) and a local AI-powered backend.
- Purpose: let users upload and interact with PDFs via Meta’s LLaMA 3 model running locally (through Ollama), while also offering OCR, summarization, search, and user management.

##### File structure
- Top-level files:
- main.py – entry point, orchestrates app startup
- ads.py – ad/banner logic (UI component)
- ai_service.py – wrapper for HTTP calls to Ollama (LLaMA 3 inference)
- ocr_service.py – image-to-text OCR
- csv_database.py & database.py – persistence layer (users.csv)
- user_management.py – login/signup workflows
- kv/ (Kivy layout files for splash, login, signup, main screens)
- tests/ – unit tests for ai_service
- Requirements.txt specifies dependencies (Kivy, PyMuPDF, etc.)
- No cloud: all inference and data storage are local.

##### README for additional insights
- Clearly calls out UI tech (Kivy/KivyMD), PDF parsing via PyMuPDF, AI backend via local HTTP API at localhost:11434, optional .env for API URL & model name.
- High-level workflow: PDF → parse → chat/summarize → UI.

a. Main components:
- GUI Layer (Kivy/KivyMD)
- Controller Layer (main.py + user_management.py + ads.py)
- Services Layer
– PDF Parser (PyMuPDF, integrated in ai_service or separate)
– OCR Service (ocr_service.py)
– AI Service (ai_service.py → HTTP to Ollama API)
- Persistence Layer (csv_database.py / database.py + users.csv)
- External Service (Ollama LLaMA 3 model via local REST at localhost:11434)
b. Relationships / data flow:
1. User actions in GUI → Controller
2. For PDF operations: Controller → PDF Parser / OCR → enrich text
3. Controller → AI Service → sends prompt + context → Ollama → receives response
4. Responses flow back to Controller → GUI render
5. User credentials flow: GUI → user_management → csv_database → users.csv → return auth status
c. Architectural patterns & design principles:
- MVC-style separation (kv + main.py as View/Controller; service modules as Model)
- Single process local application, modularized by concern (UI vs. service vs. data)
- Dependency inversion: services behind well-defined interfaces (ai_service, ocr_service)
d. Key technologies:
- Python, Kivy/KivyMD (UI)
- PyMuPDF (`fitz`) for PDF parsing
- Ollama HTTP API for LLaMA 3 inference
- CSV flat-file database for user data
- pytest for testing ai_service

##### Elements
- User → GUI interactions
- GUI → Controller → Service calls
- AI Service → HTTP → Ollama → AI Service
- Controller ↔ Database reads/writes
- Blue for UI layer
- Green for service layer (PDF/OCR/AI)
- Orange for persistence
- Gray/striped for external service

##### Final recommendations
- Be exhaustive: include every Python module as part of its logical layer.
- Asset usage only if it’s directly relevant (e.g., background video in splash screen).
- Use consistent naming matching file names (e.g., ai_service.py → “AI Service”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User"]:::user

    subgraph "UI Layer"
        GUI["Kivy/KivyMD GUI"]:::ui
        KV["kv/*.kv"]:::ui
        AS["assets/"]:::ui
    end

    subgraph "Controller Layer"
        Main["main.py"]:::controller
        Ads["ads.py"]:::controller
        UM["user_management.py"]:::controller
    end

    subgraph "Service Layer"
        PDF["PDF Parser"]:::service
        OCR["OCR Service"]:::service
        AI["AI Service"]:::service
    end

    subgraph "Persistence Layer"
        CSVDB["csv_database.py"]:::db
        SQLDB["database.py"]:::db
        UsersCSV["users.csv"]:::db
    end

    subgraph "External Service"
        Ollama["Ollama LLaMA 3\n(localhost:11434)"]:::external
    end

    subgraph "Tests"
        TestAI["tests/test_ai_service.py"]:::test
    end

    %% Connections
    User -->|"interactions"| GUI
    GUI -->|"events"| Main
    GUI --> KV
    GUI --> AS

    Main --> Ads
    Main --> UM
    Main --> PDF
    Main --> OCR
    Main --> AI
    UM --> CSVDB
    UM --> SQLDB
    CSVDB --> UsersCSV
    SQLDB --> UsersCSV

    AI -->|"HTTP request"| Ollama
    Ollama -->|"JSON response"| AI

    AI -->|"AI response"| Main
    Main -->|"render"| GUI

    TestAI -->|"tests"| AI

    %% Click Events
    click KV "https://github.com/sagnikdatta2k6/noto-ai-app/tree/main/kv/"
    click AS "https://github.com/sagnikdatta2k6/noto-ai-app/tree/main/assets/"
    click Main "https://github.com/sagnikdatta2k6/noto-ai-app/blob/main/main.py"
    click Ads "https://github.com/sagnikdatta2k6/noto-ai-app/blob/main/ads.py"
    click UM "https://github.com/sagnikdatta2k6/noto-ai-app/blob/main/user_management.py"
    click AI "https://github.com/sagnikdatta2k6/noto-ai-app/blob/main/ai_service.py"
    click OCR "https://github.com/sagnikdatta2k6/noto-ai-app/blob/main/ocr_service.py"
    click CSVDB "https://github.com/sagnikdatta2k6/noto-ai-app/blob/main/csv_database.py"
    click SQLDB "https://github.com/sagnikdatta2k6/noto-ai-app/blob/main/database.py"
    click UsersCSV "https://github.com/sagnikdatta2k6/noto-ai-app/blob/main/users.csv"
    click TestAI "https://github.com/sagnikdatta2k6/noto-ai-app/blob/main/tests/test_ai_service.py"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef controller fill:#1E90FF,stroke:#000,stroke-width:1px
    classDef service fill:#90EE90,stroke:#000,stroke-width:1px
    classDef db fill:#FFA500,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px,stroke-dasharray: 5 5
    classDef test fill:#FFB6C1,stroke:#000,stroke-width:1px
    class User user
    class User fill:#FFFFFF,stroke:#000,stroke-width:1px
    class User user
```
