# osgeo/proj architecture

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

- Interactive diagram: https://gitdiagram.com/osgeo/proj
- Repository: https://github.com/osgeo/proj

## Overview

Based on our analysis of the complete file tree and the README, PROJ is a geospatial coordinate transformation library that provides both a robust C/C++ core and several command line utilities (such as proj, cs2cs, geod, cct, gie, projinfo, and projsync). Its purpose is to transform geographic coordinates across various coordinate reference systems (CRS), including handling projections, grid shifts, and datum transformations. The project “PROJ” is heavily modularized in its source tree with distinct directories for core libraries (src and include), command line applications (src/apps), extension modules (e.g., ISO19111 folder in src), scripts (for building and generating databases), testing (unit, CLI, fuzzers, postinstall), documentation (docs), and data (grid files and configuration).

##### Main Components and Their Roles
- Core Library Module – Represent the engine that implements coordinate transformations, including coordinate systems, datums, projections, and transformation algorithms. This covers areas implemented in files under src, include, and specific subsystems like the ISO19111 implementation.
- Command Line Applications – Group together the utilities (proj, cs2cs, geod, cct, gie, projinfo, projsync) that serve as the public interface. They are built on top of the core library and provide user-facing operations.
- Data Management and Resource Handling – Show the module that manages resource files such as grid shift data, datum transformation tables, and parameter (configuration) files. This component is responsible for accessing local resource files (from PROJ_LIB) and fetching from network/CDN if required.
- Build and Configuration System – A layer showing the usage of CMake (the cmake directory, CMakeLists.txt files) and additional scripts that manage builds, tests, and continuous integration (workflows under .github, CI scripts under scripts/ci).
- Testing and Quality Assurance – Represent the various testing suites (unit tests, CLI tests, fuzzers, postinstall tests) to highlight the rigorous validation process.
- Documentation and Community – Although not part of the run-time system per se, it’s important to include the docs and examples directories that detail the usage, API references, and tutorials.

##### Relationships and Interactions
- A bi-directional relationship between the Core Library and the Data Management component. The core uses grid files and datum definitions (data directory and resource configurations) during operation, and in “network-enabled builds” these modules can dynamically retrieve needed resources.
- An “External Systems” component to denote external data sources (e.g., PROJ CDN) and optionally third-party libraries (if any, such as the JSON parser referenced in the vendor files).
- Testing layer as a separate element that interacts with both the core library and the applications, thus ensuring quality before deployment.

##### Architectural Patterns and Design Principles
- Layered Architecture: Emphasize a clear separation between the core transformation engine (business logic), command line interfaces (presentation layer), and external resource management.
- Modular Design: Indicate that many directories (such as projections, transformations, ISO19111 modules) encapsulate specific functionality. Internal interfaces (like those in “internal” directories) are key for abstraction.
- Extensibility: Note that there are components (e.g., scripts for generating grid databases, dynamic fetching of projection files) that illustrate an extensible design for maintaining up-to-date data.
- Testability: Emphasize the comprehensive testing suite that supports unit, integration, and fuzz testing, which is critical for a core library used in geospatial computations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build & CI Infrastructure
    subgraph "Build & CI Infrastructure"
        CMakeRoot["CMakeLists.txt"]:::build
        CMakeDir["cmake"]:::build
        GitHubCI[".github/workflows"]:::build
        CIScripts["scripts/ci"]:::build
    end

    %% Core Transformation Engine
    subgraph "Core Transformation Engine"
        CoreLib["Core Library Module"]:::core
        CoreSrc["src"]:::core
        CoreInclude["include"]:::core
        ISO19111["ISO19111 Module"]:::core
    end

    %% Command Line Utilities
    subgraph "Command Line Utilities"
        CLI["Command Line Applications"]:::cli
        CmdApps["src/apps"]:::cli
        ManPages["man/man1"]:::cli
    end

    %% Data Resources & Management
    subgraph "Data Resources & Management"
        Data["Data Management & Resource Handling"]:::data
        DataDir["data"]:::data
        Scripts["scripts"]:::data
    end

    %% Testing & Validation Suite
    subgraph "Testing & Validation Suite"
        Testing["Testing & QA"]:::test
        TestDir["test"]:::test
    end

    %% Documentation & Community
    subgraph "Documentation & Community"
        Docs["Documentation"]:::doc
        DocsDir["docs"]:::doc
        Examples["Examples"]:::doc
    end

    %% External Systems
    subgraph "External Systems"
        External["External Data Source (PROJ CDN)"]:::external
    end

    %% Relationships & Data flow
    CLI -->|"uses"| CoreLib
    CoreLib <-->|"resources"| Data

    CMakeRoot -->|"builds"| CoreLib
    CMakeRoot -->|"builds"| CLI
    CMakeRoot -->|"builds"| Data
    CMakeRoot -->|"builds"| Testing

    GitHubCI -->|"CI-tests"| CoreLib
    GitHubCI -->|"CI-tests"| CLI
    GitHubCI -->|"CI-tests"| Data
    GitHubCI -->|"CI-tests"| Testing

    CIScripts -->|"CI-tests"| CoreLib
    CIScripts -->|"CI-tests"| CLI
    CIScripts -->|"CI-tests"| Data
    CIScripts -->|"CI-tests"| Testing

    Testing -->|"validates"| CoreLib
    Testing -->|"validates"| CLI

    Data -->|"fetches"| External

    %% Internal Component Connections in Core Engine
    CoreLib -->|"contains"| CoreSrc
    CoreLib -->|"contains"| CoreInclude
    CoreLib -->|"contains"| ISO19111

    %% Internal Component Connections in Command Line Utilities
    CLI -->|"implemented_in"| CmdApps
    CLI -->|"documents"| ManPages

    %% Internal Component Connections in Data Management
    Data -->|"includes"| DataDir
    Data -->|"includes"| Scripts

    %% Internal Component Connections in Documentation
    Docs -->|"source"| DocsDir
    Docs -->|"demonstrates"| Examples

    %% Styling classes
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef cli fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef data fill:#FFFFE0,stroke:#000,stroke-width:2px;
    classDef build fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef test fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef doc fill:#F4A460,stroke:#000,stroke-width:2px;
    classDef external fill:#FFA07A,stroke:#000,stroke-width:2px;

    %% Click Events
    click CoreSrc "https://github.com/osgeo/proj/tree/master/src"
    click CoreInclude "https://github.com/osgeo/proj/tree/master/include"
    click ISO19111 "https://github.com/osgeo/proj/tree/master/src/iso19111"
    click CmdApps "https://github.com/osgeo/proj/tree/master/src/apps"
    click ManPages "https://github.com/osgeo/proj/tree/master/man/man1"
    click DataDir "https://github.com/osgeo/proj/tree/master/data"
    click Scripts "https://github.com/osgeo/proj/tree/master/scripts"
    click CMakeRoot "https://github.com/osgeo/proj/blob/master/CMakeLists.txt"
    click CMakeDir "https://github.com/osgeo/proj/tree/master/cmake"
    click GitHubCI "https://github.com/osgeo/proj/tree/master/.github/workflows"
    click CIScripts "https://github.com/osgeo/proj/tree/master/scripts/ci"
    click TestDir "https://github.com/osgeo/proj/tree/master/test"
    click DocsDir "https://github.com/osgeo/proj/tree/master/docs"
    click Examples "https://github.com/osgeo/proj/tree/master/examples"
```
