# neshgp04/proyecto1-so architecture

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

- Interactive diagram: https://gitdiagram.com/neshgp04/proyecto1-so
- Repository: https://github.com/neshgp04/proyecto1-so

## Overview

Proyecto1-SO is a multithreaded TCP chat implementation with a command-line client and a server. The intended workflow is client connection and registration, command exchange, server parsing and handling, and replies or message delivery. The README describes important server capabilities, but also marks protocol parsing, registration, and most command handlers as pending or temporary. Edges reflect shown calls or documented behavior; where server startup wiring is not shown, links are omitted or marked unverified.

Main entry points: [`src/client/main_client.c`](https://github.com/neshgp04/proyecto1-so/blob/main/src/client/main_client.c) (Connect and register), [`src/server/client_thread.c`](https://github.com/neshgp04/proyecto1-so/blob/main/src/server/client_thread.c) (Client worker), [`src/client/input_loop.c`](https://github.com/neshgp04/proyecto1-so/blob/main/src/client/input_loop.c) (Command input), [`src/server/handlers.c`](https://github.com/neshgp04/proyecto1-so/blob/main/src/server/handlers.c) (Command handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Chat client"]
  node_client_entry["Connect and register<br/>[main_client.c]"]
  node_client_input["Command input<br/>[input_loop.c]"]
  node_client_local["Local commands<br/>[commands_local.c]"]
  node_client_receiver["Response receiver<br/>[receiver_loop.c]"]
  node_client_ui["Terminal UI<br/>[ui.c]"]
  node_client_contract["Client interface<br/>[client.h]"]
end

subgraph group_server["Chat server"]
  node_server_entry["Server startup<br/>[main_server.c]"]
  node_accept["Connection acceptor<br/>[accept_loop.c]"]
  node_client_thread["Client worker<br/>[client_thread.c]"]
  node_handlers["Command handlers<br/>[handlers.c]"]
  node_inactivity["Inactivity monitor<br/>[inactivity.c]"]
  node_server_contract["Server interface<br/>[server.h]"]
end

subgraph group_protocol["Protocol and validation"]
  node_parser["Message parser<br/>[protocol.c]"]
  node_protocol_contract["Wire protocol<br/>[protocol.h]"]
  node_parser_contract["Parser interface<br/>[parser.h]"]
  node_validation["Input validation<br/>[validation.c]"]
  node_common_contract["Shared constants<br/>[common.h]"]
end

subgraph group_sessions["Session management"]
  node_session_contract["Session definition<br/>[session.h]"]
  node_session_store[("Session registry<br/>[session_manager.c]")]
end

node_user(("Chat user"))

node_user -->|"starts client"| node_client_entry
node_client_entry -.->|"connects TCP"| node_server_entry
node_client_entry -->|"starts input"| node_client_input
node_client_entry -->|"starts receiver"| node_client_receiver
node_user -->|"enters commands"| node_client_input
node_client_input -->|"runs help"| node_client_local
node_client_input -->|"sends commands"| node_server_entry
node_server_entry -.->|"accepts clients"| node_accept
node_accept -.->|"spawns worker"| node_client_thread
node_client_thread -->|"parses messages"| node_parser
node_client_thread -->|"dispatches parsed"| node_handlers
node_handlers -->|"looks up sessions"| node_session_store
node_handlers -->|"builds replies"| node_parser
node_handlers -->|"validates input"| node_validation
node_client_thread -->|"cleans session"| node_session_store
node_inactivity -.->|"marks inactive"| node_session_store
node_client_receiver -.->|"displays replies"| node_client_ui
node_client_input -->|"formats commands"| node_protocol_contract
node_parser -->|"implements parsing"| node_parser_contract
node_client_entry -->|"uses interface"| node_client_contract
node_client_thread -->|"uses interface"| node_server_contract
node_session_store -->|"stores sessions"| node_session_contract

click node_client_entry "https://github.com/neshgp04/proyecto1-so/blob/main/src/client/main_client.c"
click node_client_input "https://github.com/neshgp04/proyecto1-so/blob/main/src/client/input_loop.c"
click node_client_local "https://github.com/neshgp04/proyecto1-so/blob/main/src/client/commands_local.c"
click node_client_receiver "https://github.com/neshgp04/proyecto1-so/blob/main/src/client/receiver_loop.c"
click node_client_ui "https://github.com/neshgp04/proyecto1-so/blob/main/src/client/ui.c"
click node_client_contract "https://github.com/neshgp04/proyecto1-so/blob/main/include/client.h"
click node_server_entry "https://github.com/neshgp04/proyecto1-so/blob/main/src/server/main_server.c"
click node_accept "https://github.com/neshgp04/proyecto1-so/blob/main/src/server/accept_loop.c"
click node_client_thread "https://github.com/neshgp04/proyecto1-so/blob/main/src/server/client_thread.c"
click node_handlers "https://github.com/neshgp04/proyecto1-so/blob/main/src/server/handlers.c"
click node_inactivity "https://github.com/neshgp04/proyecto1-so/blob/main/src/server/inactivity.c"
click node_server_contract "https://github.com/neshgp04/proyecto1-so/blob/main/include/server.h"
click node_parser "https://github.com/neshgp04/proyecto1-so/blob/main/src/common/protocol.c"
click node_protocol_contract "https://github.com/neshgp04/proyecto1-so/blob/main/include/protocol.h"
click node_parser_contract "https://github.com/neshgp04/proyecto1-so/blob/main/include/parser.h"
click node_validation "https://github.com/neshgp04/proyecto1-so/blob/main/src/common/validation.c"
click node_common_contract "https://github.com/neshgp04/proyecto1-so/blob/main/include/common.h"
click node_session_contract "https://github.com/neshgp04/proyecto1-so/blob/main/include/session.h"
click node_session_store "https://github.com/neshgp04/proyecto1-so/blob/main/src/server/session_manager.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_client_entry,node_client_input,node_client_local,node_client_receiver,node_client_ui,node_client_contract,node_user toneBlue
class node_server_entry,node_accept,node_client_thread,node_handlers,node_inactivity,node_server_contract toneAmber
class node_parser,node_protocol_contract,node_parser_contract,node_validation,node_common_contract toneMint
class node_session_contract,node_session_store toneRose
```

## Components

### Chat client

- [Connect and register](https://github.com/neshgp04/proyecto1-so/blob/main/src/client/main_client.c): `src/client/main_client.c`
- [Command input](https://github.com/neshgp04/proyecto1-so/blob/main/src/client/input_loop.c): `src/client/input_loop.c`
- [Local commands](https://github.com/neshgp04/proyecto1-so/blob/main/src/client/commands_local.c): `src/client/commands_local.c`
- [Response receiver](https://github.com/neshgp04/proyecto1-so/blob/main/src/client/receiver_loop.c): `src/client/receiver_loop.c`
- [Terminal UI](https://github.com/neshgp04/proyecto1-so/blob/main/src/client/ui.c): `src/client/ui.c`
- [Client interface](https://github.com/neshgp04/proyecto1-so/blob/main/include/client.h): `include/client.h`

### Chat server

- [Server startup](https://github.com/neshgp04/proyecto1-so/blob/main/src/server/main_server.c): `src/server/main_server.c`
- [Connection acceptor](https://github.com/neshgp04/proyecto1-so/blob/main/src/server/accept_loop.c): `src/server/accept_loop.c`
- [Client worker](https://github.com/neshgp04/proyecto1-so/blob/main/src/server/client_thread.c): `src/server/client_thread.c`
- [Command handlers](https://github.com/neshgp04/proyecto1-so/blob/main/src/server/handlers.c): `src/server/handlers.c`
- [Inactivity monitor](https://github.com/neshgp04/proyecto1-so/blob/main/src/server/inactivity.c): `src/server/inactivity.c`
- [Server interface](https://github.com/neshgp04/proyecto1-so/blob/main/include/server.h): `include/server.h`

### Protocol and validation

- [Message parser](https://github.com/neshgp04/proyecto1-so/blob/main/src/common/protocol.c): `src/common/protocol.c`
- [Wire protocol](https://github.com/neshgp04/proyecto1-so/blob/main/include/protocol.h): `include/protocol.h`
- [Parser interface](https://github.com/neshgp04/proyecto1-so/blob/main/include/parser.h): `include/parser.h`
- [Input validation](https://github.com/neshgp04/proyecto1-so/blob/main/src/common/validation.c): `src/common/validation.c`
- [Shared constants](https://github.com/neshgp04/proyecto1-so/blob/main/include/common.h): `include/common.h`

### Session management

- [Session definition](https://github.com/neshgp04/proyecto1-so/blob/main/include/session.h): `include/session.h`
- [Session registry](https://github.com/neshgp04/proyecto1-so/blob/main/src/server/session_manager.c): `src/server/session_manager.c`

### Other components

- **Chat user**

## Connections

- Chat user → Connect and register: starts client (evidence: `src/client/main_client.c`)
- Connect and register → Server startup: connects TCP (evidence: `README.md`)
- Connect and register → Command input: starts input (evidence: `src/client/main_client.c`)
- Connect and register → Response receiver: starts receiver (evidence: `src/client/main_client.c`)
- Chat user → Command input: enters commands
- Command input → Local commands: runs help
- Command input → Server startup: sends commands (evidence: `src/client/input_loop.c`)
- Server startup → Connection acceptor: accepts clients
- Connection acceptor → Client worker: spawns worker (evidence: `README.md`)
- Client worker → Message parser: parses messages (evidence: `src/server/client_thread.c`)
- Client worker → Command handlers: dispatches parsed (evidence: `src/server/client_thread.c`)
- Command handlers → Session registry: looks up sessions (evidence: `src/server/handlers.c`)
- Command handlers → Message parser: builds replies (evidence: `src/server/handlers.c`)
- Command handlers → Input validation: validates input (evidence: `src/server/handlers.c`)
- Client worker → Session registry: cleans session (evidence: `src/server/client_thread.c`)
- Inactivity monitor → Session registry: marks inactive (evidence: `README.md`)
- Response receiver → Terminal UI: displays replies
- Command input → Wire protocol: formats commands (evidence: `src/client/input_loop.c`)
- Message parser → Parser interface: implements parsing (evidence: `src/common/protocol.c`)
- Connect and register → Client interface: uses interface (evidence: `src/client/main_client.c`)
- Client worker → Server interface: uses interface (evidence: `src/server/client_thread.c`)
- Session registry → Session definition: stores sessions (evidence: `src/server/session_manager.c`)
