# metacubed-projects/k8s-auth-sidecar-demo architecture

> Architecture diagram of the GitHub repository metacubed-projects/k8s-auth-sidecar-demo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/metacubed-projects/k8s-auth-sidecar-demo
- Repository: https://github.com/metacubed-projects/k8s-auth-sidecar-demo

## Overview

##### Main Components
- Kubernetes Cluster: At the top level, show that the application is deployed on Kubernetes (Minikube in this demo).
- Kubernetes Pod: Within the cluster, encapsulate the pod that houses two key containers:
– Sidecar Proxy (auth-proxy): A Java-based proxy (located in the “auth-proxy” directory, with its Dockerfile, Maven configuration, and Java source files like Application.java and ProxyController.java). It listens on port 8000 and intercepts incoming API calls to perform authentication/authorization.
– Resource Server: A Node.js-based server (in the “resource-server” directory with package.json and index.js) handling API endpoints at port 80.
- Deployment Configurations: Outside the pod, include a block for deployment scripts/configurations from “deploy-config” (like deploy-minikube.sh, deployment.yml, service.yml). This shows how the pods are instantiated, exposed, and managed on Kubernetes.

##### Relationships and Data Flow
- Incoming Traffic: Illustrate that external clients make API calls (e.g., to /data) which are received by a Kubernetes Service (as defined in “service.yml”) that routes the request into the pod.
– If authentication/authorization checks pass, the request is forwarded to the Resource Server.
– If checks fail, a 403 Forbidden response is generated by the proxy.
- Initialization: Optionally, show an initialization flow from the “auth-proxy-init” container that sets up configurations or any required environment for the auth proxy prior to receiving live traffic.

##### Architectural Patterns and Technologies
- Sidecar Pattern: Emphasize the separation and close coupling within the pod – the proxy running alongside the resource server.
- Technology Stack: Note that the sidecar is implemented in Java (with Spring Boot-like patterns implied by the file structure), while the resource server uses Node.js for API logic. Also, mention the use of Maven for Java dependency management and standard Kubernetes tools (kubectl, Minikube) for orchestration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    client("External Client"):::external
    k8sService("Kubernetes Service"):::service
    deployConfig("Deployment Configurations"):::deploy

    %% Kubernetes Cluster and Pod
    subgraph "Kubernetes Cluster (Minikube)"
        subgraph "Pod"
            initContainer("Init Container: auth-proxy-init"):::container
            sidecarProxy("Sidecar Proxy (Java, port 8000)"):::container
            resourceServer("Resource Server (Node.js, port 80)"):::container
        end
    end

    %% Data Flow Arrows
    client -->|"API_call"| k8sService
    k8sService -->|"Routes_to"| sidecarProxy
    initContainer -->|"Initializes"| sidecarProxy
    sidecarProxy -->|"Forward_if_Authorized"| resourceServer
    sidecarProxy -->|"403_Response_if_Unauthorized"| client
    deployConfig -->|"Deploys_via"| k8sService

    %% Click Events for Sidecar Proxy
    click sidecarProxy "https://github.com/metacubed-projects/k8s-auth-sidecar-demo/tree/master/auth-proxy/Dockerfile"
    click sidecarProxy "https://github.com/metacubed-projects/k8s-auth-sidecar-demo/blob/master/auth-proxy/pom.xml"
    click sidecarProxy "https://github.com/metacubed-projects/k8s-auth-sidecar-demo/blob/master/auth-proxy/src/main/java/org/metacubed/authproxy/Application.java"
    click sidecarProxy "https://github.com/metacubed-projects/k8s-auth-sidecar-demo/blob/master/auth-proxy/src/main/java/org/metacubed/authproxy/ProxyController.java"

    %% Click Events for Resource Server
    click resourceServer "https://github.com/metacubed-projects/k8s-auth-sidecar-demo/blob/master/resource-server/index.js"
    click resourceServer "https://github.com/metacubed-projects/k8s-auth-sidecar-demo/blob/master/resource-server/package.json"
    click resourceServer "https://github.com/metacubed-projects/k8s-auth-sidecar-demo/tree/master/resource-server/Dockerfile"

    %% Click Events for Init Container
    click initContainer "https://github.com/metacubed-projects/k8s-auth-sidecar-demo/tree/master/auth-proxy-init/Dockerfile"
    click initContainer "https://github.com/metacubed-projects/k8s-auth-sidecar-demo/blob/master/auth-proxy-init/init.sh"

    %% Click Events for Deployment Configurations
    click deployConfig "https://github.com/metacubed-projects/k8s-auth-sidecar-demo/blob/master/deploy-config/deploy-minikube.sh"
    click deployConfig "https://github.com/metacubed-projects/k8s-auth-sidecar-demo/blob/master/deploy-config/deployment.yml"
    click deployConfig "https://github.com/metacubed-projects/k8s-auth-sidecar-demo/blob/master/deploy-config/service.yml"

    %% Styles and Colors
    classDef external fill:#fce4ec,stroke:#ad1457,stroke-width:2px;
    classDef service fill:#fff9c4,stroke:#f9a825,stroke-width:2px;
    classDef container fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
    classDef deploy fill:#ffcdd2,stroke:#c62828,stroke-width:2px;
```
