# keinsell/neuronek architecture

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

- Interactive diagram: https://gitdiagram.com/keinsell/neuronek
- Repository: https://github.com/keinsell/neuronek

## Overview

##### Main Components Identification

a. Core Application Layers:
- CLI Interface Layer
- TUI (Terminal User Interface) Layer
- Core Business Logic Layer
- Database Layer

b. Major Modules:
- Ingestion Management
- Substance Management
- Analysis System
- Journal System

##### Component Relationships

**User Interface Layer**

- CLI Interface (src/cli/)
- Command Handlers (analyze.rs, ingestion.rs, substance.rs, stats.rs)

- TUI Interface (src/tui/)
- Views (ingestion, welcome, loading)
- Widgets (dosage, etc.)

**Core Layer (src/core/)**

- Configuration (config.rs)
- Error Handling (error_handling.rs)
- Logging (logging.rs)

**Domain Layer**

- Ingestion Module (src/ingestion/)
- Commands
- Queries
- Models

- Substance Module (src/substance/)
- Repository
- Route of Administration

- Analyzer Module (src/analyzer/)
- Services
- Models

**Data Layer (src/database/)**

- Entities
- Ingestion
- Substance
- Route of Administration

- Migrations

##### Important Architectural Patterns to Highlight

- Repository Pattern (seen in substance/repository.rs)
- Command Query Responsibility Segregation (CQRS) (visible in ingestion/command.rs and query.rs)
- Layer separation (UI, Core, Domain, Data)

##### Key Interactions

- CLI/TUI → Core Layer → Domain Layer → Data Layer flow
- Analyzer interactions with Ingestion and Substance data
- Database migrations and schema management
- Configuration and logging system integration

##### Additional Elements

