# laufari/minitalk architecture

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

- Interactive diagram: https://gitdiagram.com/laufari/minitalk
- Repository: https://github.com/laufari/minitalk

## Overview

##### Project type and purpose
- This is a lightweight C-based IPC tool (“Minitalk”) that implements a custom bit-level messaging protocol over UNIX signals (SIGUSR1 = bit0, SIGUSR2 = bit1).
- Purpose: client sends a string to server by encoding each character’s bits into signals; server rebuilds the characters, prints them (via ft_printf), and optionally acknowledges each bit.

##### File structure
- Top–level sources:
- client.c / client.h → client process
- server.c / server.h → server process
- ft_memcpy.c → memory helper
- ft_printf/… → custom printf library (Makefile + source files)
- Build: single Makefile compiles all sources into two executables (client, server).
- No external services—communication happens through the kernel’s signal delivery mechanism.

##### README for additional insights
- Protocol: client reads server PID, loops over message characters, and for each bit invokes kill(server_pid, SIGUSR1 or SIGUSR2).
- Server prints its PID on startup, installs signal handlers (signal() or sigaction()), reconstructs bytes, prints via ft_printf, and (bonus) sends back an acknowledgment signal for each bit.
- Performance constraint: server must handle 100 chars in <1s, no memory leaks, conform to 42 school norms.

- Client Process (rectangle)
- Server Process (rectangle)
- ft_memcpy Utility (smaller module)
- Makefile (annotation)
1. Client → Kernel: kill(server_pid, SIGUSR1/ SIGUSR2) – “bit0/bit1”
2. Kernel → Server: deliver SIGUSRx → server’s signal handler
3. Server Handler → Internal Logic: accumulate bits → reconstruct char → call ft_printf
4. (Optional) Server → Kernel: kill(client_pid, SIGUSR1) – “ack”
5. Kernel → Client: deliver ACK signal → client proceeds to next bit
6. Both client & server link against ft_printf and use ft_memcpy
c. Architectural patterns & principles:
- Event-driven (async signal handlers)
- Single responsibility (client-only send, server-only receive)
- Modular library separation (ft_printf as reusable component)
- Minimal coupling (communication via OS-managed signals)
d. Key technologies & libraries:
- C standard library (kill(), signal() / sigaction())
- Custom ft_printf + ft_memcpy
- Makefile for build orchestration

