# franciscolh04/projeto-rc architecture

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

- Interactive diagram: https://gitdiagram.com/franciscolh04/projeto-rc
- Repository: https://github.com/franciscolh04/projeto-rc

## Overview

##### Project Type and Purpose
- This is a networked, console-based Mastermind game written in C, with a clear client–server split.
- The server (“GS.c” & friends) runs the game logic and manages player state; the client (“communication.c” & “player.c”) handles user I/O and communicates with the server.
- A small common library (“verifications.c”) is shared for input validation.

##### File Structure
Top-level:
- Makefile – build orchestration
- README.md – (minimal) grading info
src/
- client/
– communication.c/.h → socket I/O, message framing
– player.c/.h → user input loop, result display
- common/
– verifications.c/.h → shared checks (e.g. valid guess format)
- server/
– GS.c/.h → game server main, listener loop
– command_handler.c/.h → parsing incoming commands, routing
– game.c/.h → central game-state machine, turn logic
– state.c/.h → in-memory model of players, guesses, results
– mastermind.c → core algorithm (compare guess vs. solution)

##### Extract Architectural Patterns and Components
a. Client–Server architecture (request→response over TCP/UDP sockets)
b. Modular layering on the server:
– Listener & dispatcher (GS)
– Command parser & router
– Game engine (game + mastermind)
– State repository
c. Shared validation logic in a separate module (DRY principle).

- Components:
1. Client Module
- Player Interface (player.c)
- Communication Layer (communication.c)
2. Network Layer
- Socket channel (TCP)
3. Server Module
- GS (listener & connection manager)
- Command Handler
- Game Engine
– Mastermind Algorithm
– Game Logic
- State Store
4. Common Library
- Verifications (shared between client & server builds)
5. Build System (Makefile)

- Interactions:
- Player Interface → Communication Layer → Network → GS
- GS → Command Handler → Game Engine → State Store → Command Handler → GS → Network → Client
- Both client and server link against the Common Library for input/command verifications.

##### Call-outs for Key Technologies & Patterns
- C language, POSIX sockets
- Makefile build targets (e.g., “client”, “server”, “common”)
- Modular layering on the server: separation of concerns (listener, parsing, logic, state)
- Client event loop vs. server multi–client handling (if any threading or select/poll is used)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client"
        PI["Player Interface\n(player.c, player.h)"]:::client
        CL["Communication Layer\n(communication.c, communication.h)"]:::client
    end

    subgraph "Network"
        TCP["TCP Socket"]:::network
    end

    subgraph "Server"
        GS["GS\n(GS.c, GS.h)"]:::server
        CH["Command Handler\n(command_handler.c, command_handler.h)"]:::server
        subgraph "Game Engine"
            GL["Game Logic\n(game.c, game.h)"]:::server
            MM["Mastermind Algorithm\n(mastermind.c)"]:::server
        end
        SS["State Store\n(state.c, state.h)"]:::server
    end

    subgraph "Common Library"
        CV["Verifications\n(verifications.c, verifications.h)"]:::common
    end

    Build["Build System\n(Makefile)"]:::build

    %% Data flows
    PI -->|invokes| CL
    CL -.->|send/recv| TCP
    TCP -.->|accept/connect| GS
    GS -->|delegate| CH
    CH -->|process| GL
    GL -->|uses| MM
    GL -->|read/write| SS
    SS -->|state data| CH
    CH -->|respond| GS
    GS -.->|send/recv| TCP
    TCP -.->|send/recv| CL

    %% Compile/link dependencies
    CV -.->|links with| PI
    CV -.->|links with| GS

    %% Build targets
    Build -->|build client| PI
    Build -->|build server| GS
    Build -->|build common| CV

    %% Click events
    click PI "https://github.com/franciscolh04/projeto-rc/blob/main/src/client/player.c"
    click CL "https://github.com/franciscolh04/projeto-rc/blob/main/src/client/communication.c"
    click CV "https://github.com/franciscolh04/projeto-rc/blob/main/src/common/verifications.c"
    click GS "https://github.com/franciscolh04/projeto-rc/blob/main/src/server/GS.c"
    click CH "https://github.com/franciscolh04/projeto-rc/blob/main/src/server/command_handler.c"
    click GL "https://github.com/franciscolh04/projeto-rc/blob/main/src/server/game.c"
    click MM "https://github.com/franciscolh04/projeto-rc/blob/main/src/server/mastermind.c"
    click SS "https://github.com/franciscolh04/projeto-rc/blob/main/src/server/state.c"
    click Build "https://github.com/franciscolh04/projeto-rc/tree/main/Makefile"

    %% Styles
    classDef client fill:#D6EAF8,stroke:#1B4F72,color:#1B2631
    classDef server fill:#D5F5E3,stroke:#186A3B,color:#1E8449
    classDef common fill:#FCF3CF,stroke:#B7950B,color:#6E2C00
    classDef build fill:#E5E7E9,stroke:#566573,color:#1C2833
    classDef network fill:#FADBD8,stroke:#C0392B,color:#641E16
```
