# hitranonline/hapi2 architecture

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

- Interactive diagram: https://gitdiagram.com/hitranonline/hapi2
- Repository: https://github.com/hitranonline/hapi2

## Overview

##### Main Components

a) Core System Components:
- Data Access Layer
- Web API Client (hapi2/web/)
- Database Layer (hapi2/db/)
- SQLAlchemy ORM Integration

b) Processing Components:
- Collection Module (hapi2/collect/)
- Format Handlers (hapi2/format/)
- Opacity Calculators (hapi2/opacity/)

c) Supporting Components:
- Configuration System (hapi2/config/)
- Provenance Tracking (hapi2/provenance/)
- Utility Functions (hapi2/utils/)

**[External Systems Layer]**
- HITRANonline Web Server
- External Databases (MySQL/SQLite)
- ↕
**[Interface Layer]**
- REST API Client
- Database Connectors
- ↕
**[Core Processing Layer]**
- Data Collection
- Format Processing
- Opacity Calculations
- ↕
**[Infrastructure Layer]**
- Configuration
- Provenance
- Utilities

##### Key Relationships to Highlight

a) Data Flow:
- How data moves from HITRANonline through the REST API
- Database storage and retrieval paths
- Demonstrate calculation pipeline flow

b) Component Integration:
- Format handlers with opacity calculators
- Configuration influence on all components
- Provenance tracking across operations

##### Special Architectural Elements

a) Modular Plugin System:
- Extension points for custom plugins
- Plugin interfaces for:
- LBL calculation plugins
- SQLAlchemy backends
- Format handlers

b) Performance Optimizations:
- Numba JIT compilation components
- Parallel processing paths

##### Technical Details

- SQLAlchemy ORM integration
- Numba-accelerated calculations
- REST API v2 endpoints
- Supported database backends (MySQL, SQLite)
- Cache mechanisms
- Configuration management

##### Implementation Notes

- Use standard UML notation where appropriate
- Version information (HAPI2 v0.1)
- Database schema relationships
- Async/sync operations
- JIT-compiled components

##### Integration with external systems

Keep the abstraction level high enough to show the overall architecture while including sufficient detail to understand the system's operation and extension points.

This design should reflect HAPI2's role as a scientific computing library with emphasis on performance, extensibility, and data management capabilities.

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Systems Layer
    subgraph External
        HITRAN[HITRANonline Web Server]
        ExtDB[(External Databases)]
    end

    %% Interface Layer
    subgraph Interface
        WebAPI["REST API Client"]:::api
        DBConn["Database Connectors"]:::db
        SQLAlchemy["SQLAlchemy ORM"]:::db
        MySQL["MySQL Backend"]:::db
        SQLite["SQLite Backend"]:::db
        Models["Database Models"]:::db
    end

    %% Core Processing Layer
    subgraph Processing
        Collection["Data Collection"]:::core
        Format["Format Handlers"]:::core
        HITRANFormat["HITRAN Format"]:::core
        StreamFormat["Streaming Format"]:::core
        
        subgraph Calculations
            Opacity["Opacity Calculators"]:::calc
            LBL["Line-by-line"]:::calc
            XSC["Cross-section"]:::calc
            CIA["CIA"]:::calc
            Numba["Numba JIT"]:::perf
        end
    end

    %% Infrastructure Layer
    subgraph Infrastructure
        Config["Configuration"]:::infra
        Provenance["Provenance Tracking"]:::infra
        Utils["Utilities"]:::infra
        Profiling["Performance Profiling"]:::infra
    end

    %% Relationships
    HITRAN --> WebAPI
    WebAPI --> Collection
    ExtDB --> DBConn
    DBConn --> SQLAlchemy
    SQLAlchemy --> |Backend| MySQL
    SQLAlchemy --> |Backend| SQLite
    SQLAlchemy --> Models
    
    Collection --> Format
    Format --> HITRANFormat
    Format --> StreamFormat
    
    Format --> Opacity
    Opacity --> LBL
    Opacity --> XSC
    Opacity --> CIA
    LBL --> Numba
    
    Config --> Processing
    Config --> Interface
    Provenance --> Processing
    Utils --> Processing
    Profiling --> Calculations

    %% Click Events
    click WebAPI "https://github.com/hitranonline/hapi2/blob/master/hapi2/web/api.py"
    click DBConn "https://github.com/hitranonline/hapi2/tree/master/hapi2/db/"
    click SQLAlchemy "https://github.com/hitranonline/hapi2/tree/master/hapi2/db/sqlalchemy/"
    click MySQL "https://github.com/hitranonline/hapi2/tree/master/hapi2/db/sqlalchemy/mysql/"
    click SQLite "https://github.com/hitranonline/hapi2/tree/master/hapi2/db/sqlalchemy/sqlite/"
    click Collection "https://github.com/hitranonline/hapi2/tree/master/hapi2/collect/"
    click Format "https://github.com/hitranonline/hapi2/tree/master/hapi2/format/"
    click HITRANFormat "https://github.com/hitranonline/hapi2/tree/master/hapi2/format/hitran/"
    click StreamFormat "https://github.com/hitranonline/hapi2/tree/master/hapi2/format/streamers/"
    click Opacity "https://github.com/hitranonline/hapi2/tree/master/hapi2/opacity/"
    click LBL "https://github.com/hitranonline/hapi2/tree/master/hapi2/opacity/lbl/"
    click Numba "https://github.com/hitranonline/hapi2/tree/master/hapi2/opacity/lbl/numba/"
    click Config "https://github.com/hitranonline/hapi2/blob/master/hapi2/config/config.py"
    click Provenance "https://github.com/hitranonline/hapi2/tree/master/hapi2/provenance/"
    click Utils "https://github.com/hitranonline/hapi2/tree/master/hapi2/utils/"
    click Profiling "https://github.com/hitranonline/hapi2/tree/master/hapi2/profiling/"
    click Models "https://github.com/hitranonline/hapi2/blob/master/hapi2/db/models.py"
    click XSC "https://github.com/hitranonline/hapi2/tree/master/hapi2/opacity/xsc/"
    click CIA "https://github.com/hitranonline/hapi2/tree/master/hapi2/opacity/cia/"

    %% Styles
    classDef api fill:#2374ab
    classDef db fill:#ffb703
    classDef core fill:#52b788
    classDef calc fill:#38b000
    classDef perf fill:#d00000
    classDef infra fill:#6c757d
```
