# mounseflit/ni-ma architecture

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

- Interactive diagram: https://gitdiagram.com/mounseflit/ni-ma
- Repository: https://github.com/mounseflit/ni-ma

## Overview

##### Project type and purpose
- This is a multi‐repo, full-stack IoT/ML system for real-time illegal-logging detection.
- Forest Sensors (Arduino devices) capture audio, a Data API ingests events, an ML Service classifies sounds, alerts go out via Twilio, and a React Console visualizes events. There’s also a static Landing Page for marketing.

##### File structure
- Top-level directories:
- Sensor: `forest-sensor.ino` for hardware code.
- Back-End: Node.js/Express ingestion service (`server/server.js`), uses Firebase Admin SDK (`secret.sample/firebase-admin-sdk.json`), IBM Cloud Foundry manifest.
- ML: Python microservice (Django/Flask style with `manage.py`, `server/routes`, `services/Detector.py`), Swagger UI (`public/swagger-ui`), containerized via `Dockerfile`, IBM Cloud Foundry manifest.
- Front-End: React app (`src/`), Firebase client (`src/firebase.js`), hosted on Surge/static.
- Landing Page: static HTML/CSS/JS marketing site with an embedded AI demo (`ai/CODE.py`, model files).

##### README for additional insights
- Architecture described in text:
1. Forest Sensors → raw alerts DB
2. Data Server → ML-Service classification
3. Chainsaw alerts → DB + Twilio SMS/Call
4. Alerts → Forest Console map

a. Main components
- Forest Sensor Devices (Arduino)
- Data Ingestion API (Node.js/Express)
- ML Classification Service (Python + Docker + Swagger)
- Database (Firebase Realtime DB or Firestore)
- Notification Service (Twilio)
- Web Console (React + Firebase client)
- Landing Page (Static site)
- Cloud Platform (IBM Cloud Foundry)
b. Relationships & data flow
1. Sensor captures audio → POST to Data API
2. Data API writes raw event to DB and/or invokes ML Service (REST call)
3. ML Service fetches or receives raw data → runs Detector → returns classification
4. On “chainsaw” → Data API persists classified alert to DB → invokes Twilio API → SMS/Call to responders
5. React Console subscribes to DB events via Firebase SDK → renders markers on map
6. Landing Page is a separate static site for marketing/demo
c. Architectural patterns & principles
- Microservices: separate Data API & ML Service
- Event-driven: DB as pub/sub for real-time updates
- RESTful APIs between components
- Containerization for ML, managed on Cloud Foundry
- Single-page React app with secure Firebase integration
d. Key technologies
- Hardware: Arduino C++
- Data API: Node.js, Express, Firebase Admin SDK
- ML Service: Python (Flask/Django), Docker, Swagger UI
- Database: Firebase Realtime Database / Firestore
- Notification: Twilio REST API
- Frontend: React, Firebase JS SDK
- Hosting: IBM Cloud Foundry, Surge (static sites)

