# lucas-tran110/linux--hoochamacallit-system architecture

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

- Interactive diagram: https://gitdiagram.com/lucas-tran110/linux--hoochamacallit-system
- Repository: https://github.com/lucas-tran110/linux--hoochamacallit-system

## Overview

##### Project Overview and Main Components
- The project is an inter-process communication (IPC) assignment that consists of three key applications: one Data Consumer (DC) and two Data Producers. Although the README calls them DP-1 and DP-2, the file tree names the producer directories as DR and DX. In this explanation, assume:
- DC (Data Consumer)
- DR (Data Producer – corresponding to DP-1)
- DX (Data Producer – corresponding to DP-2)
- There is also a “common” directory that provides shared code or configurations used by the other modules.
- The system makes heavy use of IPC mechanisms such as shared memory (with a circular buffer), semaphores to control access to the buffer, and signals for process termination and control.

##### Analyzing the File Structure
- Each component (DC, DR, DX) is a separate directory with its own makefile and a source (src) and header (inc) structure, suggesting a modular design.
- The “common” folder contains a common library (common.h) and its own makefile, indicating shared functionality (possibly routines for initializing IPC or for error handling).
- Top-level build and clean scripts exist which help with component compilation as a suite.

##### Components and Their Interactions
- Shared Memory (Circular Buffer): This is central to the architecture. It is allocated (by DR/DP-1) and used by both producers (DR and DX) to write random letters and consumed by DC which reads from it.
- Semaphores: These are used in the DR and DX components to control access when writing into the circular buffer.
- Signals: Both producers and the consumer handle SIGINT. DC is responsible for catching SIGINT and then sending a SIGINT to both producer processes.
- Process Flow: DR/DP-1 allocates the shared memory and launches DX/DP-2 (which in turn launches DC), creating a cascade dependency. DC reads data to generate and periodically display a histogram of letter occurrences.

##### Architectural Patterns and Design Principles
- Modular Design: Each application exists in its own directory with clear separation between headers (inc), source (src), and build scripts. The common functionalities are abstracted in the “common” module.
- IPC & Synchronization: Using shared memory and semaphores alongside signals for inter-process coordination highlights classic IPC design within UNIX/Linux, ensuring safe concurrent access to shared resources.
- Circular Buffer: The design necessitates circular buffer logic (buffer wrap-around), which is central to the data flow in the system.

##### Final Checklist for the Principal Software Engineer
- Every component is clearly labeled (DC, DR, DX, Common, Shared Memory, Semaphore, Signals).
- Data flow from DR and DX to the shared memory.
- Consumption from shared memory by DC.
- Signal paths (e.g., SIGINT from DC to DR and DX).
- Avoid unnecessary complexity; focus on the modular and IPC-related architecture while being as detailed as possible.
- Review and annotate potential edge cases like shared memory initialization, cleanup, and error handling that are implicitly defined by the assignment requirements.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Components
    subgraph "Producers"
        DR["DR (Data Producer)"]:::components
        DX["DX (Data Producer)"]:::components
    end

    subgraph "Consumer"
        DC["DC (Data Consumer)"]:::components
    end

    %% Shared IPC Resources
    SharedMem["Shared Memory (Circular Buffer)"]:::ipc
    Semaphore["Semaphore"]:::ipc

    %% Common Module for Shared Functionality
    Common["Common Module"]:::common

    %% Process Spawning Flow
    DR -->|"spawns"| DX
    DX -->|"spawns"| DC

    %% Data Flow using IPC with Synchronization
    DR -->|"writes"| SharedMem
    DX -->|"writes"| SharedMem
    DR -->|"sync"| Semaphore
    DX -->|"sync"| Semaphore
    SharedMem -->|"data_read"| DC

    %% Signal Propagation for Termination
    DC -->|"SIGINT"| DR
    DC -->|"SIGINT"| DX

    %% Usage of Common Module
    DR ---|"uses"| Common
    DX ---|"uses"| Common
    DC ---|"uses"| Common

    %% Legend (Informational Node)
    Legend["Legend: DR allocates shared memory and spawns DX; DX spawns DC; Both producers use semaphores for mutual exclusion; DC reads from shared memory to update histogram and sends SIGINT to producers"]:::info

    %% Styling
    classDef components fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef ipc fill:#ccf2ff,stroke:#0066cc,stroke-width:2px;
    classDef common fill:#ccffcc,stroke:#009900,stroke-width:2px;
    classDef info fill:#ffffcc,stroke:#999900,stroke-width:1px;

    %% Click Events for Component Mapping
    click DC "https://github.com/lucas-tran110/linux--hoochamacallit-system/blob/master/Hoochamacallit-System/DC/src/DC.c"
    click DR "https://github.com/lucas-tran110/linux--hoochamacallit-system/blob/master/Hoochamacallit-System/DR/src/DR.c"
    click DX "https://github.com/lucas-tran110/linux--hoochamacallit-system/blob/master/Hoochamacallit-System/DX/src/DX.c"
    click Common "https://github.com/lucas-tran110/linux--hoochamacallit-system/blob/master/Hoochamacallit-System/common/inc/common.h"
```
