# nasa-pds/registry-api architecture

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

- Interactive diagram: https://gitdiagram.com/nasa-pds/registry-api
- Repository: https://github.com/nasa-pds/registry-api

## Overview

##### Project type and purpose
- This is a Maven multi-module Java project providing a standalone Search API (Spring Boot) for NASA’s PDS registry.
- It has three subcomponents:
– lexer: ANTLR4 grammar and parser for incoming “q” query strings
– model: generated OpenAPI client/server definitions and data transfer objects
– service: the Spring Boot application implementing REST endpoints, wiring lexer + model, and querying OpenSearch/Elasticsearch

##### File structure
- Top-level modules:
– pom.xml (parent POM)
– lexer/ (parser library)
– model/ (OpenAPI-based DTOs and controller interfaces)
– service/ (Spring Boot application, controllers, configuration, provisioning, tests)
– docker/ (Dockerfiles for local and CI images)
– terraform/ (IaC for AWS, ECS, networking, API URI rewrites)
- service/src/main/java/gov/nasa/pds/api/registry: layered package structure (configuration, controllers, model, search, util, view) follows a classic layered-MVC pattern
- CI/CD manifests under .github/workflows drive build, test, security checks, release

##### Extract README insights
- It implements PDS Search API v1.0.0 via Spring Boot
- External dependency: an OpenSearch/Elasticsearch cluster (can be stood up via docker-compose in the “registry” repo)
- Two run modes: non-containerized (mvn spring-boot:run) or containerized (mvn spring-boot:build-image + Docker)
- Integration tests driven by Postman/Newman against a running stack

##### Main components & interactions
a. Code modules & build pipeline
– GitHub Source → Maven multi-module build → JARs (lexer.jar, model.jar, service.jar)
– CI/CD (GitHub Actions) automates build → unit tests → Docker image push to registry
b. Runtime deployment
– Docker (container image of registry-api-service) deployed via Docker Compose (dev) or AWS ECS (prod via Terraform)
– Spring Boot Service exposes HTTPS endpoints (/search, /health, /docs)
– Internal processing: HTTP request → SecurityValidationFilter → Controllers → RequestConstructionContext & RequestBuildContext → Antlr4 parser (lexer) → OpenSearch client (OpenSearchRegistryConnectionImpl) → Transform results via ResponseTransformerRegistry → Serialize via Pds4Json/Product serializers → HTTP response
– Swagger UI served from static resources for API docs
c. External services & infrastructure
– OpenSearch/Elasticsearch cluster (multi-tenant discipline nodes)
– AWS (ECS tasks, IAM for secrets via AWSSecretsAccess, CloudWatch for logs)
– Terraform manages AWS infra: provider.tf, variables.tf, ecs.tf, api_uri_rewrite.js

##### Architectural patterns & principles
- Maven multi-module for separation of concerns (lexer, model, service)
- Layered MVC + Service pattern within “service” module:
– Controllers handle HTTP → Services build/search contexts → Repository/Client layer for OpenSearch
- Use of Antlr4 for query parsing (lexer component)
- Dependency-injection (Spring) and AOP for cross-cutting concerns (LoggingAspect, execution timing)
- OpenAPI-first development for model generation

