# ddanrom05/productor-consumidor architecture

> Architecture diagram of the GitHub repository ddanrom05/productor-consumidor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ddanrom05/productor-consumidor
- Repository: https://github.com/ddanrom05/productor-consumidor

## Overview

This is a single-file C++ producer–consumer simulation. The producer and consumer maintain separate linked-list replicas and coordinate operations through a file-backed protocol channel; a file-backed Peterson implementation guards their critical sections. The excerpt shows initialization and these component responsibilities, but omits the program’s launch and some loop details, so those connections are not inferred.

Main entry points: [`practica2.cpp`](https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp) (Operation protocol)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workers["Producer–consumer"]
  node_producer["Producer<br/>[practica2.cpp]"]
  node_consumer["Consumer<br/>[practica2.cpp]"]
end

subgraph group_coordination["File coordination"]
  node_protocol["Operation protocol<br/>[practica2.cpp]"]
  node_channel[("Operation channel<br/>[practica2.cpp]")]
  node_peterson["Peterson lock<br/>[practica2.cpp]"]
  node_lockfiles[("Lock state files<br/>[practica2.cpp]")]
end

subgraph group_structures["Data structures"]
  node_producerlist["Producer list<br/>[practica2.cpp]"]
  node_consumerlist["Consumer list<br/>[practica2.cpp]"]
  node_linkedlist["Linked-list implementation<br/>[practica2.cpp]"]
end

node_main["Program entry<br/>[practica2.cpp]"]

node_main -->|"initializes"| node_protocol
node_main -->|"initializes"| node_peterson
node_producer -->|"enters critical section"| node_peterson
node_consumer -->|"enters critical section"| node_peterson
node_peterson -->|"reads and writes"| node_lockfiles
node_producer -->|"reads and writes operations"| node_protocol
node_consumer -->|"reads and writes operations"| node_protocol
node_protocol -->|"reads and writes"| node_channel
node_producer -->|"produces and replicates"| node_producerlist
node_consumer -->|"consumes and replicates"| node_consumerlist
node_producerlist -->|"uses"| node_linkedlist
node_consumerlist -->|"uses"| node_linkedlist

click node_main "https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp"
click node_producer "https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp"
click node_consumer "https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp"
click node_protocol "https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp"
click node_channel "https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp"
click node_peterson "https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp"
click node_lockfiles "https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp"
click node_producerlist "https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp"
click node_consumerlist "https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp"
click node_linkedlist "https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_producer,node_consumer toneBlue
class node_protocol,node_channel,node_peterson,node_lockfiles toneAmber
class node_producerlist,node_consumerlist,node_linkedlist toneMint
class node_main toneTeal
```

## Components

### Producer–consumer

- [Producer](https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp): `practica2.cpp`
- [Consumer](https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp): `practica2.cpp`

### File coordination

- [Operation protocol](https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp): `practica2.cpp`
- [Operation channel](https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp): `practica2.cpp`
- [Peterson lock](https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp): `practica2.cpp`
- [Lock state files](https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp): `practica2.cpp`

### Data structures

- [Producer list](https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp): `practica2.cpp`
- [Consumer list](https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp): `practica2.cpp`
- [Linked-list implementation](https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp): `practica2.cpp`

### Other components

- [Program entry](https://github.com/ddanrom05/productor-consumidor/blob/main/practica2.cpp): `practica2.cpp`

## Connections

- Program entry → Operation protocol: initializes
- Program entry → Peterson lock: initializes
- Producer → Peterson lock: enters critical section
- Consumer → Peterson lock: enters critical section
- Peterson lock → Lock state files: reads and writes
- Producer → Operation protocol: reads and writes operations
- Consumer → Operation protocol: reads and writes operations
- Operation protocol → Operation channel: reads and writes
- Producer → Producer list: produces and replicates
- Consumer → Consumer list: consumes and replicates
- Producer list → Linked-list implementation: uses
- Consumer list → Linked-list implementation: uses
