# whats-up-pro/nt547 architecture

> Architecture diagram of the GitHub repository whats-up-pro/nt547, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/whats-up-pro/nt547
- Repository: https://github.com/whats-up-pro/nt547

## Overview

##### Project Type and Purpose
- This is a full-stack web application: a Control Flow Graph (CFG) visualizer for Solidity smart contracts.
- Purpose: Users paste Solidity code into a web editor, the system parses the code into an AST, constructs a CFG, and renders it interactively for security analysis and comprehension.

##### File Structure Analysis
Top-level:
- backend/ (Python Flask service, plus a Node helper)
- frontend/ (React app)
- documentation and setup guides (.md files)
- test_contracts.js (sample inputs)

backend/:
- app.py – Flask entry point; defines REST routes (health checks, analysis endpoints)
- api/routes.py – Flask route definitions
- security_analyzer.py – placeholder for server-side security logic
- node_helper/ – Node.js microservice (index.js) for AST or supplemental parsing tasks
- requirements.txt – Python dependencies

frontend/:
- public/index.html – host HTML page
- src/index.js, App.js – React bootstrapping and main component
- src/components/CodeEditor.js – Monaco code editor wrapper
- src/components/CFGVisualizer.js – React Flow graph renderer
- src/utils/parser.js – AST parsing and CFG-builder logic using @solidity-parser/parser
- package.json – React and tool dependencies

##### README Insights
- Architecture is explicitly two-tier: React frontend and Flask backend with CORS enabled.
- Frontend handles AST parsing and CFG construction via @solidity-parser/parser and React Flow.
- Backend currently only provides health checks, but is extensible (e.g., to offload parsing or security analysis).
- No database layer; interactions are ephemeral.

a. Main Components
1. Client Browser (User Agent)
2. React Frontend
- CodeEditor (Monaco)
- CFGBuilder & Parser (utils/parser.js)
- Visualization Engine (React Flow)
3. Backend Services
- Flask REST API (app.py, api/routes.py)
- SecurityAnalyzer (security_analyzer.py)
- NodeHelper Microservice (node_helper/index.js)
4. External Libraries/Services
- @solidity-parser/parser (JavaScript AST parser)
- React Flow (graph lib)
- Monaco Editor
- Flask-CORS
- Axios (HTTP client)

b. Relationships & Data Flows
- User → React App (code input)
- React App → Parser/CFGBuilder (AST & graph model)
- React App ↔ Flask API (health checks, future server analysis) via Axios
- Flask API → NodeHelper (spawn JS process for AST or heavy jobs)
- NodeHelper → Flask API (returns parse results)
- React App → React Flow (renders CFG)
- User ↔ React Flow (interactive node clicks → highlight code)

c. Architectural Patterns & Principles
- Two-tier client-server separation
- Modular frontend: editor, parser, visualizer
- Microservice pattern for Node-based parsing helper
- RESTful API layer with CORS
- Separation of concerns: UI vs. processing vs. data models

d. Key Technologies & Libraries
- Frontend: React18, Monaco Editor, @solidity-parser/parser, React Flow, Axios
- Backend: Python3.8+, Flask, Flask-CORS, Node.js (for node_helper)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    User["User Browser"]:::external

    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        ReactApp["React App"]:::frontend
        CodeEditor["CodeEditor\n(Monaco)"]:::frontend
        Parser["Parser & CFG Builder"]:::core
        Visualizer["CFGVisualizer\n(React Flow)"]:::frontend

        ReactApp -->|loads module| CodeEditor
        ReactApp -->|loads module| Parser
        ReactApp -->|loads module| Visualizer

        User -->|paste code| CodeEditor
        CodeEditor -->|code text| Parser
        Parser -->|AST & CFG| Visualizer
        Visualizer -->|render graph| User

        %% HTTP to backend
        Parser -->|HTTP/JSON via Axios| FlaskAPI
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        FlaskAPI["Flask API Gateway\n(app.py)"]:::service
        Routes["Route Definitions\n(api/routes.py)"]:::service
        SecAnalyzer["SecurityAnalyzer\n(security_analyzer.py)"]:::core
        NodeHelper["NodeHelper Service\n(node_helper/index.js)"]:::service

        FlaskAPI -->|registers endpoints| Routes
        FlaskAPI -->|invokes| SecAnalyzer
        FlaskAPI -->|spawn process| NodeHelper
        NodeHelper -->|AST results| FlaskAPI
    end

    %% Connections between layers
    Parser -->|HTTP/JSON via Axios| FlaskAPI

    %% Click Events
    click ReactApp "https://github.com/whats-up-pro/nt547/blob/main/frontend/src/index.js"
    click ReactApp "https://github.com/whats-up-pro/nt547/blob/main/frontend/src/App.js"
    click ReactApp "https://github.com/whats-up-pro/nt547/blob/main/frontend/public/index.html"
    click CodeEditor "https://github.com/whats-up-pro/nt547/blob/main/frontend/src/components/CodeEditor.js"
    click CodeEditor "https://github.com/whats-up-pro/nt547/blob/main/frontend/src/components/CodeEditor.css"
    click Parser "https://github.com/whats-up-pro/nt547/blob/main/frontend/src/utils/parser.js"
    click Visualizer "https://github.com/whats-up-pro/nt547/blob/main/frontend/src/components/CFGVisualizer.js"
    click Visualizer "https://github.com/whats-up-pro/nt547/blob/main/frontend/src/components/CFGVisualizer.css"
    click FlaskAPI "https://github.com/whats-up-pro/nt547/blob/main/backend/app.py"
    click Routes "https://github.com/whats-up-pro/nt547/blob/main/backend/api/routes.py"
    click SecAnalyzer "https://github.com/whats-up-pro/nt547/blob/main/backend/security_analyzer.py"
    click NodeHelper "https://github.com/whats-up-pro/nt547/blob/main/backend/node_helper/index.js"
    click NodeHelper "https://github.com/whats-up-pro/nt547/blob/main/backend/node_helper/package.json"
    click NodeHelper "https://github.com/whats-up-pro/nt547/blob/main/backend/node_helper/package-lock.json"
    click FrontendDeps "https://github.com/whats-up-pro/nt547/blob/main/frontend/package.json"
    click FrontendDeps "https://github.com/whats-up-pro/nt547/blob/main/frontend/package-lock.json"
    click BackendDeps "https://github.com/whats-up-pro/nt547/blob/main/backend/requirements.txt"
    click TestContracts "https://github.com/whats-up-pro/nt547/blob/main/test_contracts.js"

    %% Style Definitions
    classDef frontend fill:#D0E8FF,stroke:#0288D1,color:#000;
    classDef core fill:#D0FFD8,stroke:#2E7D32,color:#000;
    classDef service fill:#FFE6B3,stroke:#F9A825,color:#000;
    classDef external fill:#F2F2F2,stroke:#9E9E9E,color:#000;
```
