# sangam14/syft-api architecture

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

- Interactive diagram: https://gitdiagram.com/sangam14/syft-api
- Repository: https://github.com/sangam14/syft-api

## Overview

##### Project Type & Purpose
- This is a backend service written in Go that provides an API (with an exposed OpenAPI spec at http://localhost:3000) for generating Software Bill of Materials (SBOMs).
- It integrates AI capabilities through the use of the Ollama model runner and can scan Docker images, local directories, and GitHub repositories.
- The presence of a static folder (with an index.html, a JavaScript file, and CSS) indicates a basic frontend served by the API (or via static hosting) to interact with users.

##### Main Components
- API/Backend Service: Represented by main.go and its supporting backend business logic. This is the central component of the system.
- SBOM Generation Engine: A logical component within the backend that coordinates scans across different sources (Docker images, directories, and GitHub repositories) and integrates with the AI-powered model.
- External Service Integration (Ollama): Since the README mandates that Ollama must be running locally, outline this as an external dependency that the SBOM generator communicates with.
- Static Frontend Assets: The static directory contains assets like index.html, script.js, style.css, and even an output.log. This represents a user interface that interacts with the backend service.
- Containerization/Docker Environment: With files such as docker-compose.yaml, dockerfile, and .dockerignore, stress the importance of container orchestration. This encapsulates the runtime environment of the application.

##### Relationships & Data Flow
- The frontend (static assets) is served to the user’s browser. Users interact with the UI, which sends HTTP requests (via API calls) to the Go-based backend service.
- The backend service (API) processes these requests. Depending on the source the user wants to scan (Docker images, directories, or GitHub repositories), it triggers the appropriate scanning logic.
- When AI capabilities are required, the backend makes a request to the local Ollama model runner to get model-based insights or enhance the SBOM generation.
- Docker Compose manages the container lifecycle, ensuring that the API service and any related services (if added in the future, such as a Docker-model-runner container) run with the proper configuration.

##### Architectural Patterns & Design Principles
- Layered Architecture: Separate the system into layers – a presentation layer (frontend), an application layer (API endpoints and business logic), and integrations with external services (Ollama).
- Clear Separation of Concerns: Distinguish between scanning logic, AI integration, and deployment responsibilities.
- Containerized Deployment: Emphasize how Docker (via docker-compose) is used to encapsulate and deploy the complete environment, ensuring consistency between development and production.

- Next, highlight the static assets being served to users from the backend or as a separate delivery mechanism.
- External dependencies—particularly the local Ollama service that the API calls during SBOM generation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Docker Ecosystem"
        API["Go API Service (main.go)\nSBOM Generator & Scanner"]:::backend
        DC["docker-compose.yaml"]:::docker
        DF["dockerfile"]:::docker
        DI[".dockerignore"]:::docker
    end

    FE["User Interface / Frontend (static/)"]:::frontend
    AI["Ollama Model Runner"]:::ai

    FE -->|"HTTP_API_call"| API
    API -->|"Model_Execution_Request"| AI

    click API "https://github.com/sangam14/syft-api/blob/main/main.go"
    click FE "https://github.com/sangam14/syft-api/tree/main/static/"
    click DC "https://github.com/sangam14/syft-api/blob/main/docker-compose.yaml"
    click DF "https://github.com/sangam14/syft-api/tree/main/dockerfile"
    click DI "https://github.com/sangam14/syft-api/blob/main/.dockerignore"

    classDef backend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef docker fill:#B0E0E6,stroke:#000,stroke-width:2px;
    classDef frontend fill:#FFFACD,stroke:#000,stroke-width:2px;
    classDef ai fill:#FFDAB9,stroke:#000,stroke-width:2px;
```
