# apdn7/analysisplatform architecture

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

- Interactive diagram: https://gitdiagram.com/apdn7/analysisplatform
- Repository: https://github.com/apdn7/analysisplatform

## Overview

##### Main components
- User’s Browser (UI Layer)
– Static assets (CSS/JS under ap/static)
– HTML templates (Jinja2 under ap/templates)
– Third-party JS libs (Plotly, D3, Sigma.js, jQuery, etc.)
- Web Server (Flask App)
– Entry point: main.py, config.py, startup scripts
– Blueprint modules:
- ap/api/*: REST controllers + services supplying JSON endpoints for each visualization (aggregate_plot, analyze, heatmap, etc.)
- ap/[aggregate_plot|analyze|…]/*: server-side controllers & business logic for rendering pages and data processing
- ap/common: shared utilities (DB connectors in pydn/dblib, caching, logging, scheduling, SSE, error handling)
- ap/etl: pull & transform pipelines for data ingestion
- ap/script: one-off scripts (migration, setup, R-process calls, etc.)
- ap/setting_module: configuration UIs & services, backup/restore jobs
- background jobs scheduler (ap/common/jobs + ap/common/scheduler)
- translations (ap/translations) for i18n
- Database Layer
– Local SQLite instance (init/app.sqlite3) or external DBs via pydn/dblib (MySQL, PostgreSQL, SQL Server, Oracle, Snowflake)
– Schema migrations via Alembic (migrations/)
- External Services
– Factory data sources: CSV/TSV files, external databases
– Oracle Instant Client (optional), network-accessible DB servers
- Background/Batch Layer
– Scheduled ETL jobs (ap/etl invoked by scheduler)
– Long-running tasks (backup/restore, polling frequency)
- Configuration/Deployment
– startup.ini, basic_config.yml, tile_interface_analysis_platform.yml, other tile_interface configs
– start_ap.bat / start_ap.py: installer & embeddable Python bootstrap

##### Relationships and data flows
– Browser → HTTP GET/POST → Flask controllers (ap/api & ap/*/controllers)
– Controllers → Business services (ap/api/*/services.py, ap/*/services)
– Services → Common utilities and DB connectors (ap/common, pydn/dblib)
– DB connectors → Database (SQLite or remote)
– Responses → JSON or rendered HTML → Browser (JS charts consumed by static assets)
– Scheduler → ETL pipelines → Database
– Scripts (ap/script) → one-time DB or config migrations

##### Architectural patterns
– Layered MVC-style:
- Controllers (request routing)
- Services (business logic)
- Data access (common/db layer)
– Modular “plugin” structure per visualization type under both ap/api and ap/
– Shared ‘common’ library for cross-cutting concerns (caching, logging, errors)
– Background job scheduling decoupled from request cycle
– Configuration-driven UI (tile interfaces defined in YAML + templates)

