# palash2198/two-tier-flask-app architecture

> Architecture diagram of the GitHub repository palash2198/two-tier-flask-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/palash2198/two-tier-flask-app
- Repository: https://github.com/palash2198/two-tier-flask-app

## Overview

##### Project type and purpose
- This is a two-tier full-stack web application built with Flask (Python) on the backend and MySQL as the datastore.
- It supports two deployment modes:
a. Local development using Docker Compose
b. Production-style deployment onto an AWS EKS (Kubernetes) cluster via the manifests in `eks-manifests/` or `k8s/`.
- A Jenkinsfile is included, indicating a CI/CD pipeline to build and push container images, then deploy to Kubernetes.

##### File structure
- Top level:
- Dockerfile & Dockerfile-multistage – container image definitions for the Flask app
- docker-compose.yml – local two-tier orchestration
- Jenkinsfile & Makefile – CI/CD automation and build scripts
- app.py & templates/index.html – Flask application code and frontend template
- requirements.txt – Python dependencies
- eks-manifests/ & k8s/ – Kubernetes deployment manifests (ConfigMaps, Secrets, Deployments, Services, PV/PVC definitions)
- message.sql – example SQL statement to initialize the `messages` table
- Patterns: two-tier (web + database), containerization, configuration-as-code (K8s YAMLs), CI/CD integration.

##### README for insights
- Confirms two deployment workflows and environment variable setup
- Describes runtime endpoints:
- Frontend at http://localhost (serving index.html via Flask)
- Backend API at http://localhost:5000 (e.g., `/insert_sql`)
- Emphasizes need for a `messages` table in MySQL
- Points out manual vs. automated (Docker Compose vs. network-based Docker run) launches

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        Git["Git Repository"]:::repo
        Jenkins["Jenkins"]:::ci
        Registry["Container Registry"]:::registry
        Git -->|"push trigger"| Jenkins
        Jenkins -->|"build image"| Registry
    end

    %% Production Environment
    subgraph "Production (AWS EKS)" 
        AWS["AWS EKS Cluster"]:::cloud
        Registry -->|"deploy manifests"| AWS

        subgraph "Kubernetes Namespace"
            LB["LoadBalancer Service"]:::service
            FSvc["Flask Service (ClusterIP)"]:::service
            FPod["Flask Pod"]:::pod
            Config["ConfigMap"]:::config
            Secret["Secret"]:::secret
            MSvc["MySQL Service (ClusterIP)"]:::service
            MPod["MySQL Pod"]:::pod
            PVC["Persistent Volume Claim"]:::storage
            PV["Persistent Volume"]:::storage
        end

        AWS --> LB
        LB --> FPod
        FPod -->|"env vars"| Config
        FPod -->|"env vars"| Secret
        FPod --> FSvc
        FSvc -->|connects| MPod
        MPod --> MSvc
        MPod --> PVC
        PVC --> PV
    end

    %% Local Development
    subgraph "Local Development (Docker Compose)"
        Browser["User Browser"]:::client
        DCC["Docker Compose Network"]:::compose
        FL["Flask Container"]:::pod
        MY["MySQL Container"]:::pod
        Browser -->|HTTP| FL
        FL -->|SQL| MY
        FL --> DCC
        MY --> DCC
    end

    %% Click Events
    click app_py "https://github.com/palash2198/two-tier-flask-app/blob/master/app.py"
    click requirements_txt "https://github.com/palash2198/two-tier-flask-app/blob/master/requirements.txt"
    click index_html "https://github.com/palash2198/two-tier-flask-app/blob/master/templates/index.html"
    click Dockerfile "https://github.com/palash2198/two-tier-flask-app/tree/master/Dockerfile"
    click DockerfileMultistage "https://github.com/palash2198/two-tier-flask-app/tree/master/Dockerfile-multistage"
    click message_sql "https://github.com/palash2198/two-tier-flask-app/blob/master/message.sql"
    click docker_compose "https://github.com/palash2198/two-tier-flask-app/blob/master/docker-compose.yml"
    click Jenkinsfile "https://github.com/palash2198/two-tier-flask-app/tree/master/Jenkinsfile"
    click Makefile "https://github.com/palash2198/two-tier-flask-app/tree/master/Makefile"
    click eksAppDeploy "https://github.com/palash2198/two-tier-flask-app/blob/master/eks-manifests/two-tier-app-deployment.yml"
    click eksAppSvc "https://github.com/palash2198/two-tier-flask-app/blob/master/eks-manifests/two-tier-app-svc.yml"
    click eksMySQLDeploy "https://github.com/palash2198/two-tier-flask-app/blob/master/eks-manifests/mysql-deployment.yml"
    click eksMySQLSvc "https://github.com/palash2198/two-tier-flask-app/blob/master/eks-manifests/mysql-svc.yml"
    click eksConfig "https://github.com/palash2198/two-tier-flask-app/blob/master/eks-manifests/mysql-configmap.yml"
    click eksSecret "https://github.com/palash2198/two-tier-flask-app/blob/master/eks-manifests/mysql-secrets.yml"
    click k8sAppDeploy "https://github.com/palash2198/two-tier-flask-app/blob/master/k8s/two-tier-app-deployment.yml"
    click k8sAppPod "https://github.com/palash2198/two-tier-flask-app/blob/master/k8s/two-tier-app-pod.yml"
    click k8sAppSvc "https://github.com/palash2198/two-tier-flask-app/blob/master/k8s/two-tier-app-svc.yml"
    click k8sMySQLDeploy "https://github.com/palash2198/two-tier-flask-app/blob/master/k8s/mysql-deployment.yml"
    click k8sMySQLSvc "https://github.com/palash2198/two-tier-flask-app/blob/master/k8s/mysql-svc.yml"
    click k8sPV "https://github.com/palash2198/two-tier-flask-app/blob/master/k8s/mysql-pv.yml"
    click k8sPVC "https://github.com/palash2198/two-tier-flask-app/blob/master/k8s/mysql-pvc.yml"
    click README "https://github.com/palash2198/two-tier-flask-app/blob/master/README.md"
    click k8sREADME "https://github.com/palash2198/two-tier-flask-app/blob/master/k8s/README.md"

    %% Styles
    classDef repo fill:#e3f2fd,stroke:#90caf9;
    classDef ci fill:#e8f5e9,stroke:#66bb6a;
    classDef registry fill:#fff3e0,stroke:#ffb74d;
    classDef cloud fill:#ede7f6,stroke:#9575cd,stroke-dasharray: 5 5;
    classDef service fill:#e0f7fa,stroke:#26c6da;
    classDef pod fill:#fffde7,stroke:#fdd835;
    classDef config fill:#f5f5f5,stroke:#bdbdbd;
    classDef secret fill:#fce4ec,stroke:#f06292;
    classDef storage fill:#fff8e1,stroke:#ffca28;
    classDef client fill:#bbdefb,stroke:#2196f3;
    classDef compose fill:#fafafa,stroke:#9e9e9e,stroke-dasharray: 4 2;
```