##### Detail & granularity
- Break the client into sub-steps: message input → bit encoder → kill() calls
- Break the server into: signal handler → bit accumulator → character emitter → ft_printf call → optional ack
- Sequence numbers or timing constraints if desired (to reflect the performance goal).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Processes
    subgraph "Client Process" 
        direction TB
        ClientC["client.c"]:::code
        ClientH["client.h"]:::code
        Input["Message Input"]:::process
        Encoder["Bit Encoder"]:::process
        KILL["kill(server_pid, SIGUSR1/2)"]:::process
    end

    subgraph "Server Process"
        direction TB
        ServerC["server.c"]:::code
        ServerH["server.h"]:::code
        Handler["Signal Handler"]:::process
        Accumulator["Bit Accumulator"]:::process
        Emitter["Character Emitter"]:::process
        PrintCall["ft_printf Call"]:::process
        ACKKILL["kill(client_pid, SIGUSR1)"]:::process
        Performance["Performance: 100 chars <1s"]:::note
    end

    %% Kernel
    Kernel["Kernel Signal API"]:::kernel

    %% Libraries
    subgraph "Utilities & Libraries"
        direction TB
        Memcpy["ft_memcpy.c"]:::util
        subgraph "ft_printf Library"
            direction TB
            FP_Make["Makefile"]:::build
            FP_C["ft_printf.c"]:::lib
            FP_H["ft_printf.h"]:::lib
            FP_Hexa["ft_printf_hexa.c"]:::lib
            FP_HexMin["ft_printf_hexamin.c"]:::lib
            FP_Num["ft_printf_numbers.c"]:::lib
            FP_Ptr["ft_printf_pointer.c"]:::lib
            FP_Str["ft_printf_strings.c"]:::lib
            FP_Unsgn["ft_printf_unsigned_numbers.c"]:::lib
        end
    end

    %% Build file
    Makefile["Makefile"]:::build

    %% Connections Client
    ClientC --> Input
    ClientH --> Input
    Input --> Encoder
    Encoder --> KILL
    KILL -->|"SIGUSR1=0\nSIGUSR2=1"| Kernel

    %% Connections Server
    Kernel -->|"SIGUSRx"| Handler
    Handler --> Accumulator
    Accumulator --> Emitter
    Emitter --> PrintCall
    PrintCall --> Memcpy
    PrintCall --> FP_C
    Emitter --> ACKKILL
    ACKKILL -->|"ack SIGUSR1"| Kernel
    Performance --> ServerC

    %% Linking code to processes
    ServerC --> Handler
    ServerH --> Handler

    %% Libraries usage
    Encoder --> Memcpy
    Handler --> Memcpy

    %% Build orchestration
    Makefile -.-> ClientC
    Makefile -.-> ServerC
    Makefile -.-> Memcpy
    Makefile -.-> FP_Make

    %% Links from libraries to processes
    FP_C --> PrintCall
    FP_H --> PrintCall
    FP_Hexa --> PrintCall
    FP_HexMin --> PrintCall
    FP_Num --> PrintCall
    FP_Ptr --> PrintCall
    FP_Str --> PrintCall
    FP_Unsgn --> PrintCall

    %% Click Events
    click ClientC "https://github.com/laufari/minitalk/blob/master/client.c"
    click ClientH "https://github.com/laufari/minitalk/blob/master/client.h"
    click ServerC "https://github.com/laufari/minitalk/blob/master/server.c"
    click ServerH "https://github.com/laufari/minitalk/blob/master/server.h"
    click Memcpy "https://github.com/laufari/minitalk/blob/master/ft_memcpy.c"
    click FP_Make "https://github.com/laufari/minitalk/tree/master/ft_printf/Makefile"
    click FP_C "https://github.com/laufari/minitalk/blob/master/ft_printf/ft_printf.c"
    click FP_H "https://github.com/laufari/minitalk/blob/master/ft_printf/ft_printf.h"
    click FP_Hexa "https://github.com/laufari/minitalk/blob/master/ft_printf/ft_printf_hexa.c"
    click FP_HexMin "https://github.com/laufari/minitalk/blob/master/ft_printf/ft_printf_hexamin.c"
    click FP_Num "https://github.com/laufari/minitalk/blob/master/ft_printf/ft_printf_numbers.c"
    click FP_Ptr "https://github.com/laufari/minitalk/blob/master/ft_printf/ft_printf_pointer.c"
    click FP_Str "https://github.com/laufari/minitalk/blob/master/ft_printf/ft_printf_strings.c"
    click FP_Unsgn "https://github.com/laufari/minitalk/blob/master/ft_printf/ft_printf_unsigned_numbers.c"
    click Makefile "https://github.com/laufari/minitalk/tree/master/Makefile"

    %% Styles
    classDef process fill:#D0E6FF,stroke:#0366d6,color:#0366d6;
    classDef kernel fill:#E8E8E8,stroke:#666666,color:#333333,shape:cloud;
    classDef lib fill:#E2F0D9,stroke:#2E8B57,color:#2E8B57,shape:parallelogram;
    classDef util fill:#E2F0D9,stroke:#2E8B57,color:#2E8B57,shape:parallelogram;
    classDef code fill:#FFF5BA,stroke:#D4A017,color:#8B4513;
    classDef build fill:#FFF2CC,stroke:#E2A500,color:#E2A500;
    classDef note fill:#FFF4E5,stroke:#A67C00,color:#A67C00;
```
