# abeqqalmarouane/devops-capstone-project architecture

> Architecture diagram of the GitHub repository abeqqalmarouane/devops-capstone-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abeqqalmarouane/devops-capstone-project
- Repository: https://github.com/abeqqalmarouane/devops-capstone-project

## Overview

##### Project Type and Purpose
- This is a standalone RESTful microservice template built with Python 3.9 and Flask.
- It implements CRUD operations on an Account model (MVC pattern), backed by a Postgres database.
- It’s designed for DevOps capstone exercises: containerized development, CI/CD via Tekton, and Kubernetes deployment.

##### High-Level File Structure
- `/service` – Flask app package
– `models.py` (Model & DB logic)
– `routes.py` (Controller/REST API)
– `common/` (error handlers, logging, CLI commands)
– `config.py` (Flask configuration)
- `/tests` – unit tests for CLI, models, routes (TDD style)
- `/bin` – environment setup script
- `/deploy` – Kubernetes/Postgres templates
- `tekton/` – Tekton Pipeline, Tasks, PVC definitions
- `.devcontainer/` – VSCode Remote-Container definitions
- `Makefile`, `Procfile`, `requirements.txt` – build, run, and dependency specs

##### Key Architectural Insights from README
- MVC separation: Models ↔ Routes
- Dockerized Postgres for local dev (`make db`)
- Local K3D Kubernetes + Tekton for CI/CD
- Target: ≥95% code coverage via TDD

a. Developer Environment
– VSCode Remote Container (.devcontainer)
– Local virtualenv (bin/setup.sh)
b. Source Control & CI/CD
– GitHub Repo (push triggers Tekton)
– Tekton Pipeline
- Tasks: lint, test, build Docker image, push to registry
- PVC for Postgres data in CI/CD cluster
c. Container Registry
– Holds built Flask service image
d. Kubernetes Cluster
– Deployment of:
1. Flask Service Pod (environment variables from ConfigMap/Secrets)
2. Postgres Pod (PVC from `pvc.yaml`)
– Service (ClusterIP/LoadBalancer) routing traffic to Flask Pod
e. External Clients
– CURL/HTTP clients consuming the REST API

##### Interactions and Data Flow
1. Developer codes → commits to GitHub
2. GitHub webhook → Tekton Pipeline
3. Pipeline Tasks execute in order:
a. `pip install` & `make test` → unit tests (95% coverage)
b. Lint & security scans
c. Build Docker image → push to registry
d. Apply K8s manifests (`deploy/` + Tekton deploy tasks)
4. Kubernetes deploys Flask + Postgres Pods
5. Flask service connects to Postgres via SQLAlchemy (Model layer)
6. External REST clients ↔ Flask routes ↔ Models ↔ DB

