# ms82119/nifimcp architecture

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

- Interactive diagram: https://gitdiagram.com/ms82119/nifimcp
- Repository: https://github.com/ms82119/nifimcp

## Overview

##### Project type and purpose
- This is a full-stack, Python-based “chat interface” application that sits between a user and one or more Apache NiFi instances.
- It comprises a browser-based UI (built with Streamlit) and a backend HTTP API server (built with FastAPI/uvicorn).
- The system integrates with:
- A Large Language Model (LLM) service (e.g., OpenAI)
- The NiFi REST API
- Custom “MCP tools” that wrap NiFi operations

##### File structure
- Top-level entries:
- config/ (application settings, logging setup)
- nifi_chat_ui/ (frontend Streamlit app)
- nifi_mcp_server/ (backend FastAPI server + core logic + NiFi API wrappers)
- tests/ (automated tests of NiFi operations)
- Within nifi_chat_ui/:
- app.py (Streamlit entrypoint)
- chat_manager.py (session/history management)
- mcp_handler.py (invokes backend API)
- system_prompt.md (base prompt for LLM)
- Within nifi_mcp_server/:
- server.py (FastAPI entrypoint)
- core.py (business logic orchestrator)
- nifi_client.py (low-level HTTP calls to NiFi)
- api_tools/*.py (tool implementations for create/lookup/modify/review operations)
- flow_documenter.py, request_context.py (helper modules)

##### README for additional insights
- The README confirms the two-tier architecture (Streamlit client + uvicorn FastAPI server).
- It calls out the LLM integration (“some tools are exposed to the LLM at different phases”).
- It describes the primary use cases: “document NiFi flows,” “create/modify NiFi components,” and “audit/log.”

##### Detail and essential elements
- Logging/config layers and how request context flows through for traceability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend" 
        Browser["User Browser / Streamlit UI"]:::frontend
        ChatManager["Chat Manager (session/history)"]:::frontend
        MCPHandler["MCP Handler (invoke backend API)"]:::frontend
        SystemPrompt["System Prompt (base LLM prompt)"]:::configstyle
    end

    %% Backend Layer
    subgraph "Backend"
        Server["FastAPI Server Entry Point"]:::backend
        Core["Core Orchestrator"]:::backend
        NiFiClient["NiFi HTTP Client"]:::backend
        subgraph "MCP Tools"
            Creation["Tool: creation.py"]:::backend
            Lookup["Tool: lookup.py"]:::backend
            Modification["Tool: modification.py"]:::backend
            Operation["Tool: operation.py"]:::backend
            Review["Tool: review.py"]:::backend
            Utils["Tools Utilities"]:::backend
        end
        FlowDoc["Flow Documenter"]:::backend
        ReqContext["Request Context & Logging Helpers"]:::backend
    end

    %% Configuration & Logging
    subgraph "Configuration & Logging"
        Settings["Configuration Settings"]:::configstyle
        LogSetup["Logging Setup (.py)"]:::configstyle
        LogYAML["Logging Configuration YAML"]:::configstyle
    end

    %% External Services
    subgraph "External Services"
        LLM["External LLM API Service"]:::external
        NiFi["Apache NiFi Cluster"]:::external
    end

    %% Test Harness
    subgraph "Tests"
        TestHarness["Automated Test Harness"]:::teststyle
    end

    %% Interactions
    Browser -->|"user input"| ChatManager
    ChatManager -->|"forward request"| MCPHandler
    MCPHandler -->|"HTTP POST"| Server
    Server -->|"handle request"| Core
    Core -->|"select tool"| Creation
    Core -->|"select tool"| Lookup
    Core -->|"select tool"| Modification
    Core -->|"select tool"| Operation
    Core -->|"select tool"| Review
    Core -->|"use utilities"| Utils
    Core -->|"call LLM API"| LLM
    Core -->|"invoke NiFi client"| NiFiClient
    NiFiClient -->|"REST API calls"| NiFi
    Core -->|"generate docs"| FlowDoc
    Server -->|"log request/response"| ReqContext
    ReqContext -->|"load config"| LogSetup
    ReqContext -->|"load config"| LogYAML
    Settings -->|"provide configs"| Server
    Settings -->|"provide configs"| Core
    Settings -->|"provide configs"| NiFiClient
    Server -->|"response"| MCPHandler
    MCPHandler -->|"display response"| Browser
    TestHarness -.->|"invoke endpoints"| Server

    %% Click Events
    click Browser "https://github.com/ms82119/nifimcp/blob/master/nifi_chat_ui/app.py"
    click ChatManager "https://github.com/ms82119/nifimcp/blob/master/nifi_chat_ui/chat_manager.py"
    click MCPHandler "https://github.com/ms82119/nifimcp/blob/master/nifi_chat_ui/mcp_handler.py"
    click SystemPrompt "https://github.com/ms82119/nifimcp/blob/master/nifi_chat_ui/system_prompt.md"
    click Server "https://github.com/ms82119/nifimcp/blob/master/nifi_mcp_server/server.py"
    click Core "https://github.com/ms82119/nifimcp/blob/master/nifi_mcp_server/core.py"
    click NiFiClient "https://github.com/ms82119/nifimcp/blob/master/nifi_mcp_server/nifi_client.py"
    click Creation "https://github.com/ms82119/nifimcp/blob/master/nifi_mcp_server/api_tools/creation.py"
    click Lookup "https://github.com/ms82119/nifimcp/blob/master/nifi_mcp_server/api_tools/lookup.py"
    click Modification "https://github.com/ms82119/nifimcp/blob/master/nifi_mcp_server/api_tools/modification.py"
    click Operation "https://github.com/ms82119/nifimcp/blob/master/nifi_mcp_server/api_tools/operation.py"
    click Review "https://github.com/ms82119/nifimcp/blob/master/nifi_mcp_server/api_tools/review.py"
    click Utils "https://github.com/ms82119/nifimcp/blob/master/nifi_mcp_server/api_tools/utils.py"
    click ReqContext "https://github.com/ms82119/nifimcp/blob/master/nifi_mcp_server/request_context.py"
    click FlowDoc "https://github.com/ms82119/nifimcp/blob/master/nifi_mcp_server/flow_documenter.py"
    click Settings "https://github.com/ms82119/nifimcp/blob/master/config/settings.py"
    click LogSetup "https://github.com/ms82119/nifimcp/blob/master/config/logging_setup.py"
    click LogYAML "https://github.com/ms82119/nifimcp/blob/master/logging_config.yaml"
    click TestHarness "https://github.com/ms82119/nifimcp/blob/master/tests/test_nifi_tools.py"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px;
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px;
    classDef configstyle fill:#D3D3D3,stroke:#333,stroke-width:1px;
    classDef teststyle fill:#FFB6C1,stroke:#333,stroke-width:1px;
```
