# darkzorro79/rebrain_devops architecture

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

- Interactive diagram: https://gitdiagram.com/darkzorro79/rebrain_devops
- Repository: https://github.com/darkzorro79/rebrain_devops

## Overview

##### Overview of the Project Purpose and Types
- This project contains multiple delivery scenarios for a TODO application.
- The TODO application consists of several components: a PostgreSQL database, a backend (API) service, a frontend application (built with npm), a worker/cleaner process, and an Nginx server acting as a reverse proxy.
- Four deployment workflows are covered:
- dz1: A “manual” deployment and configuration scenario using Ansible playbooks.
- dz2: A GitLab CI/CD integration scenario including automated deployment pipelines.
- dz3: A Docker container deployment scenario where each component (postgres, back, front, worker) runs inside its own container; nginx remains on the host.
- dz4: A Docker Swarm cluster deployment where multiple nodes (manager and workers) run containers in an overlay network using stacks.

##### Analyzing the File Structure for Architectural Insights
- The top-level directories “dz1”, “dz2”, “dz3”, and “dz4” clearly separate the different deployment strategies.
- Within each “dz”:
- Playbooks, inventory files, and variable groups (.yml) indicate a heavy reliance on Ansible as the configuration management and orchestration tool.
- The presence of many “templates” or “.j2” files shows that configuration files for services (like nginx.conf, backend.service, worker.service, Dockerfiles, GitLab CI files, etc.) are dynamically rendered.
- In dz4, the “roles” directory (especially for docker-swarm and gitlab-setup) suggests modular roles for setting up more complex swarm clusters and GitLab integrations.

##### Specific Elements
- Clear labels for each component/module (e.g., POSTGRES, BACK, FRONT, WORKER, NGINX, GITLAB, ANSIBLE).
- Notations that denote:
- The Docker “app” network in containerized setups.
- The overlay network in the swarm cluster.
- The distinct phases: manual deployment (dz1), CI/CD integration (dz2), container deployment (dz3), and cluster orchestration (dz4).
- Infrastructure components (database, containers, servers)
- Control components (Ansible playbooks, CI/CD pipelines)
- Environment-specific layers (host machine versus container or cluster nodes)

