# cerema/agirisk architecture

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

- Interactive diagram: https://gitdiagram.com/cerema/agirisk
- Repository: https://github.com/cerema/agirisk

## Overview

##### And represent the main components
- QGIS Integration Layer:
– Represent the plugin initialization and QGIS integration files (e.g., “agirisk.py”, “agirisk_dialog.py”, “ui_agirisk_dialog_base.py”, and “agirisk_dialog_base.ui”).
– Show how these components hook into the QGIS interface.
- Business Logic Layer:
– Represent the “classes” directory components (e.g., “Bdd.py”, “Dashboard.py”, “ModeleTerritorial.py”, “Cards.py”, “ArborescenceActions.py”, “ArborescenceIndicateurs.py”, etc.).
– These provide the core functionality and processing routines including data handling, UI dashboard management (with QML files), and territorial modeling.
- Resource and Configuration Layer:
– Also note “metadata.txt” and other static configuration files that control appearance and parameters.
- Database and SQL Management Layer:
– Highlight classes and scripts managing database interactions (the “Bdd.py” class and numerous SQL scripts under “scripts/export_sql” and “scripts/init_table_niv_zoom”).
– Show the dependency on SQL scripts (including partitioning and base initialization) for setting up, exporting, and maintaining the database schema.
- Supporting Scripts and Installation Tools:
– Differentiate the “scripts” folder which includes:
- Creation of arborescences (e.g., “scripts/creation_arborescences”).
- SQL dump helpers (“scripts/dump_sql” and “scripts/export_sql”).
- Installation and initialization scripts (“scripts/installation”) that help deploy the plugin’s backend environment.

##### Relationships and interactions
- The QGIS Integration Layer (plugin interface and dialogs) triggers interactions with the Business Logic Layer.
- The Business Logic Layer handles core processing (e.g., loading configurations, applying flood vulnerability computations) and communicates with the Database Layer for data persistence and queries.
- The Database Layer relies on extensive SQL and initialization scripts. This layer is maintained separately via administration tools provided in the “scripts/export_sql” and “scripts/init_table_niv_zoom” directories.
- The Resource and Configuration Layer supplies styling, thematic mapping (via QML), and various JSON configuration files that are loaded by both the UI components and business logic.
- Supporting Scripts interact with all layers during installation, upgrade, or migration processes, ensuring correct database schema setups and updated configuration distribution.

