# sebastianmunozcodes/syst-prog-p4 architecture

> Architecture diagram of the GitHub repository sebastianmunozcodes/syst-prog-p4, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sebastianmunozcodes/syst-prog-p4
- Repository: https://github.com/sebastianmunozcodes/syst-prog-p4

## Overview

chatd is a single-file TCP chat server. Clients connect, send framed protocol messages, and receive chat, query, status, or error responses. Its documented features include name registration, broadcast and private messaging, WHO queries, status updates, and handling malformed or invalid requests. The excerpt shows the event loop accepting connections and parsing messages, but omits much of dispatch and handler logic; README-backed edges capture those documented interactions without asserting unsampled implementation details.

Main entry points: [`chatd.c`](https://github.com/sebastianmunozcodes/syst-prog-p4/blob/main/chatd.c) (Socket event loop)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server runtime"]
  node_eventloop["Socket event loop<br/>[chatd.c]"]
  node_clientstate["Client state<br/>[chatd.c]"]
end

subgraph group_protocol["Protocol handling"]
  node_framing["Message framing<br/>[chatd.c]"]
  node_parser["Message parser<br/>[chatd.c]"]
  node_responses["Protocol responses<br/>[chatd.c]"]
end

subgraph group_chat["Chat features"]
  node_namehandling["Name registration<br/>[chatd.c]"]
  node_messaging["Message routing<br/>[chatd.c]"]
  node_queries["WHO queries<br/>[chatd.c]"]
  node_status["Status updates<br/>[chatd.c]"]
end

node_clients(("Chat clients"))

node_clients -->|"connect and send"| node_eventloop
node_eventloop -->|"checks completeness"| node_framing
node_eventloop -->|"parses messages"| node_parser
node_eventloop -->|"dispatches NAM"| node_namehandling
node_eventloop -->|"buffers client input"| node_clientstate
node_clients -->|"register names"| node_namehandling
node_clients -->|"send messages"| node_messaging
node_clients -->|"request WHO"| node_queries
node_clients -->|"set status"| node_status
node_messaging -->|"deliver messages"| node_clients
node_queries -->|"return user status"| node_clients
node_status -->|"announce updates"| node_clients
node_namehandling -->|"reports errors"| node_responses
node_messaging -->|"reports errors"| node_responses
node_queries -->|"reports errors"| node_responses
node_status -->|"reports errors"| node_responses
node_responses -->|"send replies"| node_clients

click node_eventloop "https://github.com/sebastianmunozcodes/syst-prog-p4/blob/main/chatd.c"
click node_clientstate "https://github.com/sebastianmunozcodes/syst-prog-p4/blob/main/chatd.c"
click node_framing "https://github.com/sebastianmunozcodes/syst-prog-p4/blob/main/chatd.c"
click node_parser "https://github.com/sebastianmunozcodes/syst-prog-p4/blob/main/chatd.c"
click node_namehandling "https://github.com/sebastianmunozcodes/syst-prog-p4/blob/main/chatd.c"
click node_messaging "https://github.com/sebastianmunozcodes/syst-prog-p4/blob/main/chatd.c"
click node_queries "https://github.com/sebastianmunozcodes/syst-prog-p4/blob/main/chatd.c"
click node_status "https://github.com/sebastianmunozcodes/syst-prog-p4/blob/main/chatd.c"
click node_responses "https://github.com/sebastianmunozcodes/syst-prog-p4/blob/main/chatd.c"

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_eventloop,node_clientstate,node_clients toneBlue
class node_framing,node_parser,node_responses toneAmber
class node_namehandling,node_messaging,node_queries,node_status toneMint
```

## Components

### Server runtime

- [Socket event loop](https://github.com/sebastianmunozcodes/syst-prog-p4/blob/main/chatd.c): `chatd.c`
- [Client state](https://github.com/sebastianmunozcodes/syst-prog-p4/blob/main/chatd.c): `chatd.c`

### Protocol handling

- [Message framing](https://github.com/sebastianmunozcodes/syst-prog-p4/blob/main/chatd.c): `chatd.c`
- [Message parser](https://github.com/sebastianmunozcodes/syst-prog-p4/blob/main/chatd.c): `chatd.c`
- [Protocol responses](https://github.com/sebastianmunozcodes/syst-prog-p4/blob/main/chatd.c): `chatd.c`

### Chat features

- [Name registration](https://github.com/sebastianmunozcodes/syst-prog-p4/blob/main/chatd.c): `chatd.c`
- [Message routing](https://github.com/sebastianmunozcodes/syst-prog-p4/blob/main/chatd.c): `chatd.c`
- [WHO queries](https://github.com/sebastianmunozcodes/syst-prog-p4/blob/main/chatd.c): `chatd.c`
- [Status updates](https://github.com/sebastianmunozcodes/syst-prog-p4/blob/main/chatd.c): `chatd.c`

### Other components

- **Chat clients**

## Connections

- Chat clients → Socket event loop: connect and send (evidence: `README`)
- Socket event loop → Message framing: checks completeness (evidence: `chatd.c`)
- Socket event loop → Message parser: parses messages (evidence: `chatd.c`)
- Socket event loop → Name registration: dispatches NAM (evidence: `chatd.c`)
- Socket event loop → Client state: buffers client input (evidence: `chatd.c`)
- Chat clients → Name registration: register names (evidence: `README`)
- Chat clients → Message routing: send messages (evidence: `README`)
- Chat clients → WHO queries: request WHO (evidence: `README`)
- Chat clients → Status updates: set status (evidence: `README`)
- Message routing → Chat clients: deliver messages (evidence: `README`)
- WHO queries → Chat clients: return user status (evidence: `README`)
- Status updates → Chat clients: announce updates (evidence: `README`)
- Name registration → Protocol responses: reports errors (evidence: `README`)
- Message routing → Protocol responses: reports errors (evidence: `README`)
- WHO queries → Protocol responses: reports errors (evidence: `README`)
- Status updates → Protocol responses: reports errors (evidence: `README`)
- Protocol responses → Chat clients: send replies (evidence: `README`)