- External dependencies (from Cargo.toml)
- Configuration sources (.envrc, config files)
- Build and deployment workflow connections
- Testing infrastructure

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        CLI["CLI Interface"]
        TUI["TUI Interface"]
        
        subgraph CLI_Components["CLI Components"]
            CLI_Main["Main CLI"]
            CLI_Analysis["Analysis Commands"]
            CLI_Ingestion["Ingestion Commands"]
            CLI_Substance["Substance Commands"]
            CLI_Stats["Statistics Commands"]
        end

        subgraph TUI_Components["TUI Components"]
            TUI_Main["Main TUI"]
            TUI_App["TUI App"]
            TUI_Views["Views"]
            TUI_Layouts["Layouts"]
            TUI_Widgets["Widgets"]
        end
    end

    subgraph Core["Core Layer"]
        Config["Configuration"]
        ErrorHandling["Error Handling"]
        Logging["Logging"]
        Foundation["Foundation"]
    end

    subgraph Domain["Domain Layer"]
        subgraph Ingestion["Ingestion Module"]
            Ing_Commands["Commands"]
            Ing_Queries["Queries"]
            Ing_Models["Models"]
        end

        subgraph Substance["Substance Module"]
            Sub_Repo["Repository"]
            Sub_ROA["Route of Administration"]
            Sub_Error["Error Handling"]
        end

        subgraph Analyzer["Analyzer Module"]
            Ana_Services["Services"]
            Ana_Models["Models"]
        end

        Journal["Journal System"]
    end

    subgraph Data["Data Layer"]
        DB["Main Database"]
        subgraph Entities["Database Entities"]
            Ent_Ingestion["Ingestion"]
            Ent_Substance["Substance"]
            Ent_ROA["Route of Administration"]
        end
        Migrations["Migrations"]
        Schema["Schema"]
    end

    %% Relationships
    CLI --> Core
    TUI --> Core
    Core --> Domain
    Domain --> Data
    Analyzer --> Ingestion
    Analyzer --> Substance

    %% Click events
    click CLI_Main "https://github.com/keinsell/neuronek/blob/trunk/src/cli/mod.rs"
    click CLI_Analysis "https://github.com/keinsell/neuronek/blob/trunk/src/cli/analyze.rs"
    click CLI_Ingestion "https://github.com/keinsell/neuronek/blob/trunk/src/cli/ingestion.rs"
    click CLI_Substance "https://github.com/keinsell/neuronek/blob/trunk/src/cli/substance.rs"
    click CLI_Stats "https://github.com/keinsell/neuronek/blob/trunk/src/cli/stats.rs"
    
    click TUI_Main "https://github.com/keinsell/neuronek/blob/trunk/src/tui/mod.rs"
    click TUI_App "https://github.com/keinsell/neuronek/blob/trunk/src/tui/app.rs"
    click TUI_Views "https://github.com/keinsell/neuronek/tree/trunk/src/tui/views/"
    click TUI_Layouts "https://github.com/keinsell/neuronek/tree/trunk/src/tui/layout/"
    click TUI_Widgets "https://github.com/keinsell/neuronek/tree/trunk/src/tui/widgets/"
    
    click Config "https://github.com/keinsell/neuronek/blob/trunk/src/core/config.rs"
    click ErrorHandling "https://github.com/keinsell/neuronek/blob/trunk/src/core/error_handling.rs"
    click Logging "https://github.com/keinsell/neuronek/blob/trunk/src/core/logging.rs"
    click Foundation "https://github.com/keinsell/neuronek/blob/trunk/src/core/foundation.rs"
    
    click Ing_Commands "https://github.com/keinsell/neuronek/blob/trunk/src/ingestion/command.rs"
    click Ing_Queries "https://github.com/keinsell/neuronek/blob/trunk/src/ingestion/query.rs"
    click Ing_Models "https://github.com/keinsell/neuronek/blob/trunk/src/ingestion/model.rs"
    
    click Sub_Repo "https://github.com/keinsell/neuronek/blob/trunk/src/substance/repository.rs"
    click Sub_ROA "https://github.com/keinsell/neuronek/tree/trunk/src/substance/route_of_administration/"
    click Sub_Error "https://github.com/keinsell/neuronek/blob/trunk/src/substance/error.rs"
    
    click Ana_Services "https://github.com/keinsell/neuronek/blob/trunk/src/analyzer/service.rs"
    click Ana_Models "https://github.com/keinsell/neuronek/blob/trunk/src/analyzer/model.rs"
    
    click DB "https://github.com/keinsell/neuronek/blob/trunk/src/database/mod.rs"
    click Ent_Ingestion "https://github.com/keinsell/neuronek/blob/trunk/src/database/entities/ingestion.rs"
    click Ent_Substance "https://github.com/keinsell/neuronek/blob/trunk/src/database/entities/substance.rs"
    click Ent_ROA "https://github.com/keinsell/neuronek/blob/trunk/src/database/entities/substance_route_of_administration.rs"
    click Migrations "https://github.com/keinsell/neuronek/tree/trunk/src/database/migrations/"
    click Schema "https://github.com/keinsell/neuronek/blob/trunk/src/database/schema.sql"
    
    click Journal "https://github.com/keinsell/neuronek/blob/trunk/src/journal/mod.rs"

    classDef ui fill:#a8d1ff,stroke:#333,stroke-width:2px
    classDef core fill:#90EE90,stroke:#333,stroke-width:2px
    classDef domain fill:#FFB6C1,stroke:#333,stroke-width:2px
    classDef data fill:#FFE4B5,stroke:#333,stroke-width:2px
    
    class CLI,TUI,CLI_Components,TUI_Components,CLI_Main,CLI_Analysis,CLI_Ingestion,CLI_Substance,CLI_Stats,TUI_Main,TUI_App,TUI_Views,TUI_Layouts,TUI_Widgets ui
    class Core,Config,ErrorHandling,Logging,Foundation core
    class Domain,Ingestion,Substance,Analyzer,Journal,Ing_Commands,Ing_Queries,Ing_Models,Sub_Repo,Sub_ROA,Sub_Error,Ana_Services,Ana_Models domain
    class Data,DB,Entities,Ent_Ingestion,Ent_Substance,Ent_ROA,Migrations,Schema data
```
