# amitabh-devops/dev-gemini-clone architecture

> Architecture diagram of the GitHub repository amitabh-devops/dev-gemini-clone, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amitabh-devops/dev-gemini-clone
- Repository: https://github.com/amitabh-devops/dev-gemini-clone

## Overview

##### Project type and purpose
- This is a full-stack web application (“Google Gemini Clone”) built with Next.js (React + Node).
- It’s production-grade with a full DevSecOps pipeline: CI/CD using Jenkins, GitOps via ArgoCD, Infrastructure as Code via Terraform, containerization with Docker/Kubernetes on AWS EKS, and observability with Prometheus/Grafana.

##### File structure
- Top‐level infra code:
- terraform/ (EC2 + Jenkins provisioning)
- Terraform-EKS-Deployment/ (EKS cluster provisioning)
- kubernetes/ (K8s manifests: Namespace, Deployments, Services, Ingress, ConfigMap, Secrets, HPA)
- GitOps/Jenkinsfile & Jenkinsfile in root for CI/CD pipelines.
- Application code under src/:
- A Next.js “app router” structure (routes, layout.tsx, page.tsx).
- API routes (src/app/api/auth/… using NextAuth).
- Models (chat.model.ts, user.model.ts), utilities (db.ts, theme providers), and atomic/react components.
- Config files: Dockerfile, docker-compose.yml, next.config.mjs, tsconfig.json, Tailwind CSS config.
- CI/CD & DevOps docs: DOCKER_BUILD.md, ENV_SETUP.md, DOCKERIGNORE, .env.sample.

##### README for additional insights
- The app uses MongoDB (MONGODB_URI) and Google OAuth via NextAuth.
- DevSecOps steps:
- Build → Tag → Push Docker image → Update K8s manifests.
- Terraform for EKS & EC2 provisioning.
- ArgoCD for GitOps-driven deployments.
- Jenkins master/agent pipeline with SonarQube, OWASP Dependency-Check and Trivy scans.
- Observability via Prometheus/Grafana.

