# rizonesoft/notepad3 architecture

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

- Interactive diagram: https://gitdiagram.com/rizonesoft/notepad3
- Repository: https://github.com/rizonesoft/notepad3

## Overview

##### Project type and purpose
- Notepad3 is a native Windows desktop text editor built in C/C++, leveraging the Scintilla editing component for syntax highlighting.
- It integrates multiple third-party libraries (Oniguruma for regex, UCHARDET for encoding detection, TinyExpr for inline math), plugins (minipath file browser, grepWinNP3 search tool), and supports localization via language DLLs.

##### File structure for components
Top-level modules:
- src/ : Core Notepad3 application code (UI, menu, file I/O, settings)
- scintilla/ : Scintilla editing engine (document model, rendering, lexing APIs)
- lexilla/ : High-level lexer library supplying language lexers to Scintilla
- src/crypto, src/uthash, src/uchardet, src/tinyexpr* : Native static libraries for encryption, hash tables, encoding detection, expression evaluation
- grepWinNP3/ : Standalone search/replace utility invoked externally
- minipath/ : File-browser plugin launched from Notepad3
- language/ & grepWinNP3/sktoolslib_mod/ : Localization and shared UI helper code
- np3encrypt/ : Command-line encryption tool for batch file processing
- np3portableapp/ : PortableApps wrapper packaging Notepad3 and its plugins

##### Behaviors and interactions described in the README
- Notepad3.exe launches, loads settings (Notepad3.ini), initializes Scintilla control, registers lexers via Lexilla/Scintilla APIs.
- On file open, it uses encoding detection (UCHARDET, SimpleIni config) and optional AES-256 crypto.
- Search in files spawns grepWinNP3.exe; Browse spawns minipath.exe.
- Language DLLs are loaded on demand for UI strings.
- Settings and UI actions map to core editing operations or external tool invocations.

##### Components and relationships
A. Main Application Layer (Notepad3.exe)
- UI Layer: Win32 dialogs, menus, toolbars (src/*.c, *.cpp UI files)
- Core Controller: handles commands, settings, file I/O
- Scintilla Control: embedded editing component

B. Editor Engine & Lexers
- Scintilla Core (scintilla/src*, win32)
- Lexilla library for lexers (lexilla/include, lexers)

C. Services and Helpers
- Encoding Detection Service: UCHARDET (src/uchardet)
- Regex Engine: Oniguruma (Build/Docs/crypto/oniguruma)
- Crypto Module: Rijndael AES (src/crypto) & external np3encrypt
- Expression Evaluator: TinyExpr / TinyExprCPP (src/tinyexpr*)
- Hashing/Data Structures: UTHash (src/uthash)

D. External Tools & Plugins
- grepWinNP3.exe (grepWinNP3/) invoked for “Search in Files”
- minipath.exe (minipath/) invoked for “Browse”
- PortableApps wrapper (np3portableapp/)

E. Localization
- Language DLLs (language/np3_XX_XX/*.vcxproj) loaded for UI strings

F. Configuration & Resources
- Notepad3.ini (settings file)
- Themes (Build/Themes, themes/)

##### Architectural patterns and design principles
- Layered modular architecture: UI → Controller → Engine → Services
- Dependency injection of lexers and services via static linking
- Externalization of heavy tasks (search, file browsing) into separate executables
- Localization via DLLs for language switching at runtime
- Plugins and wrappers decoupled from core via command-line interfaces

##### Essential elements
- Arrowheads showing data flow and invocation direction
- Notes on protocols (Win32 APIs, command-line arguments)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Main Application"
        UI["UI Layer"]:::core
        Controller["Core Controller"]:::core
        UI -->|User Interaction| Controller
    end

    subgraph "Editor Engine"
        Scintilla["Scintilla Control"]:::core
        Lexers["Lexilla Library"]:::service
        Controller -->|"Invoke Edit Operations"| Scintilla
        Scintilla -->|"Load Lexers"| Lexers
    end

    subgraph Services
        Encoding["Encoding Detection Service\n(UCHARDET)"]:::service
        Crypto["Crypto Module (AES-256)"]:::service
        Regex["Regex Engine (Oniguruma)"]:::service
        Expr["Expression Evaluator\n(TinyExpr)"]:::service
        Hash["Hash Table Utilities\n(UTHASH)"]:::service
        Controller -->|"Detect Encoding"| Encoding
        Controller -->|"Encrypt/Decrypt"| Crypto
        Controller -->|"Use Regex"| Regex
        Controller -->|"Evaluate Expression"| Expr
        Controller -->|"Data Structures"| Hash
    end

    subgraph ExternalTools
        grep["grepWinNP3.exe"]:::external
        minipath["minipath.exe"]:::external
        portable["PortableApps Wrapper"]:::external
        Controller -->|"Search in Files"| grep
        Controller -->|"Browse"| minipath
        Controller -->|"Package"| portable
    end

    subgraph Localization
        lang["Language DLLs"]:::service
        Controller -->|"Load UI Strings"| lang
    end

    subgraph "Configuration & Resources"
        INI["Notepad3.ini"]:::config
        Themes["Themes & Bitmaps"]:::config
        Controller -->|"Read/Write Settings"| INI
        Controller -->|"Load Themes & Icons"| Themes
    end

    %% Click Events
    click UI "https://github.com/rizonesoft/notepad3/blob/master/src/Notepad3.vcxproj"
    click Controller "https://github.com/rizonesoft/notepad3/blob/master/src/Config/Config.cpp"
    click Scintilla "https://github.com/rizonesoft/notepad3/tree/master/scintilla/src/"
    click Lexers "https://github.com/rizonesoft/notepad3/tree/master/lexilla/include/"
    click Encoding "https://github.com/rizonesoft/notepad3/tree/master/src/uchardet/"
    click Regex "https://github.com/rizonesoft/notepad3/tree/master/scintilla/oniguruma/"
    click Crypto "https://github.com/rizonesoft/notepad3/tree/master/src/crypto/"
    click Expr "https://github.com/rizonesoft/notepad3/tree/master/src/tinyexpr/"
    click Hash "https://github.com/rizonesoft/notepad3/tree/master/src/uthash/"
    click grep "https://github.com/rizonesoft/notepad3/tree/master/grepWinNP3/"
    click minipath "https://github.com/rizonesoft/notepad3/tree/master/minipath/"
    click portable "https://github.com/rizonesoft/notepad3/tree/master/np3portableapp/"
    click lang "https://github.com/rizonesoft/notepad3/tree/master/language/"
    click INI "https://github.com/rizonesoft/notepad3/blob/master/Build/Notepad3.ini"
    click Themes "https://github.com/rizonesoft/notepad3/tree/master/Build/Themes/"

    %% Styles
    classDef core fill:#cfe2f3,stroke:#2a5d84,color:#000;
    classDef service fill:#d9ead3,stroke:#38761d,color:#000;
    classDef external fill:#fce5cd,stroke:#b45f06,color:#000;
    classDef config fill:#e7e6e6,stroke:#666,color:#000;
```