##### Final Reminder
- Every architectural component is clearly represented and that the relationships (dependencies, connectivity, and data/control flows) are explicitly drawn.
- Use annotations if necessary to explain the role of specific directories (like how “roles” in dz4 encapsulate docker swarm setup and GitLab configuration).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global User Node
    User["User Request"]:::control

    %% dz1: Manual Deployment
    subgraph "dz1: Manual Deployment"
        dz1_ansible["ANSIBLE Deployment Controller"]:::control
        dz1_postgres["POSTGRES Database"]:::service
        dz1_back["BACK (API) 8080"]:::service
        dz1_front["FRONT (npm)"]:::service
        dz1_worker["WORKER (cleaner.py)"]:::service
        dz1_nginx["NGINX Reverse Proxy"]:::proxy
    end

    %% Connections for dz1
    User -->|"routes"| dz1_nginx
    dz1_nginx -->|"forwards to"| dz1_front
    dz1_nginx -->|"forwards to"| dz1_back
    dz1_back -->|"queries"| dz1_postgres
    dz1_ansible -->|"deploys"| dz1_postgres
    dz1_ansible -->|"deploys"| dz1_back
    dz1_ansible -->|"deploys"| dz1_front
    dz1_ansible -->|"deploys"| dz1_worker
    dz1_ansible -->|"configures"| dz1_nginx
    dz1_ansible -->|"configures"| User

    %% dz2: GitLab CI/CD Deployment
    subgraph "dz2: CI/CD Deployment"
        dz2_gitlab["GITLAB Server"]:::ci
        dz2_ansible["ANSIBLE Deployment"]:::control
        dz2_back["BACK Service"]:::service
        dz2_front["FRONT Application"]:::service
        dz2_worker["WORKER Process"]:::service
        dz2_nginx["NGINX Configuration"]:::proxy
        dz2_ci_back["BACK CI/CD Pipeline"]:::ci
        dz2_ci_front["FRONT CI/CD Pipeline"]:::ci
        dz2_ci_worker["WORKER CI/CD Pipeline"]:::ci
    end

    %% Connections for dz2
    User -->|"accesses"| dz2_nginx
    dz2_gitlab -->|"triggers"| dz2_ci_back
    dz2_gitlab -->|"triggers"| dz2_ci_front
    dz2_gitlab -->|"triggers"| dz2_ci_worker
    dz2_ansible -->|"deploys"| dz2_back
    dz2_ansible -->|"deploys"| dz2_front
    dz2_ansible -->|"deploys"| dz2_worker
    dz2_ansible -->|"configures"| dz2_nginx
    dz2_ci_back -->|"builds"| dz2_back
    dz2_ci_front -->|"builds"| dz2_front
    dz2_ci_worker -->|"builds"| dz2_worker

    %% dz3: Docker Container Deployment
    subgraph "dz3: Docker Container Deployment"
        dz3_network["Docker Network 'app'"]:::container
        dz3_postgres["Container: POSTGRES"]:::container
        dz3_back["Container: BACK (API)"]:::container
        dz3_front["Container: FRONT (npm)"]:::container
        dz3_worker["Container: WORKER"]:::container
        dz3_nginx["Host NGINX Container"]:::proxy
    end

    %% Connections for dz3
    User -->|"hits"| dz3_nginx
    dz3_nginx -->|"routes to"| dz3_front
    dz3_nginx -->|"routes to"| dz3_back
    dz3_back -->|"accesses"| dz3_postgres
    dz3_back -->|"joins"| dz3_network
    dz3_front -->|"joins"| dz3_network
    dz3_worker -->|"joins"| dz3_network
    dz3_postgres -->|"joins"| dz3_network
    dz3_nginx -->|"joins"| dz3_network

    %% dz4: Docker Swarm Cluster Deployment
    subgraph "dz4: Docker Swarm Cluster Deployment"
        dz4_ansible["ANSIBLE (Swarm Deployment)"]:::control
        dz4_overlay["Overlay Network 'app'"]:::cluster
        dz4_manager["Manager Node"]:::cluster
        dz4_worker1["Worker Node 1"]:::cluster
        dz4_worker2["Worker Node 2"]:::cluster
        dz4_postgres["Service: POSTGRES"]:::service
        dz4_back["Service: BACK"]:::service
        dz4_front["Service: FRONT"]:::service
        dz4_worker["Service: WORKER"]:::service
        dz4_nginx["Service: NGINX"]:::proxy
    end

    %% Connections for dz4
    User -->|"requests"| dz4_nginx
    dz4_ansible -->|"deploys"| dz4_postgres
    dz4_ansible -->|"deploys"| dz4_back
    dz4_ansible -->|"deploys"| dz4_front
    dz4_ansible -->|"deploys"| dz4_worker
    dz4_ansible -->|"deploys"| dz4_nginx
    dz4_manager -->|"connects to"| dz4_overlay
    dz4_worker1 -->|"connects to"| dz4_overlay
    dz4_worker2 -->|"connects to"| dz4_overlay
    dz4_nginx -->|"routes to"| dz4_front
    dz4_nginx -->|"routes to"| dz4_back
    dz4_back -->|"queries"| dz4_postgres

    %% Click Events for Component Mapping

    %% PostgreSQL Database
    %% (Implicit for dz3 and dz4 via container/service definitions are not given explicit file mappings.)

    %% Backend (API) Service
    click dz1_back "https://github.com/darkzorro79/rebrain_devops/blob/main/dz1/playbook/templates/backend.service.j2"
    click dz2_back "https://github.com/darkzorro79/rebrain_devops/blob/main/dz2/ansible_0/templates/back.service.j2"
    click dz3_back "https://github.com/darkzorro79/rebrain_devops/blob/main/dz3/templates/back-dockerfile.j2"
    click dz4_back "https://github.com/darkzorro79/rebrain_devops/blob/main/dz4/roles/gitlab-setup/templates/back-dockerfile.j2"

    %% Frontend Application
    click dz2_front "https://github.com/darkzorro79/rebrain_devops/blob/main/dz2/ansible/templates/front-gitlab-ci.yml.j2"
    click dz3_front "https://github.com/darkzorro79/rebrain_devops/blob/main/dz3/templates/front-dockerfile.j2"
    click dz4_front "https://github.com/darkzorro79/rebrain_devops/blob/main/dz4/roles/gitlab-setup/templates/front-dockerfile.j2"

    %% Worker Process
    click dz1_worker "https://github.com/darkzorro79/rebrain_devops/blob/main/dz1/playbook/templates/worker.service.j2"
    click dz2_worker "https://github.com/darkzorro79/rebrain_devops/blob/main/dz2/ansible_0/templates/worker.service.j2"
    click dz3_worker "https://github.com/darkzorro79/rebrain_devops/blob/main/dz3/templates/worker-dockerfile.j2"
    click dz4_worker "https://github.com/darkzorro79/rebrain_devops/blob/main/dz4/roles/gitlab-setup/templates/worker-dockerfile.j2"

    %% NGINX Reverse Proxy
    click dz1_nginx "https://github.com/darkzorro79/rebrain_devops/blob/main/dz1/playbook/templates/nginx.conf.j2"
    click dz2_nginx "https://github.com/darkzorro79/rebrain_devops/blob/main/dz2/ansible_0/templates/nginx.conf.j2"
    click dz3_nginx "https://github.com/darkzorro79/rebrain_devops/blob/main/dz3/templates/nginx.conf.j2"
    click dz4_nginx "https://github.com/darkzorro79/rebrain_devops/blob/main/dz4/templates/nginx.conf.j2"

    %% Ansible Playbook Orchestration (Deployment Controller)
    click dz1_ansible "https://github.com/darkzorro79/rebrain_devops/tree/main/dz1/playbook/"
    click dz2_ansible "https://github.com/darkzorro79/rebrain_devops/tree/main/dz2/ansible/"
    click dz4_ansible "https://github.com/darkzorro79/rebrain_devops/blob/main/dz4/deploy-swarm.yml"

    %% CI/CD Pipelines (GitLab Integration)
    click dz2_ci_back "https://github.com/darkzorro79/rebrain_devops/blob/main/dz2/ansible/templates/back-gitlab-ci.yml.j2"
    click dz2_ci_front "https://github.com/darkzorro79/rebrain_devops/blob/main/dz2/ansible/templates/front-gitlab-ci.yml.j2"
    click dz2_ci_worker "https://github.com/darkzorro79/rebrain_devops/blob/main/dz2/ansible/templates/worker-gitlab-ci.yml.j2"
    click dz3_back "https://github.com/darkzorro79/rebrain_devops/blob/main/dz3/templates/back-ci-cd.yml.j2"
    click dz3_front "https://github.com/darkzorro79/rebrain_devops/blob/main/dz3/templates/front-ci-cd.yml.j2"
    click dz3_worker "https://github.com/darkzorro79/rebrain_devops/blob/main/dz3/templates/worker-ci-cd.yml.j2"
    
    %% Frontend additional NGINX config (where applicable)
    click dz3_front "https://github.com/darkzorro79/rebrain_devops/blob/main/dz3/templates/front-nginx.j2"
    click dz4_front "https://github.com/darkzorro79/rebrain_devops/blob/main/dz4/roles/gitlab-setup/templates/front-nginx.j2"

    %% End of Diagram

    %% Styles
    classDef control fill:#a9d18e,stroke:#333,stroke-width:2px;
    classDef service fill:#9fc5e8,stroke:#333,stroke-width:2px;
    classDef proxy fill:#c6efce,stroke:#333,stroke-width:2px;
    classDef ci fill:#ead1dc,stroke:#333,stroke-width:2px;
    classDef container fill:#fce5cd,stroke:#333,stroke-width:2px;
    classDef cluster fill:#d9ead3,stroke:#333,stroke-width:2px;
```
