# marcounie/dekker architecture

> Architecture diagram of the GitHub repository marcounie/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/marcounie/dekker
- Repository: https://github.com/marcounie/dekker

## Overview

##### Project type and purpose
- This is a concurrency-synchronization utility (an open-source tool/library) that implements Dekker’s algorithm in Python.
- There is no frontend, backend or external service—just a single module providing mutual exclusion between two threads.

##### File structure
- Top-level:
– README.md     ← contains only project title
– dekker.py     ← contains the implementation of Dekker’s algorithm
- No subdirectories, no external dependencies beyond the Python standard library (threading).

##### README
- Only “# Dekker” is present—no additional architectural notes.
- Conclude that the README does not describe components; you must infer them from dekker.py.

##### Main components
a. Python Runtime / Interpreter
b. dekker.py Module (the “Dekker Algorithm” component)
c. Thread 1 and Thread 2 (consumer processes using the algorithm)
d. Shared Memory State:
– flag[0], flag[1]
– turn variable

##### Relationships & data flows
- Both Thread 1 and Thread 2 invoke “enter_critical_section()” and “exit_critical_section()” in the dekker.py module.
- dekker.py manipulates shared-memory flags and turn.
- After acquiring the lock, each thread proceeds into its critical section; upon exit, it clears its flag and gives up turn.

##### Architectural patterns & design principles
- Busy-waiting spinlock using Dekker’s two-process mutual exclusion algorithm.
- Single shared-memory concurrency—no message passing, no I/O, no networking.
- Separation of concerns: algorithm logic in dekker.py; client threads remain generic.

1. “Python Interpreter” (container)
2. “dekker.py” (module)
3. “Thread A” and “Thread B”
4. “Shared Memory” (flags & turn)
– From each Thread → dekker.py.enter_critical_section()
– dekker.py → Shared Memory (read/write flags & turn)
– Shared Memory → dekker.py (to check flags/turn)
– dekker.py.exit_critical_section() → Shared Memory
– Algorithm module in another (e.g., yellow)
– Shared Memory in a third (e.g., green)

##### Putting it all together
b. Inside it, place:
– Thread A → dekker.py.enter_critical_section()
– dekker.py ↔ Shared Memory
– dekker.py → Thread A (handoff into critical section)
– Similarly for Thread B

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Python Interpreter"
        direction TB
        ThreadA["Thread A"]:::threads
        ThreadB["Thread B"]:::threads
        DekkerModule["dekker.py - Dekker Algorithm"]:::module
        SharedMemory["Shared Memory<br/>(flag[ ], turn)"]:::memory
    end

    README["README.md"]:::docs

    ThreadA -->|"enter_critical_section()"| DekkerModule
    ThreadB -->|"enter_critical_section()"| DekkerModule

    DekkerModule -->|"read/write flags & turn"| SharedMemory
    SharedMemory -->|"return flags & turn"| DekkerModule

    DekkerModule -->|"exit_critical_section() → clear flag & give up turn"| SharedMemory

    DekkerModule -->|"grant critical section"| ThreadA
    DekkerModule -->|"grant critical section"| ThreadB

    click DekkerModule "https://github.com/marcounie/dekker/blob/main/dekker.py"
    click README "https://github.com/marcounie/dekker/blob/main/README.md"

    classDef threads fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef module fill:#FFE066,stroke:#333,stroke-width:1px
    classDef memory fill:#A2D5AB,stroke:#333,stroke-width:1px
    classDef docs fill:#DDD,stroke:#333,stroke-width:1px
```
