# alessok/devops-proyecto-final architecture

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

- Interactive diagram: https://gitdiagram.com/alessok/devops-proyecto-final
- Repository: https://github.com/alessok/devops-proyecto-final

## Overview

##### Project Type and Purpose
- This is a full-stack web application comprising:
- A React/TypeScript frontend served by Nginx
- A Node.js/Express/TypeScript backend
- A PostgreSQL database with Flyway migrations
- CI/CD pipeline (Jenkins + GitHub Actions)
- Containerized deployment (Docker, docker-compose, Kubernetes)
- Monitoring (Prometheus + Grafana)
- The app appears to be an inventory management or CRUD admin system (categories, products, users).

##### File Structure Analysis
- Top-level “src” directory splits into “frontend” & “backend” subprojects, each with its own Dockerfile, package.json, tsconfig.
- “database” holds Flyway config & SQL migrations.
- “infrastructure/kubernetes” contains K8s manifests for namespace, backend, frontend, and Postgres.
- “docker-compose.yml” orchestrates local dev services (frontend, backend, Postgres).
- “.github/workflows/ci-cd.yml”, “Jenkinsfile”, and related scripts outline the CI/CD flow.
- “monitoring” directory defines Prometheus configs, alerting rules, and Grafana dashboards.
- “tests” holds API collection tests, end-to-end tests, integration scripts, and performance tests.

##### README Insights
- The README is a timestamp stub for Jenkins sync; no architecture details here.
- We infer tech stack and deployment patterns solely from file structure.

##### Main Components
a. Client Layer
- Web Browser/Mobile → React Frontend (served by Nginx)
b. Presentation/API Layer
- Frontend Container → REST API calls → Backend Container (Node/Express)
c. Data Layer
- Backend → Flyway-managed PostgreSQL
d. CI/CD Pipeline
- GitHub → GitHub Actions + Jenkins → Build & Test → Docker Registry → K8s Deployment
e. Infrastructure/Orchestration
- Kubernetes Cluster:
- Frontend Pod(s)
- Backend Pod(s)
- Postgres Pod
- ConfigMaps/Secrets
- docker-compose (dev/local)
f. Monitoring & Logging
- Prometheus scrapes metrics from backend & Kubernetes
- Alertmanager rules (Prometheus alerts)

##### Relationships & Interactions
- User’s browser ↔ HTTP(S) ↔ Nginx (frontend) ↔ JavaScript app ↔ HTTP REST ↔ Express server
- Express server ↔ SQL queries ↔ Postgres
- CI/CD triggers on commit → runs tests (unit, E2E, performance) → builds Docker images → pushes to registry → deploys to K8s
- K8s liveness/readiness health checks ensure pods are healthy
- Prometheus scrapes:
- /metrics endpoint on backend
- K8s API
Grafana reads from Prometheus → dashboards & alerts

##### Architectural Patterns & Principles
- Layered architecture: presentation (frontend), application (backend), data (DB).
- Micro-layer separation: distinct containers for each service.
- Infrastructure as Code: K8s manifests, docker-compose, Flyway migrations.
- Continuous Delivery: automated CI/CD pipelines.
- Observability: metrics, dashboards, alerting.

