# duclong06/face-detection-ml-system architecture

> Architecture diagram of the GitHub repository duclong06/face-detection-ml-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/duclong06/face-detection-ml-system
- Repository: https://github.com/duclong06/face-detection-ml-system

## Overview

##### Main Components
- ML Service (API): Represent the face detection API (located in the “api” folder). This is where the core business logic (e.g., main.py, my_yolo.py) runs.
- Deployment and Orchestration: Include the Kubernetes layer (GKE) that hosts your containers. Represent the Helm charts (in “charts/face-detection” and “charts/nginx-ingress”) that deploy the API service and manage the ingress.
- Cloud Infrastructure: Show the infrastructure components (managed by Terraform and Ansible under “infrastructure”) used for provisioning GCP resources and configuring the cluster.
- Observability Stack: Include the monitoring and logging tools such as Prometheus, Grafana (via kube-prometheus-stack), ELK stack (Elasticsearch, Logstash, Kibana), and Jaeger for distributed tracing. Note that observability configurations exist in “monitoring/K8s” for the cluster and “monitoring/Local” for local testing.

##### Relationships and Interactions
- The ML Service is containerized and deployed on the GKE cluster, with the Kubernetes Ingress (configured via Helm charts in “charts/nginx-ingress”) managing external traffic.
- The CI/CD pipeline (Jenkins) automates the process: it builds Docker images (referenced in the “scripts” directory and Dockerfiles in API and Jenkins locations), pushes them to a container registry, and triggers Helm upgrades to update deployments.
- The infrastructure layer (Terraform and Ansible) provisions the GKE cluster and required network/security configurations. It also handles generate SSH keys and service accounts for deployment.
- The Observability Component collects metrics (Prometheus), offers dashboards (Grafana), and manages logs (ELK stack) alongside distributed tracing (Jaeger) that monitor the running services in the cluster.

##### Architectural Patterns and Principles
- Containerization and Orchestration: Emphasize the usage of Docker, Kubernetes (GKE) and Helm charts to encapsulate and deploy microservices.
- CI/CD and DevOps Automation: Outline the pipeline that integrates code validation, automated testing, image building, and automated deployment.
- Infrastructure as Code: Note the use of Terraform and Ansible for provisioning cloud resources and automating environment configuration.
- Observability and Monitoring: Detail the stack’s strategies to capture metrics, logs, and traces to ensure the system’s health is continuously monitored.

##### Technologies, Frameworks, and Tools
- Languages/Frameworks: Python for the API service.
- Container Tools: Docker, Docker Compose.
- Orchestration & Deployment: Kubernetes (GKE), Helm, and Helmfile.
- Infrastructure Automation: Terraform, Ansible.
- CI/CD: Jenkins.
- Monitoring & Logging: Prometheus, Grafana, ELK Stack (Elasticsearch, Logstash, Kibana), and Jaeger.
- Other DevOps utilities: Google Cloud SDK, kubectl, helm, and related CLI utilities.

- Each component should be clearly labeled (e.g., “Face Detection API”, “Nginx Ingress”, “GKE Cluster”, “Terraform/Ansible Infrastructure”, “Jenkins CI/CD”, “Prometheus/Grafana”, “ELK Stack”, “Jaeger”).
- Request flows from users -> ingress -> API service.
- Deployment flows from Jenkins to the container registry and then to GKE (via Helm charts).
- Data flows from running containers toward observability tools.
- Interconnection notes where important (e.g., “API Service deployed via Helm”, “Infrastructure provisioned with Terraform”, “Logs aggregated in ELK”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Layer"
        User("User/Client"):::user
    end

    subgraph "Ingress Layer"
        Ingress("Nginx Ingress"):::ingress
    end

    subgraph "Service/Application Layer"
        Helm("Helm Chart (Face Detection)"):::orchestration
        API("Face Detection API"):::service
        MainPy("main.py"):::serviceDetail
        YOLO("my_yolo.py"):::serviceDetail
    end

    subgraph "CI/CD Pipeline"
        Jenkins("Jenkins CI/CD"):::cicd
        Jenkinsfile("Jenkinsfile"):::cicdDetail
        CustomJenkins("Custom Jenkins Image"):::cicdDetail
    end

    subgraph "Infrastructure Layer"
        GKE("GKE Cluster"):::infra
        Terraform("Terraform Provisioning"):::infraDetail
        Ansible("Ansible Provisioning"):::infraDetail
    end

    subgraph "Observability Layer"
        PromGraf("Prometheus/Grafana"):::observability
        ELK("ELK Stack"):::observability
        Jaeger("Jaeger"):::observability
        K8sMon("K8s Monitoring Config"):::observabilityDetail
        LocalMon("Local Monitoring Config"):::observabilityDetail
    end

    User -->|"requests"| Ingress
    Ingress -->|"routes"| Helm
    Helm -->|"deploys"| API
    API -->|"contains"| MainPy
    API -->|"contains"| YOLO
    API -->|"deployed_on"| GKE
    Terraform -->|"provisions"| GKE
    Ansible -->|"configures"| GKE
    Jenkins -->|"triggers"| GKE
    Jenkins -->|"defines"| Jenkinsfile
    Jenkins -->|"uses"| CustomJenkins
    GKE -->|"metrics"| PromGraf
    GKE -->|"logs"| ELK
    GKE -->|"traces"| Jaeger
    GKE -->|"configures"| K8sMon
    GKE -->|"configures"| LocalMon

    classDef user fill:#B3E5FC,stroke:#0277BD,stroke-width:2px;
    classDef ingress fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
    classDef orchestration fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef service fill:#FFF9C4,stroke:#F9A825,stroke-width:2px;
    classDef serviceDetail fill:#FFF59D,stroke:#FBC02D,stroke-width:2px;
    classDef cicd fill:#D1C4E9,stroke:#512DA8,stroke-width:2px;
    classDef cicdDetail fill:#B39DDB,stroke:#673AB7,stroke-width:2px;
    classDef infra fill:#E1BEE7,stroke:#8E24AA,stroke-width:2px;
    classDef infraDetail fill:#CE93D8,stroke:#AD1457,stroke-width:2px;
    classDef observability fill:#FFECB3,stroke:#FF8F00,stroke-width:2px;
    classDef observabilityDetail fill:#FFE082,stroke:#FFA000,stroke-width:2px;

    click API "https://github.com/duclong06/face-detection-ml-system/tree/main/api"
    click MainPy "https://github.com/duclong06/face-detection-ml-system/blob/main/api/main.py"
    click YOLO "https://github.com/duclong06/face-detection-ml-system/blob/main/api/my_yolo.py"
    click Helm "https://github.com/duclong06/face-detection-ml-system/tree/main/charts/face-detection"
    click Ingress "https://github.com/duclong06/face-detection-ml-system/tree/main/charts/nginx-ingress"
    click Terraform "https://github.com/duclong06/face-detection-ml-system/tree/main/infrastructure/terraform"
    click Ansible "https://github.com/duclong06/face-detection-ml-system/tree/main/infrastructure/ansible"
    click Jenkinsfile "https://github.com/duclong06/face-detection-ml-system/tree/main/Jenkinsfile"
    click CustomJenkins "https://github.com/duclong06/face-detection-ml-system/tree/main/custom_images/jenkins"
    click K8sMon "https://github.com/duclong06/face-detection-ml-system/tree/main/monitoring/K8s"
    click LocalMon "https://github.com/duclong06/face-detection-ml-system/tree/main/monitoring/Local"
```
