# lesis-lat/templates-microservice architecture

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

- Interactive diagram: https://gitdiagram.com/lesis-lat/templates-microservice
- Repository: https://github.com/lesis-lat/templates-microservice

## Overview

##### Project type and purpose
- This is a lightweight HTTP microservice (“Vulnerabilities Templates Micro‑service”) written in Perl (Mojolicious), which reads YAML templates from disk and exposes them via RESTful JSON endpoints.
- Its sole responsibility is to serve vulnerability‐report templates over HTTP, making it a specialized back‑end service with no front‑end UI or database.

##### File structure
- Top‑level files:
- app.pl – the Mojolicious application entry point (routes, controllers, JSON rendering)
- cpanfile – declares Perl module dependencies
- Dockerfile – containerizes the service
- .github/workflows/* – CI/CD pipelines for linting, security scanning, container builds
- Key folder:
- templates/ – contains ~50+ YAML files, each describing a vulnerability template
- No “frontend”, no database directories—everything is in a single service.

##### README for additional insights
- The service runs as a standalone HTTP daemon (default port 9090 mapping to container port 80)
- Deployment methods: direct Perl invocation or Docker container
- CI pipelines enforce code quality and security gates

##### Diagramming recommendations
- Rectangles for services (API, CI/CD, container runtime)
- Parallelogram for external entities (Clients, Load Balancer)
- Blue for runtime components (service, container)
- Green for infrastructure/ops (CI/CD pipelines, orchestrator)
- Orange for data/config stores (templates folder)
- Client → Service (requests)
- Service → Templates store (read)
- Service → Client (JSON response)
- GitHub Actions → Docker registry → Runtime platform

##### Essential architectural elements
- Statelessness: no DB, so multiple instances can run in parallel.
- Immutability of templates on disk—versioned via Git and baked into the image.
- CI/GitHub Actions workflows as an integral part of the delivery pipeline.
- Don’t overcomplicate: the service’s core is really “HTTP in → YAML load → JSON out.”

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    Client["HTTP Clients (CLI, Services, Dashboards)"]:::external

    %% Load Balancer / API Gateway
    LB["API Gateway / Load Balancer"]:::external

    %% Container Runtime and Orchestrator
    subgraph "Orchestrator (Kubernetes/ECS)" 
        direction TB
        Orch["Orchestrator"]:::infra
    end
    subgraph "Container Runtime" 
        direction TB
        Container["Docker Container"]:::infra
    end

    %% Templates Microservice
    subgraph "Vulnerabilities Templates Microservice"
        direction TB
        HTTP["Mojolicious HTTP Server & Routing"]:::service
        Loader["Template Loader"]:::storage
        Templates["Vulnerability Templates (YAML files)"]:::storage
        JSON["JSON Renderer"]:::service
        HTTP -->|reads| Loader
        Loader -->|loads YAML| Templates
        HTTP -->|renders JSON| JSON
        JSON -->|responds| Client
    end

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline (GitHub Actions)" 
        direction TB
        Lint["Linting & Security Scanning"]:::ci
        Build["Docker Build"]:::ci
        Publish["Publish Docker Image"]:::ci
        Lint --> Build --> Publish
    end

    %% Documentation & Config
    subgraph "Docs & Config"
        direction TB
        cpan["Dependency Management (cpanfile)"]:::docs
        perlcrit["Code Quality & Security Config (.perlcriticrc)"]:::docs
        dependabot["Dependabot Config (.github/dependabot.yml)"]:::docs
        collection["API Collection (collection.json)"]:::docs
        readme["Project Documentation (README.md)"]:::docs
    end

    %% Developer
    Dev["Developer"]:::external

    %% Relationships
    Client -->|"HTTP GET /templates[/id]"| LB
    LB -->|"forwards request"| HTTP
    HTTP -->|"runs in"| Container
    Container -->|"managed by"| Orch
    Dev -->|"push code"| Lint
    Publish -->|"image"| Orch

    %% Click Events
    click HTTP "https://github.com/lesis-lat/templates-microservice/blob/main/app.pl"
    click Loader "https://github.com/lesis-lat/templates-microservice/tree/main/templates/"
    click Templates "https://github.com/lesis-lat/templates-microservice/blob/main/templates/*.yml"
    click cpan "https://github.com/lesis-lat/templates-microservice/tree/main/cpanfile"
    click Publish "https://github.com/lesis-lat/templates-microservice/tree/main/Dockerfile"
    click Lint "https://github.com/lesis-lat/templates-microservice/blob/main/.github/workflows/linter.yml"
    click Lint "https://github.com/lesis-lat/templates-microservice/blob/main/.github/workflows/secret-scanning.yml"
    click Lint "https://github.com/lesis-lat/templates-microservice/blob/main/.github/workflows/security-gate.yml"
    click Lint "https://github.com/lesis-lat/templates-microservice/blob/main/.github/workflows/zarn.yml"
    click perlcrit "https://github.com/lesis-lat/templates-microservice/blob/main/.perlcriticrc"
    click dependabot "https://github.com/lesis-lat/templates-microservice/blob/main/.github/dependabot.yml"
    click collection "https://github.com/lesis-lat/templates-microservice/blob/main/collection.json"
    click readme "https://github.com/lesis-lat/templates-microservice/blob/main/README.md"

    %% Styles
    classDef external fill:#f2f2f2,stroke:#333,stroke-width:1px
    classDef service fill:#b3d7ff,stroke:#333,stroke-width:1px
    classDef storage fill:#ffcc99,stroke:#333,stroke-width:1px
    classDef infra fill:#c6f5c6,stroke:#333,stroke-width:1px
    classDef ci fill:#a3d5a3,stroke:#333,stroke-width:1px
    classDef docs fill:#f5c6e0,stroke:#333,stroke-width:1px
```