##### Technologies & Libraries
- Frontend: React, TypeScript, React-Router, Context API
- Backend: Node.js, Express, TypeScript, Jest tests, ESLint, Flyway, pg library
- Database: PostgreSQL
- CI/CD: Jenkins, GitHub Actions, sonar-scanner, Groovy init script
- Containerization: Docker, docker-compose, Kubernetes
- Monitoring: Prometheus, Grafana
- Testing: Jest, Supertest (API tests), Playwright or similar for E2E, Artillery for performance

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Browser["Web Browser/Mobile"]:::external
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Nginx["Nginx (Static Server)"]:::frontend
        ReactApp["React Frontend"]:::frontend
    end

    %% API Layer
    subgraph "Application Layer"
        direction TB
        Backend["Express API"]:::backend
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        Postgres(("PostgreSQL")):::database
        Flyway["Flyway Migrations"]:::database
    end

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline" 
        direction TB
        GitHub["GitHub"]:::devops
        Actions["GitHub Actions"]:::devops
        Jenkins["Jenkins"]:::devops
        Build["Build & Test"]:::devops
        Registry["Docker Registry"]:::devops
        Deploy["Deploy to K8s"]:::devops
    end

    %% Infrastructure
    subgraph "Infrastructure / Orchestration"
        direction TB
        K8sCluster["Kubernetes Cluster"]:::infra
        DockerCompose["docker-compose (Local Dev)"]:::infra
        subgraph "K8s Resources"
            direction TB
            FEpod["Frontend Pod"]:::infra
            BEpod["Backend Pod"]:::infra
            DBpod["Postgres Pod"]:::infra
            Configs["ConfigMaps & Secrets"]:::infra
        end
    end

    %% Monitoring
    subgraph "Monitoring & Logging"
        direction TB
        Prometheus["Prometheus"]:::monitoring
        Grafana["Grafana"]:::monitoring
        Alertmanager["Alertmanager"]:::monitoring
    end

    %% Connections
    Browser -->|"HTTPS"| Nginx
    Nginx -->|"Serves React App"| ReactApp
    ReactApp -->|"REST API Calls"| Backend
    Backend -->|"SQL Queries"| Postgres
    Backend -->|"Runs Migrations"| Flyway

    GitHub -->|"Push Code"| Actions
    Actions -->|"Run CI Tests"| Build
    Build -->|"Build Docker Images"| Registry
    Registry -->|"Images"| Deploy
    Deploy -->|"Apply Manifests"| K8sCluster

    K8sCluster --> FEpod
    K8sCluster --> BEpod
    K8sCluster --> DBpod
    K8sCluster --> Configs

    DockerCompose -.-> ReactApp
    DockerCompose -.-> Backend
    DockerCompose -.-> Postgres

    Prometheus -->|"Scrapes Metrics"| Backend
    Prometheus -->|"Scrapes K8s API"| K8sCluster
    Grafana -->|"Visualizes Metrics"| Prometheus
    Alertmanager -->|"Alerts on Rules"| Prometheus

    %% Click Events
    click ReactApp "https://github.com/alessok/devops-proyecto-final/tree/main/src/frontend"
    click Nginx "https://github.com/alessok/devops-proyecto-final/blob/main/src/frontend/nginx.conf"
    click Nginx "https://github.com/alessok/devops-proyecto-final/tree/main/src/frontend/Dockerfile"
    click ReactApp "https://github.com/alessok/devops-proyecto-final/blob/main/src/frontend/public/index.html"
    click ReactApp "https://github.com/alessok/devops-proyecto-final/blob/main/src/frontend/src/index.tsx"
    click ReactApp "https://github.com/alessok/devops-proyecto-final/tree/main/src/frontend/src/components"
    click ReactApp "https://github.com/alessok/devops-proyecto-final/tree/main/src/frontend/src/pages"
    click ReactApp "https://github.com/alessok/devops-proyecto-final/blob/main/src/frontend/src/services/apiService.ts"
    click ReactApp "https://github.com/alessok/devops-proyecto-final/blob/main/src/frontend/src/types/index.ts"

    click Backend "https://github.com/alessok/devops-proyecto-final/tree/main/src/backend"
    click Backend "https://github.com/alessok/devops-proyecto-final/tree/main/src/backend/Dockerfile"
    click Backend "https://github.com/alessok/devops-proyecto-final/blob/main/src/backend/src/index.ts"
    click Backend "https://github.com/alessok/devops-proyecto-final/blob/main/src/backend/src/config/database.ts"
    click Backend "https://github.com/alessok/devops-proyecto-final/tree/main/src/backend/src/controllers"
    click Backend "https://github.com/alessok/devops-proyecto-final/tree/main/src/backend/src/routes"
    click Backend "https://github.com/alessok/devops-proyecto-final/tree/main/src/backend/src/services"
    click Backend "https://github.com/alessok/devops-proyecto-final/tree/main/src/backend/src/middleware"
    click Backend "https://github.com/alessok/devops-proyecto-final/tree/main/src/backend/src/validation"
    click Backend "https://github.com/alessok/devops-proyecto-final/tree/main/src/backend/src/types"
    click Backend "https://github.com/alessok/devops-proyecto-final/tree/main/src/backend/src/__tests__"

    click Flyway "https://github.com/alessok/devops-proyecto-final/blob/main/database/flyway.conf"
    click Flyway "https://github.com/alessok/devops-proyecto-final/tree/main/database/migrations"

    click DockerCompose "https://github.com/alessok/devops-proyecto-final/blob/main/docker-compose.yml"
    click K8sCluster "https://github.com/alessok/devops-proyecto-final/tree/main/infrastructure/kubernetes"

    click Actions "https://github.com/alessok/devops-proyecto-final/blob/main/.github/workflows/ci-cd.yml"
    click Jenkins "https://github.com/alessok/devops-proyecto-final/tree/main/Jenkinsfile"
    click Jenkins "https://github.com/alessok/devops-proyecto-final/blob/main/Dockerfile.jenkins"
    click Jenkins "https://github.com/alessok/devops-proyecto-final/blob/main/init-jenkins-config.groovy"

    click Prometheus "https://github.com/alessok/devops-proyecto-final/blob/main/monitoring/prometheus.yml"
    click Prometheus "https://github.com/alessok/devops-proyecto-final/blob/main/monitoring/prometheus-alerts.yml"
    click Grafana "https://github.com/alessok/devops-proyecto-final/blob/main/monitoring/grafana/datasources/prometheus.yml"
    click Grafana "https://github.com/alessok/devops-proyecto-final/blob/main/monitoring/grafana/dashboards/dashboard.yml"
    click Grafana "https://github.com/alessok/devops-proyecto-final/blob/main/monitoring/grafana/dashboards/inventory-dashboard-v2.json"
    click Grafana "https://github.com/alessok/devops-proyecto-final/blob/main/monitoring/grafana/dashboards/inventory-simple.json"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#6CA0DC,color:#000
    classDef backend fill:#E8F0FF,stroke:#4A90E2,color:#000
    classDef database fill:#FFF4E5,stroke:#E2A400,color:#000
    classDef devops fill:#FFECD1,stroke:#E08E1A,color:#000
    classDef infra fill:#F3E8FF,stroke:#9B59B6,color:#000
    classDef monitoring fill:#E8FFEA,stroke:#27AE60,color:#000
    classDef external fill:none,stroke-dasharray: 5 5,stroke:#999,color:#000
```
