# cs340-25/notex architecture

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

- Interactive diagram: https://gitdiagram.com/cs340-25/notex
- Repository: https://github.com/cs340-25/notex

## Overview

##### Project type and purpose
- Notex is a desktop note-taking application built with Electron (to package a web app as a desktop app), a React/Vite frontend, and a Python/Flask backend.
- It provides CRUD operations on notes and user data via REST endpoints, persisting data in a local database (likely SQLite) through the `Backend/db_connection` module.

##### Main system components
A. Electron shell
- Files: `Electron/main.js`, `Electron/preload.js`, `Electron/forge.config.js`
- Role: Hosts the React frontend in a Chromium window, bridges renderer→main via the preload script, and bundles everything for distribution.
B. Frontend (React + Vite)
- Top-level: `Frontend/index.html`, `Frontend/src/main.jsx`, `Frontend/vite.config.js`
- UI layers:
- Pages (`Frontend/src/pages/...`)
- Reusable components (`Frontend/src/components/...`)
- Context Providers (`Frontend/src/Providers/...`)
- API wrappers (`Frontend/src/api/DataApi.jsx`, `UserApi.jsx`)
- Build system: Vite (`package.json` scripts, `npm run dev`)
C. Backend API (Flask)
- Entry point: `Backend/app.py`
- Route modules: `Backend/routes/data_routes.py`, `user_routes.py`
- DB access layer: `Backend/db_connection/connection.py`, and CRUD helpers (`read.py`, `insert.py`, etc.)
D. Database
- Likely an on-disk SQLite file managed by `db_connection/connection.py` and utilities.

##### Relationships & data flows
- User interacts with UI in Electron’s renderer process.
- React components call `DataApi` / `UserApi` → send HTTP requests to `http://localhost:5000/api/...`.
- Flask app receives requests in `app.py`, dispatches to route handlers in `routes/`, which call into `db_connection` for CRUD.
- `db_connection` modules open a connection, execute SQL, return results.
- Responses travel back over HTTP to the React app.