##### Architectural Patterns & Principles
- MVC: clear separation of concerns
- Twelve-Factor App: config in environment, backing services as attached resources
- Immutable Infrastructure: container images, declarative K8s manifests
- CI/CD as code: Tekton YAML files under version control

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer Environment (Blue)
    subgraph "Developer Environment"
        direction TB
        DevContainer["VSCode Remote Container"]:::dev
        LocalEnv["Local Virtualenv (bin/setup.sh)"]:::dev
    end

    %% Source Control & CI/CD (Green)
    GitHub["GitHub Repo"]:::ci
    subgraph "Tekton CI/CD Pipeline"
        direction TB
        Pipeline["Tekton Pipeline (pipeline.yaml)"]:::ci
        Tasks["Tekton Tasks (tasks.yaml)"]:::ci
        PVC_CICD["Tekton PVC for Postgres (pvc.yaml)"]:::ci
        Pipeline --> Tasks
        Pipeline --> PVC_CICD
    end

    Registry["Container Registry"]:::ci

    %% Runtime (Orange)
    subgraph "Kubernetes Cluster"
        direction TB
        ConfigMap["ConfigMap/Secrets"]:::runtime
        ServicePod["Flask Service Pod"]:::runtime
        PostgresPod["Postgres Pod"]:::runtime
        DBPVC[[Postgres PVC]]:::db
        Service["Service (ClusterIP/LoadBalancer)"]:::runtime
        ConfigMap --> ServicePod
        DBPVC --> PostgresPod
        ServicePod --> PostgresPod
        Service --> ServicePod
    end

    %% External Client
    Client["External REST Client (curl/http)"]:::runtime

    %% File Structure & Code Components under service/
    subgraph "Flask Service (MVC App)"
        direction TB
        Models["models.py"]:::code
        Routes["routes.py"]:::code
        Config["config.py"]:::code
        CommonDir["common/"]:::code
        CLI["cli_commands.py"]:::code
        ErrorHandlers["error_handlers.py"]:::code
        LogHandlers["log_handlers.py"]:::code
        Status["status.py"]:::code
        Models --> Routes
        Routes --> Models
    end

    subgraph "Unit Tests (tests/)"
        direction TB
        TestCLI["test_cli_commands.py"]:::test
        TestModels["test_models.py"]:::test
        TestRoutes["test_routes.py"]:::test
    end

    %% Other Files
    Makefile["Makefile"]:::code
    Procfile["Procfile"]:::code
    Requirements["requirements.txt"]:::code
    DevContainerConfig[".devcontainer/devcontainer.json"]:::dev
    DevContainerDockerfile[".devcontainer/Dockerfile"]:::dev
    SetupScript["bin/setup.sh"]:::dev
    DeployTemplates["deploy/"]:::runtime
    PostgresTemplate["postgresql-ephemeral-template.json"]:::runtime

    %% Flows
    DevContainer --> LocalEnv
    LocalEnv --> Models
    Models --> GitHub
    GitHub --> Pipeline
    Pipeline --> Registry
    Registry --> ServicePod
    ServicePod --> DBPVC
    Client --> Service
    Service --> Models

    %% Click Events
    click Models "https://github.com/abeqqalmarouane/devops-capstone-project/blob/main/service/models.py"
    click Routes "https://github.com/abeqqalmarouane/devops-capstone-project/blob/main/service/routes.py"
    click Config "https://github.com/abeqqalmarouane/devops-capstone-project/blob/main/service/config.py"
    click CommonDir "https://github.com/abeqqalmarouane/devops-capstone-project/tree/main/service/common/"
    click CLI "https://github.com/abeqqalmarouane/devops-capstone-project/blob/main/service/common/cli_commands.py"
    click ErrorHandlers "https://github.com/abeqqalmarouane/devops-capstone-project/blob/main/service/common/error_handlers.py"
    click LogHandlers "https://github.com/abeqqalmarouane/devops-capstone-project/blob/main/service/common/log_handlers.py"
    click Status "https://github.com/abeqqalmarouane/devops-capstone-project/blob/main/service/common/status.py"
    click TestCLI "https://github.com/abeqqalmarouane/devops-capstone-project/blob/main/tests/test_cli_commands.py"
    click TestModels "https://github.com/abeqqalmarouane/devops-capstone-project/blob/main/tests/test_models.py"
    click TestRoutes "https://github.com/abeqqalmarouane/devops-capstone-project/blob/main/tests/test_routes.py"
    click DevContainer "https://github.com/abeqqalmarouane/devops-capstone-project/tree/main/ .devcontainer/"
    click DevContainerDockerfile "https://github.com/abeqqalmarouane/devops-capstone-project/tree/main/.devcontainer/Dockerfile"
    click DevContainerConfig "https://github.com/abeqqalmarouane/devops-capstone-project/blob/main/.devcontainer/devcontainer.json"
    click SetupScript "https://github.com/abeqqalmarouane/devops-capstone-project/blob/main/bin/setup.sh"
    click Pipeline "https://github.com/abeqqalmarouane/devops-capstone-project/blob/main/tekton/pipeline.yaml"
    click Tasks "https://github.com/abeqqalmarouane/devops-capstone-project/blob/main/tekton/tasks.yaml"
    click PVC_CICD "https://github.com/abeqqalmarouane/devops-capstone-project/blob/main/tekton/pvc.yaml"
    click DeployTemplates "https://github.com/abeqqalmarouane/devops-capstone-project/tree/main/deploy/"
    click PostgresTemplate "https://github.com/abeqqalmarouane/devops-capstone-project/blob/main/deploy/postgresql-ephemeral-template.json"
    click Makefile "https://github.com/abeqqalmarouane/devops-capstone-project/tree/main/Makefile"
    click Procfile "https://github.com/abeqqalmarouane/devops-capstone-project/tree/main/Procfile"
    click Requirements "https://github.com/abeqqalmarouane/devops-capstone-project/blob/main/requirements.txt"

    %% Styles
    classDef dev fill:#a2d2ff,stroke:#1e3a5f,color:#000;
    classDef ci fill:#b7e4c7,stroke:#1a4314,color:#000;
    classDef runtime fill:#ffdfa2,stroke:#7a4f01,color:#000;
    classDef db fill:#ffe5d9,stroke:#a74f00,color:#000;
    classDef code fill:#e9ecef,stroke:#6c757d,color:#000;
    classDef test fill:#f8d7da,stroke:#721c24,color:#000
```
