# tasmirz/terra architecture

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

- Interactive diagram: https://gitdiagram.com/tasmirz/terra
- Repository: https://github.com/tasmirz/terra

## Overview

The system architecture should be represented as follows:

##### Main Components

a. Frontend Layer:
- Mobile/Web Application (SpaceApp directory)
- Built with Cordova for cross-platform support
- Features: Map visualization, data submission interface, user authentication
- OpenLayers (ol.js) for map rendering

b. Backend Services (3 main servers):
- Submission Backend Server
- Handles user authentication
- Processes data submissions
- Manages help requests
- Handles image uploads
- Query Backend Server
- Serves map data
- Provides data visualization endpoints
- Handles leaderboard functionality
- Cronjob Server
- Processes data every 6 hours
- Emergency data processing every 10 minutes
- Generates cached data formats

c. Database Layer:
- MongoDB instance
- Stores:
- User data
- Submission data
- Geospatial information
- Emergency requests

d. Data Processing Pipeline:
- Machine Learning Model integration
- Data transformation services
- GeoJSON/CSV export functionality

##### Relationships and Data Flow

- User interactions → Frontend → Submission Backend
- Frontend ← Query Backend ← Processed Data
- Cronjob Server ↔ Database
- Data Processing Pipeline → Database
- Authentication flow between components

##### Technical Stack Indicators

- Node.js v16.10.0
- MongoDB
- Python (ML components)
- Cordova
- OpenLayers
- TensorFlow

##### Additional Elements

Specialized zones for:
- Data export functionality
- Leaderboard system
- Image storage
- Emergency response handling
- Government bulk data submission

Keep the focus on the real-time nature of the emergency reporting system while showing how the periodic data processing (6-hour cycles) integrates with the main system.

This architecture should be represented as a combination of a high-level system overview with detailed subsystem breakdowns where necessary, especially for the critical emergency response and data processing components.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Frontend
        MA[Mobile/Web App]:::frontend
        MAP[Map Visualization]:::frontend
        UI[User Interface]:::frontend
        API[API Interface]:::frontend
        OL[OpenLayers]:::frontend
    end

    subgraph "Backend Services"
        direction TB
        subgraph "Submission Backend"
            SB[Submission Server]:::backend
            UA[User Authentication]:::backend
            DS[Data Submission]:::backend
            HR[Help Requests]:::backend
        end

        subgraph "Query Backend"
            QB[Query Server]:::backend
            LB[Leaderboard]:::backend
            DV[Data Visualization]:::backend
        end

        subgraph "Cronjob Server"
            CJ[Cronjob Main]:::backend
            DP[Data Processing]:::backend
            GG[GeoJSON Generator]:::backend
        end
    end

    subgraph "Database Layer"
        DB[(MongoDB)]:::database
        IMG[Image Storage]:::database
        CSV[CSV Storage]:::database
    end

    subgraph "Data Processing Pipeline"
        ML[ML Model]:::processing
        TM[Training Model]:::processing
        DC[Data Collection]:::processing
    end

    %% Relationships
    MA --> MAP
    MA --> UI
    MA --> API
    MAP --> OL

    API --> SB
    UI --> UA
    UA --> DB
    DS --> DB
    HR --> DB

    QB --> DV
    QB --> LB
    DV --> DB
    LB --> DB

    CJ --> DP
    DP --> GG
    GG --> DB

    DB --> IMG
    DB --> CSV

    DC --> ML
    ML --> TM
    TM --> DB

    %% Click Events
    click MA "https://github.com/tasmirz/Terra/tree/master/SpaceApp/www/"
    click MAP "https://github.com/tasmirz/Terra/blob/master/SpaceApp/www/js/map_display.js"
    click API "https://github.com/tasmirz/Terra/blob/master/SpaceApp/www/js/api_calls.js"
    click UI "https://github.com/tasmirz/Terra/blob/master/SpaceApp/www/js/ux.js"
    click OL "https://github.com/tasmirz/Terra/blob/master/SpaceApp/www/lib/ol.js"
    
    click SB "https://github.com/tasmirz/Terra/tree/master/Server/submission-backend/"
    click UA "https://github.com/tasmirz/Terra/blob/master/Server/submission-backend/login.js"
    click DS "https://github.com/tasmirz/Terra/blob/master/Server/submission-backend/native_submit.js"
    click HR "https://github.com/tasmirz/Terra/blob/master/Server/submission-backend/handle_help.js"
    
    click QB "https://github.com/tasmirz/Terra/tree/master/Server/query-backend/"
    click LB "https://github.com/tasmirz/Terra/blob/master/Server/query-backend/leaderboard.js"
    click DV "https://github.com/tasmirz/Terra/blob/master/Server/query-backend/ls_details.js"
    
    click CJ "https://github.com/tasmirz/Terra/blob/master/Server/cronjob/main.js"
    click GG "https://github.com/tasmirz/Terra/blob/master/Server/cronjob/geo_dlrd_full.mjs"
    
    click DB "https://github.com/tasmirz/Terra/tree/master/Database/"
    click CSV "https://github.com/tasmirz/Terra/tree/master/Database/csv_data/"
    click IMG "https://github.com/tasmirz/Terra/tree/master/Database/img/"
    
    click ML "https://github.com/tasmirz/Terra/blob/master/Analysis/ML_model.md"
    click TM "https://github.com/tasmirz/Terra/blob/master/Analysis/Second-level/training model.md"
    click DC "https://github.com/tasmirz/Terra/blob/master/Analysis/Second-level/Data Collection server.md"

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef processing fill:#9b59b6,stroke:#8e44ad,color:white

    %% Legend
    subgraph Legend
        F[Frontend]:::frontend
        B[Backend]:::backend
        D[(Database)]:::database
        P[Processing]:::processing
    end
```