##### Final advice
- Be exhaustive: represent all modules, infra bits, and external systems.
- Keep the service-layer breakdown detailed—this is where most complexity lives.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Build & CI/CD Tier
    subgraph "Build & CI/CD"
        direction TB
        GitHubSource["GitHub Source"]:::external
        CI["CI/CD (GitHub Actions)"]:::infra
        MavenBuild["Maven multi-module Build"]:::code
        ParentPOM["Parent POM"]:::code
        LexerModule["Lexer Module"]:::code
        ModelModule["Model Module"]:::code
        ServiceModule["Service Module"]:::code
        JARs["JAR Artifacts\nlexer.jar, model.jar, service.jar"]:::code
        DockerBuild["Docker Image Build"]:::code
        DockerRegistry["Docker Registry"]:::infra

        GitHubSource -->|"push"| CI
        CI -->|"mvn clean install"| MavenBuild
        MavenBuild --> ParentPOM
        MavenBuild --> LexerModule
        MavenBuild --> ModelModule
        MavenBuild --> ServiceModule
        MavenBuild --> JARs
        CI -->|"build-image"| DockerBuild
        DockerBuild --> DockerRegistry
    end

    %% Containerization & Deployment Tier
    subgraph "Containerization & Deployment"
        direction TB
        DockerRegistryImg["Registry-API Service Image"]:::code
        DevCompose["Docker Compose (Dev)"]:::infra
        TerraformApply["Terraform Apply"]:::infra
        AWSECS["AWS ECS (Prod)"]:::infra

        DockerRegistry --> DockerRegistryImg
        DockerRegistryImg --> DevCompose
        DockerRegistryImg --> TerraformApply
        TerraformApply --> AWSECS
    end

    %% Runtime Tier
    subgraph "Runtime"
        direction TB
        Client["Client"]:::external
        ServiceRuntime["Registry API Service\n(Spring Boot)"]:::code
        OpenSearchCluster["OpenSearch Cluster"]:::external

        Client -->|"HTTPS /search"| ServiceRuntime
        ServiceRuntime -->|"HTTPS (REST)"| Client
        ServiceRuntime -->|"Query DSL"| OpenSearchCluster
        OpenSearchCluster -->|"Results JSON"| ServiceRuntime
    end

    %% Service Internal Breakdown
    subgraph "Service Internals"
        direction TB
        Filter["SecurityValidationFilter"]:::code
        Controllers["Controllers"]:::code
        RequestConstruct["RequestConstructionContext"]:::code
        RequestBuild["RequestBuildContext"]:::code
        AntlrParser["Antlr4 Parser\n(Search.g4 & Main)"]:::code
        OpenSearchClient["OpenSearchRegistryConnectionImpl"]:::code
        Transformer["ResponseTransformerRegistry"]:::code
        Serializer["Pds4Json/Product Serializers"]:::code

        ServiceRuntime --> Filter
        Filter --> Controllers
        Controllers --> RequestConstruct
        RequestConstruct --> RequestBuild
        RequestBuild --> AntlrParser
        AntlrParser --> OpenSearchClient
        OpenSearchClient --> Transformer
        Transformer --> Serializer
        Serializer --> ServiceRuntime
    end

    %% Infrastructure Box
    subgraph "AWS Infrastructure"
        direction TB
        Secrets["AWS Secrets Manager"]:::infra
        CloudWatch["CloudWatch Logs"]:::infra
        AWSECS --> Secrets
        AWSECS --> CloudWatch
    end

    %% Click Events
    click ParentPOM "https://github.com/nasa-pds/registry-api/blob/develop/pom.xml"
    click LexerModule "https://github.com/nasa-pds/registry-api/tree/develop/lexer/"
    click ModelModule "https://github.com/nasa-pds/registry-api/tree/develop/model/"
    click ServiceModule "https://github.com/nasa-pds/registry-api/tree/develop/service/"
    click Filter "https://github.com/nasa-pds/registry-api/tree/develop/service/src/main/java/gov/nasa/pds/api/registry/configuration/"
    click Controllers "https://github.com/nasa-pds/registry-api/tree/develop/service/src/main/java/gov/nasa/pds/api/registry/controllers/"
    click AntlrParser "https://github.com/nasa-pds/registry-api/blob/develop/lexer/src/main/java/api/pds/nasa/gov/api_search_query_lexer/Main.java"
    click AntlrParser "https://github.com/nasa-pds/registry-api/blob/develop/lexer/src/main/antlr4/gov/nasa/pds/api/registry/lexer/Search.g4"
    click RequestConstruct "https://github.com/nasa-pds/registry-api/blob/develop/service/src/main/java/gov/nasa/pds/api/registry/RequestConstructionContext.java"
    click RequestBuild "https://github.com/nasa-pds/registry-api/blob/develop/service/src/main/java/gov/nasa/pds/api/registry/RequestBuildContext.java"
    click OpenSearchClient "https://github.com/nasa-pds/registry-api/tree/develop/service/src/main/java/gov/nasa/pds/api/registry/search/"
    click Transformer "https://github.com/nasa-pds/registry-api/tree/develop/service/src/main/java/gov/nasa/pds/api/registry/model/transformers/"
    click Serializer "https://github.com/nasa-pds/registry-api/tree/develop/service/src/main/java/gov/nasa/pds/api/registry/view/"
    click DockerBuild "https://github.com/nasa-pds/registry-api/tree/develop/docker/Dockerfile"
    click DockerBuild "https://github.com/nasa-pds/registry-api/blob/develop/docker/Dockerfile.local"
    click CI "https://github.com/nasa-pds/registry-api/tree/develop/.github/workflows/"
    click TerraformApply "https://github.com/nasa-pds/registry-api/tree/develop/terraform/"
    click ServiceRuntime "https://github.com/nasa-pds/registry-api/blob/develop/service/src/main/java/gov/nasa/pds/api/registry/SpringBootMain.java"
    click ServiceRuntime "https://github.com/nasa-pds/registry-api/blob/develop/service/src/main/resources/swagger-ui/index.html"

    %% Classes
    classDef code fill:#D0E1F9,stroke:#0366d6,color:#000;
    classDef infra fill:#D5ECD3,stroke:#228B22,color:#000;
    classDef external fill:#FDE4CF,stroke:#DD6B20,color:#000;
```
