# 0jk6/freight architecture

> Architecture diagram of the GitHub repository 0jk6/freight, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/0jk6/freight
- Repository: https://github.com/0jk6/freight

## Overview

##### Main Components

a) Frontend Layer:
- React/TypeScript application (found in ui/freight)
- As a web interface component

b) Backend Components:
- Backend API Service (cmd/backend)
- Processing Service (cmd/service)
- As separate microservices

c) Kubernetes Infrastructure:
- K8s Jobs for code execution
- Orchestration layer
- Pod isolation

d) Database Layer:
- Represented by the internal/db component
- As a persistent storage component

##### Component Relationships

- Frontend → Backend API (HTTP/REST)
- Backend API → Database (data persistence)
- Backend API → Orchestrator (job management)
- Orchestrator → K8s Jobs (code execution)
- Service → K8s Jobs (processing)

##### Architectural Patterns to Highlight

- Microservices Architecture (separate backend and service)
- Job Processing Pattern (for code execution)
- API Gateway Pattern (backend serving as the entry point)

##### Specific Implementation Details

- Handlers (internal/handlers)
- Models (internal/models)
- Jobs (internal/jobs)
- Orchestrator (internal/orchestrator)
- Middlewares (internal/middlewares)

##### Additional Elements

- Security boundaries
- CORS middleware
- Logging components
- Docker container boundaries

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        UI["Frontend Application"]:::frontend
    end

    subgraph "API Layer"
        API["Backend API Service"]:::backend
        CORS["CORS Middleware"]:::middleware
        LOG["Logging Middleware"]:::middleware
        HAND["Request Handlers"]:::handler
    end

    subgraph "Processing Layer"
        PROC["Processing Service"]:::service
        ORCH["Orchestrator"]:::service
    end

    subgraph "Data Layer"
        DB[(Database)]:::database
    end

    subgraph "Kubernetes Infrastructure"
        K8S["Kubernetes Cluster"]:::k8s
        JOBS["K8s Jobs"]:::k8s
    end

    subgraph "Core Components"
        MOD["Data Models"]:::core
        JPROC["Job Processing"]:::core
    end

    UI --> |HTTP/REST| CORS
    CORS --> LOG
    LOG --> API
    API --> HAND
    HAND --> MOD
    HAND --> DB
    HAND --> ORCH
    ORCH --> JOBS
    PROC --> JOBS
    JOBS --> JPROC
    JPROC --> DB
    DB --> API
    API --> UI

    %% Component Mappings
    click UI "https://github.com/0jk6/freight/tree/main/ui/freight/src"
    click API "https://github.com/0jk6/freight/blob/main/cmd/backend/main.go"
    click PROC "https://github.com/0jk6/freight/blob/main/cmd/service/main.go"
    click DB "https://github.com/0jk6/freight/blob/main/internal/db/db.go"
    click HAND "https://github.com/0jk6/freight/tree/main/internal/handlers"
    click JPROC "https://github.com/0jk6/freight/tree/main/internal/jobs"
    click ORCH "https://github.com/0jk6/freight/blob/main/internal/orchestrator/orchestrator.go"
    click CORS "https://github.com/0jk6/freight/blob/main/internal/middlewares/cors.go"
    click LOG "https://github.com/0jk6/freight/blob/main/internal/middlewares/logger.go"
    click MOD "https://github.com/0jk6/freight/tree/main/internal/models"

    %% Styling
    classDef frontend fill:#2196F3,stroke:#1565C0,color:white
    classDef backend fill:#4CAF50,stroke:#2E7D32,color:white
    classDef service fill:#FFC107,stroke:#FFA000,color:black
    classDef k8s fill:#F44336,stroke:#C62828,color:white
    classDef database fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef core fill:#607D8B,stroke:#37474F,color:white
    classDef middleware fill:#FF9800,stroke:#F57C00,color:white
    classDef handler fill:#8BC34A,stroke:#689F38,color:white

    %% Legend
    subgraph Legend
        L1[Frontend]:::frontend
        L2[Backend]:::backend
        L3[Service]:::service
        L4[Kubernetes]:::k8s
        L5[Database]:::database
        L6[Core]:::core
        L7[Middleware]:::middleware
        L8[Handler]:::handler
    end
```