##### Architectural patterns & design principles
- Layered architecture: Presentation (React), API (Flask routes), Data Access (db_connection).
- MVC-like separation in the backend (routes vs. data layer).
- React uses Provider pattern (AuthContext, ThemeProvider, WorkspaceProvider).
- Electron uses a main/renderer split with a preload bridge for secure IPC if needed.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Electron Layer
    subgraph "Electron Host"
        direction TB
        EM["Electron Main Process\n(Electron/main.js)"]:::electron
        EP["Electron Preload Script\n(Electron/preload.js)"]:::electron
        EF["Electron Bundler Config\n(Electron/forge.config.js)"]:::electron
    end

    %% Frontend Layer
    subgraph "Frontend (React + Vite)" 
        direction TB
        HTML["React HTML Shell\n(Frontend/index.html)"]:::frontend
        VITE["Vite Config\n(Frontend/vite.config.js)"]:::frontend
        ENTRY["React Entry Point\n(Frontend/src/main.jsx)"]:::frontend
        subgraph "React Renderer"
            direction TB
            APP["Root/App Component\n(Frontend/src/App.jsx, App.scss)"]:::frontend
            subgraph "Pages\n(Frontend/src/pages/)"
                direction TB
                P1["Home, Login, etc.\n(Frontend/src/pages/)"]:::frontend
            end
            subgraph "Components\n(Frontend/src/components/)"
                direction TB
                C1["Sidebar, Canvas, etc.\n(Frontend/src/components/)"]:::frontend
            end
            subgraph "Providers\n(Frontend/src/Providers/)"
                direction TB
                PR["AuthContext, ThemeProvider,\nWorkspaceProvider"]:::frontend
            end
            subgraph "API Wrappers\n(Frontend/src/api/)"
                direction TB
                API1["DataApi.jsx"]:::frontend
                API2["UserApi.jsx"]:::frontend
            end
        end
    end

    %% Backend Layer
    subgraph "Backend (Flask API)" 
        direction TB
        APPPY["Flask Entry Point\n(Backend/app.py)"]:::backend
        subgraph "Routes\n(Backend/routes/)"
            direction TB
            DR["data_routes.py"]:::backend
            UR["user_routes.py"]:::backend
        end
        subgraph "DB Connection Layer\n(Backend/db_connection/)"
            direction TB
            CONN["connection.py"]:::backend
            CRUD["insert.py, read.py,\nupdate.py, delete.py"]:::backend
            UTIL["utils.py"]:::backend
        end
        EXDB["Example DB Script\n(Backend/example_db_conn.py)"]:::backend
    end

    %% Database
    DB[(Local SQLite DB File)]:::db

    %% Scripts
    subgraph "Run Scripts"
        direction TB
        SB["run.bat"]:::script
        SH["run.sh"]:::script
    end

    %% Connections
    EM -->|launch| EP
    EP -->|inject to Renderer| ENTRY
    ENTRY -->|loads App| APP
    APP -->|uses Providers| PR
    APP -->|renders Pages| P1
    APP -->|renders Components| C1
    APP -->|calls| API1
    APP -->|calls| API2
    API1 -->|HTTP GET/POST| APPPY
    API2 -->|HTTP GET/POST| APPPY
    APPPY -->|routes to| DR
    APPPY -->|routes to| UR
    DR -->|calls| CONN
    UR -->|calls| CONN
    CONN -->|uses| CRUD
    CONN -->|uses| UTIL
    CONN -->|I/O| DB
    SB -->|starts| EM
    SB -->|starts| APPPY
    SH -->|starts| EM
    SH -->|starts| APPPY

    %% Click Events
    click EM "https://github.com/cs340-25/notex/blob/main/Electron/main.js"
    click EP "https://github.com/cs340-25/notex/blob/main/Electron/preload.js"
    click EF "https://github.com/cs340-25/notex/blob/main/Electron/forge.config.js"
    click HTML "https://github.com/cs340-25/notex/blob/main/Frontend/index.html"
    click ENTRY "https://github.com/cs340-25/notex/blob/main/Frontend/src/main.jsx"
    click VITE "https://github.com/cs340-25/notex/blob/main/Frontend/vite.config.js"
    click APP "https://github.com/cs340-25/notex/blob/main/Frontend/src/App.jsx"
    click P1 "https://github.com/cs340-25/notex/tree/main/Frontend/src/pages/"
    click C1 "https://github.com/cs340-25/notex/tree/main/Frontend/src/components/"
    click PR "https://github.com/cs340-25/notex/tree/main/Frontend/src/Providers/"
    click API1 "https://github.com/cs340-25/notex/blob/main/Frontend/src/api/DataApi.jsx"
    click API2 "https://github.com/cs340-25/notex/blob/main/Frontend/src/api/UserApi.jsx"
    click APPPY "https://github.com/cs340-25/notex/blob/main/Backend/app.py"
    click DR "https://github.com/cs340-25/notex/blob/main/Backend/routes/data_routes.py"
    click UR "https://github.com/cs340-25/notex/blob/main/Backend/routes/user_routes.py"
    click CONN "https://github.com/cs340-25/notex/blob/main/Backend/db_connection/connection.py"
    click CRUD "https://github.com/cs340-25/notex/blob/main/Backend/db_connection/insert.py"
    click UTIL "https://github.com/cs340-25/notex/blob/main/Backend/db_connection/utils.py"
    click EXDB "https://github.com/cs340-25/notex/blob/main/Backend/example_db_conn.py"

    %% Styles
    classDef electron fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef frontend fill:#add8e6,stroke:#333,stroke-width:1px
    classDef backend fill:#90ee90,stroke:#333,stroke-width:1px
    classDef db fill:#ffa500,stroke:#333,stroke-width:1px
    classDef script fill:#f0e68c,stroke:#333,stroke-width:1px
```
