# ardillachiki/2_intento_dekker architecture

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

- Interactive diagram: https://gitdiagram.com/ardillachiki/2_intento_dekker
- Repository: https://github.com/ardillachiki/2_intento_dekker

## Overview

##### Project Type and Purpose
- This is a single‐module Python simulation tool (CLI) illustrating Dekker’s mutual exclusion algorithm.
- It is neither a web app nor a microservice; it’s a self‐contained curses‐based, dual‐thread simulation.

##### High-Level Components
a. Main Controller (main.py)
b. UI Subsystem (curses windows)
c. Two Simulated Processes (threads or loop instances)
d. Shared State (flags: proceso1_puede_entrar, proceso2_puede_entrar; turn variable)
e. User Input Handler (waiting for Enter to cancel)

##### Component Interactions
- The Main Controller initializes the curses UI, shared flags, and launches the two process threads plus the input watcher.
- Each Simulated Process:
- Reads/writes shared flags and turn variable
- Requests CRS (Critical Section) entry per Dekker’s logic
- Writes its character (‘+’ or ‘*’) into its dedicated window via the UI subsystem
- The Shared State acts as the coordination medium enforcing mutual exclusion.
- The User Input Handler monitors keyboard; on Enter it sets `cancelar`, signaling both processes to exit their loops.

##### Architectural Patterns and Principles
- Concurrency with explicit shared memory synchronization (Dekker’s algorithm).
- Separation of concerns: UI rendering is decoupled from algorithm logic.
- Single‐responsibility threads: each process only runs the entry/critical/exit loop.
- Controlled shutdown via a shared cancellation flag.

## Diagram (Mermaid)

```mermaid
graph TD
    MC["Main Controller"]:::main
    Shared["Shared State (flags & turn)"]:::state
    P1["Process 1 (+)"]:::process
    P2["Process 2 (*)"]:::process
    UI["UI Subsystem"]:::ui
    UIHandler["User Input Handler"]:::ui
    Makefile["Makefile"]:::doc
    README["README.md"]:::doc

    MC -->|"init flags & turn"| Shared
    MC -->|"start thread"| P1
    MC -->|"start thread"| P2

    P1 -->|"read/write flags & turn"| Shared
    Shared -->|"provide state"| P1

    P2 -->|"read/write flags & turn"| Shared
    Shared -->|"provide state"| P2

    P1 -->|"print ‘+’"| UI
    P2 -->|"print ‘*’"| UI

    UIHandler -->|"set cancelar"| Shared
    UIHandler -.->|"signal shutdown"| MC

    UIHandler -->|"set cancelar"| MC

    MC --> Makefile
    MC --> README

    click MC "https://github.com/ardillachiki/2_intento_dekker/blob/main/Dekker2/main.py"
    click Shared "https://github.com/ardillachiki/2_intento_dekker/blob/main/Dekker2/main.py"
    click P1 "https://github.com/ardillachiki/2_intento_dekker/blob/main/Dekker2/main.py"
    click P2 "https://github.com/ardillachiki/2_intento_dekker/blob/main/Dekker2/main.py"
    click UI "https://github.com/ardillachiki/2_intento_dekker/blob/main/Dekker2/main.py"
    click UIHandler "https://github.com/ardillachiki/2_intento_dekker/blob/main/Dekker2/main.py"
    click Makefile "https://github.com/ardillachiki/2_intento_dekker/tree/main/Dekker2/Makefile"
    click README "https://github.com/ardillachiki/2_intento_dekker/blob/main/README.md"

    classDef process fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef state fill:#90EE90,stroke:#000,stroke-width:1px
    classDef ui fill:#FFA500,stroke:#000,stroke-width:1px
    classDef main fill:#DDA0DD,stroke:#000,stroke-width:1px
    classDef doc fill:#f2f2f2,stroke:#333,stroke-dasharray:5 5,stroke-width:1px
```
