ChatSystem is a distributed, real-time chat system implemented in Java 21 and built with Maven.
It enables multiple users on the same local network to communicate without any centralized server, relying on peer-to-peer discovery, structured message exchange, multithreading, and local persistence.
Each instance runs independently while dynamically discovering other peers, maintaining local state consistency, and persisting messages.
- Fully decentralized architecture (no server, no master node).
- Automatic peer discovery using UDP broadcast.
- Reliable message exchange combining UDP (discovery & signaling) and TCP (data).
- Structured communication through typed Payloads and Tags.
- Asynchronous message handling using dispatchers and pipelines.
- Central
ChatSystemmodel representing the global application state. - Explicit lifecycle management (
BOOTSTRAP → RUNNING → SHUTDOWN). - Clear separation between:
- network
- services
- persistence
- threading
- Event-driven design using listeners and state transitions.
- Centralized thread supervision via
ThreadManager. - Dedicated threads for:
- UDP listening
- UDP sending
- TCP server
- Payload dispatching
- Thread-safe pipelines (
Pipe) for asynchronous processing.
- Local SQLite database for message storage.
- Repository pattern for persistence abstraction.
- Centralized database lifecycle management through
DatabaseManager. - Messages persist across application restarts.
- Unique user identification (login + IP address).
- Dynamic login updates propagated to all peers.
- Automatic detection of disconnections.
- Central contact list with listener notifications.
- A graphical interface is available in the
guipackage. - The GUI interacts with the core system and services without breaking the decentralized model.
-
ChatSystem
Represents the global application state and lifecycle. -
ChatSystemContext
Dependency container holding services, repositories, and network components. -
ChatSystemBootstrap
Responsible for initializing the system, threads, and network services. -
ChatSystemShutdownManager
Ensures graceful shutdown and peer notification. -
ChatSystemState
Enumeration of system states (DISCONNECTED,CONNECTING,CONNECTED,SHUTTING_DOWN, etc.). -
User
Represents a local or remote peer. -
ContactList
Singleton storing known users and notifying listeners on updates.
-
NetworkManager
Central orchestrator for all network components. -
ServerTCP
TCP server responsible for reliable message delivery. -
SenderUDP/ListenerUDP
Peer discovery and system announcements. -
Payload/Tag
Typed network messages with explicit semantics. -
Pipe
Thread-safe pipeline enabling asynchronous message processing. -
PayloadDispatcher
Routes incoming payloads to appropriate handlers.
-
SessionService
Manages the local user session (login, address, state). -
MessageService
Handles message sending, receiving, and retrieval. -
ApplicationService
High-level application control and lifecycle coordination.
-
MessageRepository
Abstraction for message persistence. -
SQLiteMessageRepository
SQLite-based implementation of the repository. -
DatabaseManager
Singleton managing the database connection lifecycle.
ThreadManager
Centralized registration, startup, and shutdown of all application threads.
- Contains application controllers coordinating interactions between the GUI, services, and core models.
- This layer is intentionally kept thin and is not detailed here.
- Java 21 or later
- Maven 3.8+
From the project root:
mvn clean packageThe project is configured so that the main class is already defined in the pom.xml.
You can run the application using:
java -jar target/ChatSystem-1.0-SNAPSHOT-shaded.jarUnit tests are located in src/test/java and cover:
- Network flow and payload handling
- Thread lifecycle and concurrency safety
- Persistence (SQLite repositories)
- Contact and user management
Run all tests with:
mvn testsrc/
├─ main/java/
│ ├─ networks/
│ ├─ services/
│ ├─ persistence/
│ ├─ threading/
│ ├─ models/
│ ├─ gui/
│ ├─ controller/
│ └─ Main.java
└─ test/java/
├─ networks/
├─ persistence/
├─ threading/
└─ models/
- UDP broadcast is used for peer discovery.
- TCP is used for reliable message exchange.
- The system is designed for extensibility, allowing:
- New payload types
- Additional services
- Alternative persistence implementations