# tritondatacenter/sdc-papi architecture

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

- Interactive diagram: https://gitdiagram.com/tritondatacenter/sdc-papi
- Repository: https://github.com/tritondatacenter/sdc-papi

## Overview

##### Project type and purpose
- sdc-papi is a standalone Node.js microservice within the Triton Data Center ecosystem.
- It exposes an HTTP/REST interface (“Packages API”) for creating, listing, and managing software packages used during OS provisioning.

##### File structure
- Top‐level artifacts
- server.js – entry point, spins up the HTTP server
- lib/ – core modules (backend logic, PAPI routes, tools, migrations, validations)
- etc/config.test.json – configuration for test environments
- smf/manifests – SMF service definition templates for Solaris zones
- deps/ – vendored scripts and linters
- test/ – integration tests and test harness scripts
- Jenkinsfile, Makefile, tools/ – CI/CD and development utilities
- Pattern hints
- Modular separation: routing (lib/papi.js) vs. business logic (lib/backend.js) vs. migrations & validations
- Deployment via SMF manifests and config scripts under boot/ and smf/

##### Extract README insights
- The service runs in its own VM (the “PAPI VM”) and is tested end‐to‐end with runtests.
- It integrates with Triton’s global headnode for sample data setup.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    ExternalClients["External Clients (CloudAPI/CLI)"]:::external
    Headnode["Triton Global Headnode"]:::external

    %% Packages API Service
    subgraph "Packages API Service"
        direction TB
        HTTPServer["HTTP Server"]:::transport
        PAPIRouter["PAPI Router"]:::transport
        Backend["Business Logic / Backend"]:::business
        Validations["Validation Module"]:::business
        Migrations["Persistence / Migrations"]:::persistence
        ToolsUtil["Utility Tools"]:::tools
        ConfigModule["Configuration Module"]:::config
        DataStore["Data Store (Filesystem/DB)"]:::persistence
        HTTPServer --> PAPIRouter
        PAPIRouter --> Backend
        Backend --> DataStore
        Backend -->|reads| ConfigModule
        Backend -->|runs migrations| Migrations
        Backend -->|validates| Validations
        Backend -->|utilizes| ToolsUtil
    end

    %% SMF Deployment
    subgraph "SMF Deployment"
        direction TB
        SMFManifests["SMF Manifests"]:::config
        SMFTemplates["SMF Templates"]:::config
        SMFDaemon["SMF Daemon"]:::transport
        SMFManifests -->|deploy| SMFDaemon
        SMFTemplates --> SMFDaemon
        SMFDaemon -->|launches| HTTPServer
    end

    %% CI/CD & Dev Tools
    subgraph "CI/CD & Dev Tools"
        direction TB
        CI["CI/CD Pipeline"]:::tools
        MakefileNode["Makefile"]:::tools
        BootConfig["boot/configure.sh"]:::tools
        BootSetup["boot/setup.sh"]:::tools
        Vendored["Vendored Scripts & Linters"]:::tools
        DevConfigs["Dev Tool Configs"]:::tools
        CI --> MakefileNode
        CI --> BootConfig
        BootConfig --> BootSetup
        BootSetup --> DeployVM["Deploy PAPI VM"]:::transport
        DeployVM --> SMFDaemon
        CI -->|lints/tests| Vendored
        CI -->|uses| DevConfigs
    end

    %% Testing Harness
    subgraph "Testing"
        direction TB
        Tests["Test Harness"]:::tools
        APITest["api.test.js"]:::tools
        Runtests["runtests"]:::tools
        Tests --> APITest
        Tests --> Runtests
        Tests --> DeployVM
        Tests --> Headnode
    end

    %% Core Flows
    ExternalClients --> HTTPServer

    %% Package Manifest
    PackageJSON["package.json"]:::config

    %% Click Events
    click HTTPServer "https://github.com/tritondatacenter/sdc-papi/blob/master/server.js"
    click PAPIRouter "https://github.com/tritondatacenter/sdc-papi/blob/master/lib/papi.js"
    click Backend "https://github.com/tritondatacenter/sdc-papi/blob/master/lib/backend.js"
    click Validations "https://github.com/tritondatacenter/sdc-papi/blob/master/lib/validations.js"
    click Migrations "https://github.com/tritondatacenter/sdc-papi/tree/master/lib/migrations/"
    click ToolsUtil "https://github.com/tritondatacenter/sdc-papi/blob/master/lib/tools.js"
    click ConfigModule "https://github.com/tritondatacenter/sdc-papi/blob/master/etc/config.test.json"
    click SMFManifests "https://github.com/tritondatacenter/sdc-papi/blob/master/smf/manifests/papi.xml.in"
    click SMFTemplates "https://github.com/tritondatacenter/sdc-papi/blob/master/sapi_manifests/papi/manifest.json"
    click CI "https://github.com/tritondatacenter/sdc-papi/tree/master/Jenkinsfile"
    click MakefileNode "https://github.com/tritondatacenter/sdc-papi/tree/master/Makefile"
    click BootConfig "https://github.com/tritondatacenter/sdc-papi/blob/master/boot/configure.sh"
    click BootSetup "https://github.com/tritondatacenter/sdc-papi/blob/master/boot/setup.sh"
    click Vendored "https://github.com/tritondatacenter/sdc-papi/tree/master/deps/"
    click DevConfigs "https://github.com/tritondatacenter/sdc-papi/tree/master/tools/"
    click APITest "https://github.com/tritondatacenter/sdc-papi/blob/master/test/api.test.js"
    click Runtests "https://github.com/tritondatacenter/sdc-papi/tree/master/test/runtests"
    click PackageJSON "https://github.com/tritondatacenter/sdc-papi/blob/master/package.json"

    %% Styles
    classDef transport fill:#D0E6FF,stroke:#333,stroke-width:1px
    classDef business fill:#D0FFD6,stroke:#333,stroke-width:1px
    classDef persistence fill:#FFE3B3,stroke:#333,stroke-width:1px
    classDef config fill:#FFD1D1,stroke:#333,stroke-width:1px
    classDef tools fill:#EDEDED,stroke:#333,stroke-width:1px
    classDef external fill:#F0F0F0,stroke:#333,stroke-width:1px
```