##### Detail
- Repository as a separate component.
- Deployment boundaries (IBM Cloud Foundry).
- Service-to-service calls (API ↔ ML), and third-party integrations (Firebase Admin, Twilio).

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Device Tier"
        Sensor["Forest Sensor Devices"]:::device
    end

    subgraph "API & ML Tier"
        subgraph "Data Ingestion API"
            DataAPI["Data Ingestion API (Node.js)"]:::api
            Package["package.json"]:::api
            FirebaseAdmin["firebase-admin-sdk.json"]:::api
            ManifestAPI["manifest.yml"]:::api
        end
        subgraph "ML Classification Service"
            MLService["ML Classification Service (Python)"]:::api
            Manage["manage.py"]:::api
            Routes["predict.py"]:::api
            Detector["Detector Module"]:::api
            Pipfile["Pipfile"]:::api
            Dockerfile["Dockerfile"]:::api
            ManifestML["manifest.yml"]:::api
            Swagger["Swagger UI"]:::api
        end
    end

    subgraph "Data Tier"
        DB["Firebase Database"]:::db
    end

    subgraph "Notification Tier"
        Twilio["Twilio Notification Service"]:::external
    end

    subgraph "Client Tier"
        subgraph "Forest Console"
            ReactConsole["Forest Console (React SPA)"]:::ui
            IndexJS["index.js"]:::ui
            Components["Components"]:::ui
            Pages["Pages"]:::ui
            FirebaseClient["firebase.js"]:::ui
            Shell["index.html"]:::ui
        end
        subgraph "Landing Page"
            LandingPage["Landing Page (Static Site)"]:::ui
            LPIndex["index.html"]:::ui
            AIDemo["AI Demo Script"]:::ui
            Assets["assets"]:::ui
        end
    end

    Sensor -->|POST /events| DataAPI
    DataAPI -->|write raw event| DB
    DataAPI -->|predict request| MLService
    MLService -->|classification response| DataAPI
    DataAPI -->|chainsaw alert| Twilio
    ReactConsole -->|subscribe to updates| DB

    click Sensor "https://github.com/mounseflit/ni-ma/blob/main/Sensor/src/forest-sensor.ino"
    click DataAPI "https://github.com/mounseflit/ni-ma/blob/main/Back-End/server/server.js"
    click Package "https://github.com/mounseflit/ni-ma/blob/main/Back-End/package.json"
    click FirebaseAdmin "https://github.com/mounseflit/ni-ma/blob/main/Back-End/server/secret.sample/firebase-admin-sdk.json"
    click ManifestAPI "https://github.com/mounseflit/ni-ma/blob/main/Back-End/manifest.yml"
    click MLService "https://github.com/mounseflit/ni-ma/blob/main/ML/manage.py"
    click Manage "https://github.com/mounseflit/ni-ma/blob/main/ML/manage.py"
    click Routes "https://github.com/mounseflit/ni-ma/blob/main/ML/server/routes/predict.py"
    click Detector "https://github.com/mounseflit/ni-ma/blob/main/ML/server/services/Detector.py"
    click Pipfile "https://github.com/mounseflit/ni-ma/tree/main/ML/Pipfile"
    click Dockerfile "https://github.com/mounseflit/ni-ma/tree/main/ML/Dockerfile"
    click ManifestML "https://github.com/mounseflit/ni-ma/blob/main/ML/manifest.yml"
    click Swagger "https://github.com/mounseflit/ni-ma/blob/main/ML/public/swagger-ui/index.html"
    click ReactConsole "https://github.com/mounseflit/ni-ma/blob/main/Front-End/src/index.js"
    click IndexJS "https://github.com/mounseflit/ni-ma/blob/main/Front-End/src/index.js"
    click Components "https://github.com/mounseflit/ni-ma/tree/main/Front-End/src/Components"
    click Pages "https://github.com/mounseflit/ni-ma/tree/main/Front-End/src/Pages"
    click FirebaseClient "https://github.com/mounseflit/ni-ma/blob/main/Front-End/src/firebase.js"
    click Shell "https://github.com/mounseflit/ni-ma/blob/main/Front-End/public/index.html"
    click LPIndex "https://github.com/mounseflit/ni-ma/blob/main/Landing Page/index.html"
    click AIDemo "https://github.com/mounseflit/ni-ma/blob/main/Landing Page/ai/CODE.py"
    click Assets "https://github.com/mounseflit/ni-ma/tree/main/Landing Page/assets"

    classDef device fill:lightgreen,stroke:#333,stroke-width:1px
    classDef api fill:lightblue,stroke:#333,stroke-width:1px
    classDef db fill:lightyellow,stroke:#333,stroke-width:1px
    classDef external fill:lightcoral,stroke:#333,stroke-width:1px
    classDef ui fill:plum,stroke:#333,stroke-width:1px
```