##### Essential architectural elements
- Infra provisioning (Terraform → AWS EKS + EC2).
- CI/CD vs GitOps separation.
- How ConfigMap/Secrets feed runtime.
- Monitoring stack as integral to production.
- Don’t over-fragment—group related microservices and pipeline steps logically.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer & Code Repo
    subgraph "Developer & GitHub"
        Dev["Developer"]:::external
        GitHub["GitHub Repo"]:::external
    end
    Dev -->|push code| GitHub

    %% CI/CD Layer
    subgraph "CI/CD Layer"
        JenkinsMaster["Jenkins Master"]:::ci
        JenkinsAgent["Jenkins Agent"]:::ci
        JenkinsfileNode["Jenkinsfile"]:::ci
        GitOpsJenkinsfile["GitOps/Jenkinsfile"]:::ci
    end
    GitHub -->|webhook| JenkinsMaster
    JenkinsMaster -->|delegate| JenkinsAgent
    JenkinsMaster -->|"runs pipeline definitions"| JenkinsfileNode
    JenkinsMaster -->|"runs GitOps pipeline"| GitOpsJenkinsfile

    %% Container Registry
    subgraph "Container Registry"
        Registry["Docker Registry"]:::ci
    end
    JenkinsAgent -->|build image| Registry

    %% Infrastructure Provisioning
    subgraph "Infrastructure Provisioning"
        TerraformEC2["Terraform EC2 Provisioning"]:::infra
        TerraformEKS["Terraform EKS Provisioning"]:::infra
        AWS["AWS (VPC, EC2, EKS)"]:::infra
    end
    JenkinsMaster -->|trigger| TerraformEC2
    TerraformEC2 -->|provision| AWS
    JenkinsMaster -->|trigger| TerraformEKS
    TerraformEKS -->|provision| AWS

    %% GitOps
    subgraph "GitOps (ArgoCD)"
        ArgoCD["ArgoCD"]:::infra
    end
    GitOpsJenkinsfile -->|update manifests| GitHub
    ArgoCD -->|sync| GitHub
    ArgoCD -->|deploy| AWS

    %% Kubernetes Cluster
    subgraph "Kubernetes Cluster (EKS)"
        subgraph "Namespaces"
            AppNS["gemini-namespace"]:::k8s
            IngressNS["ingress-nginx"]:::k8s
            PromNS["prometheus"]:::obs
            ArgoNS["argocd"]:::infra
        end
        subgraph "Deployments & Pods"
            NextApp["Next.js App Pods"]:::k8s
            NginxIngress["NGINX Ingress Controller"]:::k8s
            CertManager["Cert-Manager"]:::k8s
            MetricsServer["Metrics Server"]:::obs
            Prometheus["Prometheus"]:::obs
            Grafana["Grafana"]:::obs
        end
        subgraph "Services"
            AppService["gemini-service"]:::k8s
            NginxService["nginx-service"]:::k8s
            ArgoCDServer["argocd-server"]:::infra
            PromService["prometheus-service"]:::obs
            GrafService["grafana-service"]:::obs
        end
        subgraph "ConfigMaps & Secrets"
            ConfigMap["ConfigMap"]:::k8s
            Secrets["Secrets"]:::k8s
        end
        Ingress["Ingress"]:::k8s
    end

    ArgoCD -->|applies| NextApp
    ArgoCD -->|applies| NginxIngress
    ArgoCD -->|applies| CertManager
    ArgoCD -->|applies| MetricsServer
    ArgoCD -->|applies| Prometheus
    ArgoCD -->|applies| Grafana

    Ingress -->|route HTTP traffic| NginxIngress
    NginxIngress -->|forward| NextApp
    NextApp -->|read| ConfigMap
    NextApp -->|read| Secrets
    NextApp -->|connect| AppService
    AppService -->|pod| NextApp

    NextApp -->|metrics| MetricsServer
    MetricsServer -->|scrape| NextApp
    Prometheus -->|collect| MetricsServer
    Grafana -->|visualize| Prometheus

    %% External Services
    subgraph "External Services"
        MongoDB["MongoDB"]:::external
        GoogleOAuth["Google OAuth"]:::external
    end
    NextApp -->|DB connection| MongoDB
    NextApp -->|auth| GoogleOAuth

    %% Application Code
    subgraph "Application Code (src/app)"
        Layout["layout.tsx"]:::app
        PageRoot["page.tsx"]:::app
        AuthRoute["[...nextauth]/route.ts"]:::app
    end

    %% Click Events
    click TerraformEC2 "https://github.com/amitabh-devops/dev-gemini-clone/tree/DevOps/terraform/"
    click TerraformEKS "https://github.com/amitabh-devops/dev-gemini-clone/tree/DevOps/Terraform-EKS-Deployment/"
    click JenkinsfileNode "https://github.com/amitabh-devops/dev-gemini-clone/tree/DevOps/Jenkinsfile"
    click GitOpsJenkinsfile "https://github.com/amitabh-devops/dev-gemini-clone/tree/DevOps/GitOps/Jenkinsfile"
    click Layout "https://github.com/amitabh-devops/dev-gemini-clone/blob/DevOps/src/app/layout.tsx"
    click PageRoot "https://github.com/amitabh-devops/dev-gemini-clone/blob/DevOps/src/app/page.tsx"
    click AuthRoute "https://github.com/amitabh-devops/dev-gemini-clone/blob/DevOps/src/app/api/auth/[...nextauth]/route.ts"
    click AppNS "https://github.com/amitabh-devops/dev-gemini-clone/blob/DevOps/kubernetes/gemini-namespace.yml"
    click NextApp "https://github.com/amitabh-devops/dev-gemini-clone/blob/DevOps/kubernetes/gemini-deployment.yml"
    click AppService "https://github.com/amitabh-devops/dev-gemini-clone/blob/DevOps/kubernetes/gemini-service.yml"
    click Ingress "https://github.com/amitabh-devops/dev-gemini-clone/blob/DevOps/kubernetes/gemini-ingress.yml"
    click NginxIngress "https://github.com/amitabh-devops/dev-gemini-clone/blob/DevOps/kubernetes/nginx-deployment.yml"
    click NginxService "https://github.com/amitabh-devops/dev-gemini-clone/blob/DevOps/kubernetes/nginx-service.yml"
    click CertManager "https://github.com/amitabh-devops/dev-gemini-clone/blob/DevOps/kubernetes/cert-issuer.yml"
    click ConfigMap "https://github.com/amitabh-devops/dev-gemini-clone/blob/DevOps/kubernetes/configmap.yml"
    click Secrets "https://github.com/amitabh-devops/dev-gemini-clone/blob/DevOps/kubernetes/secrets.yml"

    %% Styles
    classDef ci fill:#FFA500,stroke:#333,stroke-width:1px
    classDef infra fill:#32CD32,stroke:#333,stroke-width:1px
    classDef k8s fill:#87CEEB,stroke:#333,stroke-width:1px
    classDef obs fill:#9370DB,stroke:#333,stroke-width:1px
    classDef external fill:#A9A9A9,stroke:#333,stroke-width:1px
    classDef app fill:#ADD8E6,stroke:#333,stroke-width:1px
```