##### Relevant technologies
– Python 3.6+ with Flask & Jinja2
– Alembic for migrations
– pydn/dblib for multi-DB support
– JavaScript: Plotly, D3, Sigma.js, jQuery, Select2, etc.
– CSS frameworks & custom styles for each plot
– SSE for real-time updates

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% UI Layer
  subgraph "UI Layer"
    Browser["User's Browser"]:::ui
    Static["Static Assets"]:::ui
    Templates["HTML Templates"]:::ui
    ThirdParty["3rd-Party JS Libs"]:::ui
  end

  %% Web Server Layer
  subgraph "Web Server (Flask App)"
    Entry["main.py"]:::flask
    ConfigPy["config.py"]:::flask
    BasicYML["basic_config.yml"]:::flask
    TileYML["tile_interface_analysis_platform.yml"]:::flask

    subgraph "Blueprints"
      subgraph "API Layer"
        API["ap/api"]:::flask
        AggAPICTR["aggregate_plot/controllers.py"]:::flask
        AggAPISVC["aggregate_plot/services.py"]:::flask
        AnalyzeCTR["analyze/controllers.py"]:::flask
        AnalyzeSVC["analyze/services/pca.py"]:::flask
        CalCTR["calendar_heatmap/controllers.py"]:::flask
        CalSVC["calendar_heatmap/services.py"]:::flask
        CatCTR["categorical_plot/controllers.py"]:::flask
        CatSVC["categorical_plot/services.py"]:::flask
        CoCTR["co_occurrence/controllers.py"]:::flask
        CoSVC["co_occurrence/services.py"]:::flask
        APICOMCTR["common/controllers.py"]:::flask
        APICOMSVC["common/services"]:::flask
        SettingAPICTR["setting_module/controllers.py"]:::flask
        SettingAPISVC["setting_module/services"]:::flask
      end

      subgraph "Page Controllers & Business Logic"
        PageAggCTR["aggregate_plot/controllers.py"]:::flask
        PageAggUtils["aggregate_plot/services/utils.py"]:::flask
        PageAnalyzeCTR["analyze/controllers.py"]:::flask
        PageAnalyzeSensor["analyze/services/sensor_list.py"]:::flask
        SettingUICtr["setting_module/controllers.py"]:::flask
        SettingUISvc["setting_module/services"]:::flask
      end

      Translations["ap/translations"]:::flask
    end

    Common["ap/common"]:::common
    DBLib["pydn/dblib"]:::common

    JobsScheduler["ap/common/jobs/scheduler.py"]:::jobs
    JobsList["ap/common/jobs/jobs.py"]:::jobs
    ETLPull["ap/etl/pull"]:::jobs
    ETLTransform["ap/etl/transform"]:::jobs
    Scripts["ap/script"]:::jobs

    StartBAT["start_ap.bat"]:::jobs
    StartPY["start_ap.py"]:::jobs
  end

  %% Database Layer
  subgraph "Database Layer"
    SQLite["init/app.sqlite3"]:::db
    Migrations["migrations/"]:::db
  end

  %% External Services
  subgraph "External Services"
    FactoryFiles["data_files"]:::external
    ExternalDB["External DB Servers"]:::external
    SampleData["data_files"]:::external
  end

  %% Relationships
  Browser --> Static
  Browser --> Templates
  Browser --> ThirdParty
  Browser -->|"HTTP GET/POST"| API
  Browser -->|"HTTP GET/POST"| PageAggCTR
  Browser -->|"HTTP GET/POST"| PageAnalyzeCTR

  API --> AggAPICTR
  API --> AnalyzeCTR
  API --> CalCTR
  API --> CatCTR
  API --> CoCTR
  API --> APICOMCTR
  API --> SettingAPICTR

  AggAPICTR --> AggAPISVC
  AnalyzeCTR --> AnalyzeSVC
  CalCTR --> CalSVC
  CatCTR --> CatSVC
  CoCTR --> CoSVC
  APICOMCTR --> APICOMSVC
  SettingAPICTR --> SettingAPISVC

  PageAggCTR --> PageAggUtils
  PageAnalyzeCTR --> PageAnalyzeSensor
  SettingUICtr --> SettingUISvc

  AggAPISVC --> Common
  AnalyzeSVC --> Common
  CalSVC --> Common
  CatSVC --> Common
  CoSVC --> Common
  APICOMSVC --> Common
  SettingAPISVC --> Common

  PageAggUtils --> Common
  PageAnalyzeSensor --> Common
  SettingUISvc --> Common

  Common --> DBLib
  DBLib --> SQLite
  DBLib --> ExternalDB

  ETLPull --> ETLTransform
  JobsScheduler --> ETLPull
  JobsScheduler --> Scripts
  JobsScheduler --> StartBAT
  JobsScheduler --> StartPY
  ETLTransform --> DBLib
  Scripts --> DBLib

  ExternalDB --> DBLib
  FactoryFiles --> ETLPull
  SampleData --> ETLPull

  %% Click Events
  click Static "https://github.com/apdn7/analysisplatform/tree/master/ap/static"
  click Templates "https://github.com/apdn7/analysisplatform/tree/master/ap/templates"
  click ThirdParty "https://github.com/apdn7/analysisplatform/tree/master/ap/static/modules"
  click Entry "https://github.com/apdn7/analysisplatform/blob/master/main.py"
  click ConfigPy "https://github.com/apdn7/analysisplatform/blob/master/config.py"
  click BasicYML "https://github.com/apdn7/analysisplatform/blob/master/ap/config/basic_config.yml"
  click TileYML "https://github.com/apdn7/analysisplatform/blob/master/ap/config/tile_interface_analysis_platform.yml"
  click StartBAT "https://github.com/apdn7/analysisplatform/blob/master/start_ap.bat"
  click StartPY "https://github.com/apdn7/analysisplatform/blob/master/ap/start_ap.py"
  click API "https://github.com/apdn7/analysisplatform/tree/master/ap/api"
  click AggAPICTR "https://github.com/apdn7/analysisplatform/blob/master/ap/api/aggregate_plot/controllers.py"
  click AggAPISVC "https://github.com/apdn7/analysisplatform/blob/master/ap/api/aggregate_plot/services.py"
  click AnalyzeCTR "https://github.com/apdn7/analysisplatform/blob/master/ap/api/analyze/controllers.py"
  click AnalyzeSVC "https://github.com/apdn7/analysisplatform/blob/master/ap/api/analyze/services/pca.py"
  click CalCTR "https://github.com/apdn7/analysisplatform/blob/master/ap/api/calendar_heatmap/controllers.py"
  click CalSVC "https://github.com/apdn7/analysisplatform/blob/master/ap/api/calendar_heatmap/services.py"
  click CatCTR "https://github.com/apdn7/analysisplatform/blob/master/ap/api/categorical_plot/controllers.py"
  click CatSVC "https://github.com/apdn7/analysisplatform/blob/master/ap/api/categorical_plot/services.py"
  click CoCTR "https://github.com/apdn7/analysisplatform/blob/master/ap/api/co_occurrence/controllers.py"
  click CoSVC "https://github.com/apdn7/analysisplatform/blob/master/ap/api/co_occurrence/services.py"
  click APICOMCTR "https://github.com/apdn7/analysisplatform/blob/master/ap/api/common/controlllers.py"
  click APICOMSVC "https://github.com/apdn7/analysisplatform/tree/master/ap/api/common/services"
  click PageAggCTR "https://github.com/apdn7/analysisplatform/blob/master/ap/aggregate_plot/controllers.py"
  click PageAggUtils "https://github.com/apdn7/analysisplatform/blob/master/ap/aggregate_plot/services/utils.py"
  click PageAnalyzeCTR "https://github.com/apdn7/analysisplatform/blob/master/ap/analyze/controllers.py"
  click PageAnalyzeSensor "https://github.com/apdn7/analysisplatform/blob/master/ap/analyze/services/sensor_list.py"
  click Translations "https://github.com/apdn7/analysisplatform/tree/master/ap/translations"
  click Common "https://github.com/apdn7/analysisplatform/tree/master/ap/common"
  click DBLib "https://github.com/apdn7/analysisplatform/tree/master/ap/common/pydn/dblib"
  click JobsScheduler "https://github.com/apdn7/analysisplatform/blob/master/ap/common/jobs/scheduler.py"
  click JobsList "https://github.com/apdn7/analysisplatform/blob/master/ap/common/jobs/jobs.py"
  click ETLPull "https://github.com/apdn7/analysisplatform/tree/master/ap/etl/pull"
  click ETLTransform "https://github.com/apdn7/analysisplatform/tree/master/ap/etl/transform"
  click Scripts "https://github.com/apdn7/analysisplatform/tree/master/ap/script"
  click SettingUICtr "https://github.com/apdn7/analysisplatform/blob/master/ap/setting_module/controllers.py"
  click SettingUISvc "https://github.com/apdn7/analysisplatform/tree/master/ap/setting_module/services"
  click SettingAPICTR "https://github.com/apdn7/analysisplatform/blob/master/ap/api/setting_module/controllers.py"
  click SettingAPISVC "https://github.com/apdn7/analysisplatform/tree/master/ap/api/setting_module/services"
  click SQLite "https://github.com/apdn7/analysisplatform/blob/master/init/app.sqlite3"
  click Migrations "https://github.com/apdn7/analysisplatform/tree/master/migrations/"
  click SampleData "https://github.com/apdn7/analysisplatform/tree/master/data_files"

  %% Styles
  classDef ui fill:#AED6F1,stroke:#21618C,color:#1B2631
  classDef flask fill:#A9DFBF,stroke:#196F3D,color:#1B2631
  classDef common fill:#F9E79F,stroke:#B9770E,color:#1B2631
  classDef db fill:#D2B4DE,stroke:#6C3483,color:#1B2631
  classDef jobs fill:#D5DBDB,stroke:#626567,color:#1B2631
  classDef external fill:#E5E7E9,stroke:#424949,color:#1B2631
```
