# larsvogt/knowledge-graph-building-blocks architecture

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

- Interactive diagram: https://gitdiagram.com/larsvogt/knowledge-graph-building-blocks
- Repository: https://github.com/larsvogt/knowledge-graph-building-blocks

## Overview

##### Project Type and Purpose
- The application’s purpose is to demonstrate how modular knowledge graph components (KGBBs) can guide the creation, management, and exploration of FAIR (findable, accessible, interoperable, and reusable) knowledge graphs.
- The README explains that the prototype uses predefined patterns (graph patterns, input controls, access templates, display templates, and CRUD queries) to structure and process knowledge graphs, all connected through a Neo4j backend.

##### Analysis of the File Structure and Its Architectural Implications
- Top-Level Files and Directories:
- Files such as app.py, setup.py, code_notes.py, scrap_note.py, and test.py indicate that there’s an executable web server component (likely a Flask application), setup/installation capabilities, and some exploratory or test code.
- The “KGBB” directory includes modules like KGBBFunctions_and_Classes.py and connectNeo4j.py, which encapsulate the business logic and connectivity aspects to Neo4j (using the bolt:// protocol with provided authentication details).
- The “static” folder includes JavaScript (jQuery and custom JS forms), CSS, and font assets, clearly representing the frontend assets.
- The “templates” folder is populated with numerous HTML files, which are likely Jinja2 templates used to render various views corresponding to different semantic unit types (statement units, item units, etc.).
- Architectural Clues:
- The presence of templates and static assets indicates a separation of presentation (client-side) and logic (server-side).
- The specialized modules for Neo4j connectivity show a clear backend that communicates with a graph database.
- The modular grouping of files (e.g., KGBB components, various HTML templates for different semantic unit views, and static assets) suggests that the overall system is organized into several layers: user interface, backend processing, and database integration.

##### Main Components
a. Frontend / Presentation Layer:
- User's Web Browser: Represents the client that loads the application.
- HTML Templates: All the view files under the “templates” directory that render forms, graphs, and interactive UI components.
- Static Assets: JavaScript files (e.g., form_bioportal_complete.js, jquery-3.6.0.js), CSS styles (like standard.css and font-awesome assets) that define the client-side behavior and styling.

b. Backend / Application Layer:
- Flask Application: Centered around app.py, which drives the requests, renders templates, and handles routing.
- KGBB Modules: Specifically, KGBBFunctions_and_Classes.py and connectNeo4j.py, which contain business logic, domain-specific functionalities for semantic unit processing, and the logic for connecting to and querying the Neo4j database.
- Utility and Setup Scripts: Files like setup.py and code_notes.py support environment preparation and serve as documentation or development notes.

c. Data/Persistence Layer:
- Neo4j Graph Database: As required by the README, Neo4j (Version 4.2.4 or above with APOC plugin) is the primary datastore, accessed via the bolt:// protocol (bolt://localhost:7687) using specified credentials.

d. Documentation and Additional Resources:
- The Vogt_Retreat_2021_extended.pdf provides contextual details on the semantics and vision behind the KGBB concept.
- README serves as the high-level documentation for the system’s purpose, architectural overview, and setup instructions.

##### Relationships and Data Flow
- How client-side requests (HTTP GET/POST) are sent from the web browser to the Flask server.
- How the Flask application routes these requests to the appropriate business logic in the KGBB modules.
- The responses (rendered HTML pages, JSON responses, etc.) then flow back from the backend to the client.

##### Key Architectural Patterns and Design Principles
- Separation of Concerns: Clearly segmented layers between presentation (templates, static files), application logic (Flask + KGBB modules), and data persistence (Neo4j).
- Modular Design: Each semantic unit or KGBB is implemented as a separate module/component, which potentially allows for scalability by introducing new types of semantic units without major changes to the overall structure.
- Use of Standard Web Framework Patterns: The combination of a Flask application with Jinja2 templates and a dedicated module to handle database connectivity reflects a fairly standard MVC/MV* pattern.
- Integration of External Technologies: Reliance on Neo4j for graph data storage and the use of third-party libraries (e.g., jQuery, Font Awesome).

##### Elements
- "Web Client / Browser"
- "Flask Application (app.py)"
- "KGBB Business Logic Modules (KGBBFunctions_and_Classes.py, connectNeo4j.py)"
- "HTML Templates (various files under /templates)"
- "Static Assets (JS, CSS under /static)"
- "Neo4j Database" (with note of connection details: bolt://localhost:7687)
- "Setup & Documentation" (setup.py, README, Vogt_Retreat_2021_extended.pdf)
- User requests and responses between the browser and Flask app.
- Internal interactions from Flask to the KGBB modules.
- Database calls from the KGBB modules (via connectNeo4j.py) to the Neo4j server.
- Labels/Annotations:
- Component with its role (e.g., “Handles user input via forms”, “Contains business logic for managing knowledge graph units”).
- Flows with notes like “HTTP Requests/Responses” and “Graph Queries”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        Browser["Web Client / Browser"]
        HTMLTemplates["HTML Templates"]
        StaticAssets["Static Assets"]
    end

    %% Backend Layer
    subgraph "Backend Layer"
        FlaskApp["Flask Application (app.py)"]
        BusinessLogic["KGBB Business Logic Modules"]
        Neo4jConnector["Neo4j Connection Module"]
    end

    %% Data Layer
    subgraph "Data Layer"
        Neo4jDB["Neo4j Database<br/>(bolt://localhost:7687)"]
    end

    %% Utilities & Documentation
    subgraph "Utilities & Documentation"
        UtilitySetup["Utility & Setup Scripts (setup.py, code_notes.py, scrap_note.py, test.py)"]
        Documentation["Documentation & Resources (README.md, Vogt_Retreat_2021_extended.pdf)"]
    end

    %% Data Flow Connections
    Browser -->|"HTTPRequests/Responses"| FlaskApp
    FlaskApp -->|"RenderViews"| HTMLTemplates
    FlaskApp -->|"ServeStatic"| StaticAssets
    FlaskApp -->|"RoutesRequests"| BusinessLogic
    BusinessLogic -->|"GraphQueries"| Neo4jConnector
    Neo4jConnector -->|"DBOperations"| Neo4jDB

    %% Additional Guidance from Utilities & Documentation
    UtilitySetup -->|"SetupEnvironment"| FlaskApp
    Documentation -.->|"Instructions"| FlaskApp

    %% Click Events
    click HTMLTemplates "https://github.com/larsvogt/knowledge-graph-building-blocks/tree/main/templates"
    click StaticAssets "https://github.com/larsvogt/knowledge-graph-building-blocks/tree/main/static"
    click FlaskApp "https://github.com/larsvogt/knowledge-graph-building-blocks/blob/main/app.py"
    click BusinessLogic "https://github.com/larsvogt/knowledge-graph-building-blocks/blob/main/KGBB/KGBBFunctions_and_Classes.py"
    click Neo4jConnector "https://github.com/larsvogt/knowledge-graph-building-blocks/blob/main/KGBB/connectNeo4j.py"
    click UtilitySetup "https://github.com/larsvogt/knowledge-graph-building-blocks/blob/main/setup.py"
    click Documentation "https://github.com/larsvogt/knowledge-graph-building-blocks/blob/main/README.md"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef database fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef docs fill:#D3D3D3,stroke:#000,stroke-width:2px;

    class Browser,HTMLTemplates,StaticAssets frontend;
    class FlaskApp,BusinessLogic,Neo4jConnector backend;
    class Neo4jDB database;
    class UtilitySetup,Documentation docs;
```
