# fortran-lang/stdlib architecture

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

- Interactive diagram: https://gitdiagram.com/fortran-lang/stdlib
- Repository: https://github.com/fortran-lang/stdlib

## Overview

##### Main Components
- Preprocessing and Meta-programming: The project uses “fypp” – a Python-based preprocessor – to generate Fortran source files from templates. Include a component representing the preprocessing stage (scripts in the “config” directory, such as fypp_deployment.py).
- Build Systems and Configurations: The project supports CMake and Fortran Package Manager (fpm) as build systems. Mark components for CMake (CMakeLists.txt files in various directories, configuration options, installation scripts) and for fpm (fpm.toml and related branches).
- Documentation and Specification: There’s a “doc” directory and README that provide the API documentation and specifications. This is crucial for understanding the library’s intended functionalities.
- Testing and Examples: The “test” and “example” directories hold a large set of test suites and sample applications demonstrating usage of individual modules (such as examples for arrays, math routines, IO, sorting, etc.). Represent these as components interacting with the main library.
- Continuous Integration & Project Infrastructure: The “.github” directory shows CI workflows and issue templates along with community guidelines (e.g., CONTRIBUTING, CODE_OF_CONDUCT) that help maintain quality and standards.

##### Relationships and Interactions
- Dependency Flow: Indicate that tests (in “test”) and examples (in “example”) depend on the compiled stdlib library from the “src” and “include” directories.

##### Architectural Patterns and Design Principles
- Modular Design: The source code is partitioned into clear functional modules (e.g., blas, lapack, io, math, etc.). Emphasize the modular architecture.

##### Relevant Technologies, Frameworks, and Libraries
- Fortran (with Fortran 2008/2018 compliance) as the primary language.
- fypp – the preprocessing tool used for meta-programming.
- CMake – the primary build system, along with its configuration in various CMakeLists.txt files.
- fpm (Fortran Package Manager) – an alternative build and dependency management system.
- GitHub Actions – represented by the CI workflows in “.github/workflows.”
- External dependencies (like BLAS and LAPACK libraries) optionally configure the build if certain macros are defined.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Source and Preprocessing Layer"
        SRC["src - Core Modules"]:::core
        FYPP["fypp Preprocessor"]:::preproc
        BCONFIG["Build Config (config/CMakeLists.txt)"]:::conf
        SRC -->|"source"| FYPP
        BCONFIG -.-> FYPP
    end

    subgraph "Build Systems"
        CMAKE["CMake Build System"]:::build
        CMK_EXTRA["CMake Extra (cmake/stdlib.cmake)"]:::build
        FPM["fpm Build System"]:::build
        FYPP --> CMAKE
        FYPP --> FPM
        BCONFIG --> CMAKE
        BCONFIG --> FPM
        CMAKE --- CMK_EXTRA
    end

    COMPILED["Compiled stdlib Library"]:::compiled
    CMAKE --> COMPILED
    FPM --> COMPILED

    subgraph "Integration & Usage"
        TESTS["Tests (test)"]:::test
        EXAMPLES["Examples (example)"]:::example
        COMPILED --> TESTS
        COMPILED --> EXAMPLES
    end

    COMPILED --> DOC_PARENT["Documentation"]:::docGroup
    CI["CI/CD Infrastructure (.github)"]:::ci
    CI --> COMPILED

    SRC -->|"optional linking"| EXTLIB["External Libraries (BLAS/LAPACK)"]:::ext

    subgraph "Documentation"
        DOC_DIR["doc - Documentation Directory"]:::doc
        README["README.md"]:::doc
        FORD["API-doc-FORD-file.md"]:::doc
    end

    %% Click Events
    click SRC "https://github.com/fortran-lang/stdlib/tree/master/src"
    click FYPP "https://github.com/fortran-lang/stdlib/blob/master/config/fypp_deployment.py"
    click BCONFIG "https://github.com/fortran-lang/stdlib/blob/master/config/CMakeLists.txt"
    click CMAKE "https://github.com/fortran-lang/stdlib/blob/master/CMakeLists.txt"
    click CMK_EXTRA "https://github.com/fortran-lang/stdlib/blob/master/cmake/stdlib.cmake"
    click FPM "https://github.com/fortran-lang/stdlib/blob/master/fpm.toml"
    click DOC_DIR "https://github.com/fortran-lang/stdlib/tree/master/doc"
    click README "https://github.com/fortran-lang/stdlib/blob/master/README.md"
    click FORD "https://github.com/fortran-lang/stdlib/blob/master/API-doc-FORD-file.md"
    click TESTS "https://github.com/fortran-lang/stdlib/tree/master/test"
    click EXAMPLES "https://github.com/fortran-lang/stdlib/tree/master/example"
    click CI "https://github.com/fortran-lang/stdlib/blob/master/.github"

    %% Styles
    classDef core fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef preproc fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef conf fill:#f0f4c3,stroke:#827717,stroke-width:2px;
    classDef build fill:#ffe082,stroke:#ff6f00,stroke-width:2px;
    classDef compiled fill:#d1c4e9,stroke:#4a148c,stroke-width:2px;
    classDef test fill:#ffcdd2,stroke:#b71c1c,stroke-width:2px;
    classDef example fill:#ffcc80,stroke:#e65100,stroke-width:2px;
    classDef doc fill:#c5e1a5,stroke:#33691e,stroke-width:2px;
    classDef ci fill:#f8bbd0,stroke:#880e4f,stroke-width:2px;
    classDef ext fill:#eeeeee,stroke:#616161,stroke-width:2px;
    classDef docGroup fill:#80deea,stroke:#006064,stroke-width:2px;
```