##### Architectural patterns and design principles
- Separation of concerns is clear: the UI (QGIS plugin specifics) is isolated from business logic and data persistence concerns.
- Modularity: The structure separates core processing, resource handling, and administrative scripts into distinct directories.
- Extensibility: The extensive resource files and configuration JSONs indicate that the plugin’s appearance and behavior are data-driven, allowing easier customizations.
- Deployment automation: The inclusion of numerous installation and SQL export scripts shows a clear emphasis on automating the setup of both the plugin’s interface and back-end database systems.

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "Presentation/UI Layer"
        qgis_entry["Plugin Entry (agirisk.py)"]:::uiLayer
        qgis_dialog["Dialog Logic (agirisk_dialog.py)"]:::uiLayer
        qgis_ui_base["UI Base (ui_agirisk_dialog_base.py)"]:::uiLayer
        qgis_dialog_ui["Dialog UI (agirisk_dialog_base.ui)"]:::uiLayer
    end

    subgraph "Application Logic Layer"
        logic_db_connector["Database Connector (Bdd.py)"]:::logicLayer
        logic_dashboard["Dashboard (Dashboard.py)"]:::logicLayer
        logic_modele["Territorial Model (ModeleTerritorial.py)"]:::logicLayer
        logic_cards["Card Manager (Cards.py)"]:::logicLayer
        logic_actions["Action Arborescence (ArborescenceActions.py)"]:::logicLayer
        logic_indicators["Indicator Arborescence (ArborescenceIndicateurs.py)"]:::logicLayer
        logic_qml["Dashboard QML (dashboard.qml & dashboard.qmlc)"]:::logicLayer
        logic_messages["User Messages (messages_utilisateur.py)"]:::logicLayer
    end

    subgraph "Resource/Configuration Layer"
        resource_medias["Media Assets"]:::resourceLayer
        resource_ressources["Ressources Directory"]:::resourceLayer
        resource_metadata["Metadata (metadata.txt)"]:::resourceLayer
        resource_defs["Resource Definitions"]:::resourceLayer
        resource_config["Config JSON (config.json)"]:::resourceLayer
        resource_flood["Flood Config (actions_inondations_ANRN.json)"]:::resourceLayer
    end

    subgraph "Database/SQL Management Layer"
        db_export["SQL Export Scripts"]:::dbLayer
        db_init["SQL Initialization Scripts"]:::dbLayer
    end

    subgraph "Supporting Scripts Layer"
        script_arbo["Arborescence Creation"]:::scriptLayer
        script_dump["SQL Dump Helper"]:::scriptLayer
        script_install["Installation Tools"]:::scriptLayer
        script_db_fields["DB Field Types"]:::scriptLayer
    end

    %% Relationships from Presentation/UI Layer to Application Logic Layer
    qgis_entry -->|"triggers"| logic_db_connector
    qgis_dialog -->|"triggers"| logic_dashboard
    qgis_ui_base -->|"integrates"| logic_messages
    qgis_dialog_ui -->|"renders"| logic_qml

    %% Relationships within Application Logic Layer to Resource/Configuration Layer
    logic_qml -->|"loads"| resource_defs
    logic_dashboard -->|"loads"| resource_config
    logic_cards -->|"appliesStyles"| resource_ressources
    logic_messages -->|"displaysUsing"| resource_flood

    %% Relationships from Application Logic Layer to Database/SQL Management Layer
    logic_db_connector -->|"executesSQL"| db_export
    logic_db_connector -->|"executesSQL"| db_init

    %% Relationships from Supporting Scripts Layer to Database/SQL Management and Resource Layer
    script_install -->|"deploys"| db_init
    script_install -->|"deploys"| resource_metadata
    script_arbo -->|"generates"| resource_ressources
    script_dump -->|"assists"| db_export
    script_db_fields -->|"retrieves"| db_init
    script_install -->|"initializes"| logic_db_connector

    %% Style Definitions
    classDef uiLayer fill:#FFCCCC,stroke:#333,stroke-width:2px;
    classDef logicLayer fill:#CCE5FF,stroke:#333,stroke-width:2px;
    classDef resourceLayer fill:#E6CCFF,stroke:#333,stroke-width:2px;
    classDef dbLayer fill:#CCFFCC,stroke:#333,stroke-width:2px;
    classDef scriptLayer fill:#FFFFCC,stroke:#333,stroke-width:2px;

    %% Click Events - Presentation/UI Layer
    click qgis_entry "https://github.com/cerema/agirisk/blob/master/agirisk.py"
    click qgis_dialog "https://github.com/cerema/agirisk/blob/master/agirisk_dialog.py"
    click qgis_ui_base "https://github.com/cerema/agirisk/blob/master/ui_agirisk_dialog_base.py"
    click qgis_dialog_ui "https://github.com/cerema/agirisk/blob/master/agirisk_dialog_base.ui"

    %% Click Events - Application Logic Layer
    click logic_db_connector "https://github.com/cerema/agirisk/blob/master/classes/Bdd.py"
    click logic_dashboard "https://github.com/cerema/agirisk/blob/master/classes/Dashboard.py"
    click logic_modele "https://github.com/cerema/agirisk/blob/master/classes/ModeleTerritorial.py"
    click logic_cards "https://github.com/cerema/agirisk/blob/master/classes/Cards.py"
    click logic_actions "https://github.com/cerema/agirisk/blob/master/classes/ArborescenceActions.py"
    click logic_indicators "https://github.com/cerema/agirisk/blob/master/classes/ArborescenceIndicateurs.py"
    click logic_qml "https://github.com/cerema/agirisk/blob/master/classes/dashboard.qml"
    click logic_messages "https://github.com/cerema/agirisk/blob/master/classes/messages_utilisateur.py"

    %% Click Events - Resource/Configuration Layer
    click resource_medias "https://github.com/cerema/agirisk/tree/master/medias"
    click resource_ressources "https://github.com/cerema/agirisk/tree/master/ressources"
    click resource_metadata "https://github.com/cerema/agirisk/blob/master/metadata.txt"
    click resource_defs "https://github.com/cerema/agirisk/blob/master/resources.py"
    click resource_config "https://github.com/cerema/agirisk/blob/master/ressources/config.json"
    click resource_flood "https://github.com/cerema/agirisk/blob/master/ressources/actions_inondations_ANRN.json"

    %% Click Events - Database/SQL Management Layer
    click db_export "https://github.com/cerema/agirisk/tree/master/scripts/export_sql"
    click db_init "https://github.com/cerema/agirisk/tree/master/scripts/init_table_niv_zoom"

    %% Click Events - Supporting Scripts Layer
    click script_arbo "https://github.com/cerema/agirisk/tree/master/scripts/creation_arborescences"
    click script_dump "https://github.com/cerema/agirisk/tree/master/scripts/dump_sql"
    click script_install "https://github.com/cerema/agirisk/tree/master/scripts/installation"
    click script_db_fields "https://github.com/cerema/agirisk/tree/master/scripts/recup_champs_types_bdd"
```
