# abhij1401/ais-illegal-fishing-detection architecture

> Architecture diagram of the GitHub repository abhij1401/ais-illegal-fishing-detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abhij1401/ais-illegal-fishing-detection
- Repository: https://github.com/abhij1401/ais-illegal-fishing-detection

## Overview

##### Project Type & Purpose
- This is an open-source, single-page Streamlit application that ingests AIS vessel data, applies hybrid ML models (Isolation Forest + Autoencoder) to flag suspicious (illegal) fishing activities, and provides real-time geospatial visualization.

##### Main Architectural Components
a. Presentation Layer (Frontend)
- app.py: Streamlit web app that renders forms, maps, and results.
b. Business Logic / ML Engine (Backend)
- model.py: Data preprocessing pipelines, feature engineering (speed, heading changes), calls to Isolation Forest & Autoencoder models.
c. Data Layer
- dataset/ais_data.csv & illegal_Data.txt: Historical AIS data used for seeding or re-training models.
- prediction_log.csv: Append-only CSV log of all user inputs & model outputs.
d. Visualization Subsystem
- Streamlit’s built-in map functions (with Folium/pydeck under the hood) to render vessel positions, popular ports, and anomalies.
e. External Services & Dependencies
- Python libraries: pandas, scikit-learn, TensorFlow/Keras or PyTorch, Streamlit, geospatial libs.
- (Optional) External tile server/APIs for map backgrounds.

##### Component Interactions & Data Flow
1. User opens the Streamlit UI (app.py).
2. User inputs vessel navigational features via forms.
3. app.py calls functions in model.py:
- Data cleaning & feature generation
- Pass features to Isolation Forest and Autoencoder
4. model.py returns a prediction (normal vs. anomalous).
5. app.py:
- Renders geospatial map with vessel point + ports layer.
- Displays prediction labels and metrics.
- Appends a new row (input features + prediction + timestamp) to prediction_log.csv.

##### Architectural Patterns & Design Principles
- Separation of Concerns: UI (app.py) vs. ML logic (model.py) vs. persistent storage (CSV files).
- Modular Design: model.py encapsulates all preprocessing + model code; easy to swap or extend models.
- Data Logging: Immutable log file for audit trail of predictions.

##### Final Checklist
- Clear, descriptive labels on all components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["app.py (Streamlit UI)"]:::frontend
    end

    %% Business Logic / ML Engine
    subgraph "Business Logic / ML Engine"
        ML["model.py (Preprocess + IsolationForest + Autoencoder)"]:::compute
    end

    %% Data Layer
    subgraph "Data Layer"
        AIS["dataset/ais_data.csv"]:::storage
        ILLEGAL["dataset/illegal_Data.txt"]:::storage
        LOG["prediction_log.csv"]:::storage
    end

    %% External Services
    subgraph "External Services"
        External["Map Tile Service"]:::external
    end

    %% Data Flow
    UI -->|"feature vector"| ML
    AIS -->|"historical data"| ML
    ILLEGAL -->|"illegal records"| ML
    ML -->|"prediction + metadata"| UI
    UI -->|"new log entry"| LOG
    UI -->|"map tile request"| External
    External -->|"tile data"| UI

    %% Click Events
    click UI "https://github.com/abhij1401/ais-illegal-fishing-detection/blob/main/app.py"
    click ML "https://github.com/abhij1401/ais-illegal-fishing-detection/blob/main/model.py"
    click AIS "https://github.com/abhij1401/ais-illegal-fishing-detection/blob/main/dataset/ais_data.csv"
    click ILLEGAL "https://github.com/abhij1401/ais-illegal-fishing-detection/blob/main/dataset/illegal_Data.txt"
    click LOG "https://github.com/abhij1401/ais-illegal-fishing-detection/blob/main/prediction_log.csv"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef compute fill:#90EE90,stroke:#333,stroke-width:1px
    classDef storage fill:#FFA500,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
