How yan-misael/aplicacion-whatsapp works
1. Scope of this repository
- This repo contains the server-side of a distributed WhatsApp-like messenger plus the shared network DTOs used over the wire.
- The documented client/UI exists conceptually in the README, but it is not present in this tree; the architecture here is centered on the server broker and its protocol objects.
2. Top-level architecture
- The system uses a centralized client-server broker model.
- All clients connect to one server endpoint, and that server acts as the intermediary for private chat and group communication, so clients do not need direct knowledge of each other’s addresses.
3. Core startup boundary
- whatsapp.server.core.ServidorPrincipal is the server entry point.
- It is responsible for bootstrapping the socket listener, choosing the listening port, and wiring the shared managers into the connection-handling layer.
4. Connection handling boundary
- whatsapp.server.handlers.ManejadorCliente is the per-connection worker.
- The server follows a thread-per-client model: each accepted socket is handed to an isolated handler thread so one slow or blocked client does not stall the rest.
5. Global state management
- whatsapp.server.managers.SessionManager owns the active-session registry.
- It enforces consistency around user registration/login/session lookup, preventing duplicate or conflicting session state when multiple clients connect concurrently.
6. Group membership and fan-out
- whatsapp.server.managers.GroupManager owns group/chat-room state.
- It is the concurrency-sensitive boundary for group membership changes and for obtaining member lists used when broadcasting messages to a room.
7. Concurrency model
- The server protects shared mutable state with explicit synchronization:
- SessionManager uses monitor-style locking for atomic session operations.
- GroupManager uses a read/write lock so many reads can happen in parallel while membership changes remain exclusive.
- This design reflects a chat workload where reads and message delivery are much more frequent than membership mutations.
8. Network data model
- whatsapp.common.models.PaqueteRed is the base message envelope for all network traffic.
- PaqueteMensaje is a concrete payload for chat content, and the README indicates the server dispatches on packet type using polymorphism/instanceof.
- These classes are serialized Java objects, so the wire format is native Java serialization rather than text-based encoding.
9. Shared model boundary
- whatsapp.common.models is the contract shared by sender and receiver.
- The immutability noted in the README means packets behave like DTOs: they are created, transmitted, and processed without being mutated in transit.
10. Request flow through the system
- A client connects to the server socket.
- The accepted socket is assigned to a ManejadorCliente thread.
- The handler reads a serialized PaqueteRed, determines the packet subtype, and delegates to SessionManager or GroupManager.
- The server then routes or broadcasts the resulting message to the intended recipient(s).
11. Failure and isolation boundaries
- Each client connection is wrapped in local error handling, so disconnects or malformed traffic are contained to that thread.
- Cleanup removes the affected session and closes the socket without impacting other active clients.
12. Build/runtime environment
- The project is a Java/Maven application, with the server intended to run on JDK 17.
- pom.xml defines the Maven project structure and makes the repository reproducible across IDEs and environments.
13. Diagramming takeaway
- The main boxes to draw are: Server bootstrap, connection handler threads, session manager, group manager, and shared serializable packet models.
- The key arrows are: client socket traffic into handler threads, handlers into shared managers, and handlers back out to recipient sockets for private or group message delivery.
Main entry points: ManejadorCliente.java Client Handler · GroupManager.java Group Manager · ServidorPrincipal.java Server Main · SessionManager.java Session Manager
Components 9
Build
Maven project definition and runtime target.
- pom.xml · Defines the Java/Maven build and JDK target.
pom.xml
Server Core
Entry point and connection orchestration.
- Server Main · Starts the server socket and wires shared managers.
src/main/java/whatsapp/server/core/ServidorPrincipal.java
Handlers
Per-connection request processing.
- Client Handler · Handles one client socket on its own thread.
src/main/java/whatsapp/server/handlers/ManejadorCliente.java
Managers
Shared server state and concurrency boundaries.
- Session Manager · Tracks active users and guards login/session consistency.
src/main/java/whatsapp/server/managers/SessionManager.java - Group Manager · Manages room membership and broadcast recipient sets.
src/main/java/whatsapp/server/managers/GroupManager.java - Managers · Package-level server manager container.
src/main/java/whatsapp/server/managers/Managers.java
Shared Models
Serializable wire contracts shared by client and server.
- Red Packet · Base serializable packet used for all network traffic.
src/main/java/whatsapp/common/models/PaqueteRed.java - Message Packet · Concrete message DTO for chat content.
src/main/java/whatsapp/common/models/PaqueteMensaje.java - Models · Package-level shared model container.
src/main/java/whatsapp/common/models/Models.java
Connections 14
- pom.xml → Server Main: builds · Maven builds the server entry point.
- Server Main → Client Handler: accepts · Bootstraps per-connection worker threads.
- Server Main → Session Manager: wires · Injects session state management into the server.
- Server Main → Group Manager: wires · Injects group membership management into the server.
- Client Handler → Red Packet: reads · Deserializes incoming network envelopes.
- Client Handler → Message Packet: dispatches · Special-cases message payloads from generic packets.
- Client Handler → Session Manager: auth/session · Registers, looks up, and removes client sessions.
- Client Handler → Group Manager: groups · Resolves room membership and broadcast targets.
- Session Manager → Group Manager: resolves users · Session state feeds group membership and addressing.
- Group Manager → Client Handler: broadcasts · Delivers room messages back through client handlers/sockets.
- Models → Red Packet: contains · Shared model container anchors the wire envelope types.
- Models → Message Packet: contains · Shared model container anchors message DTOs.
- Managers → Session Manager: contains · Manager hub groups session state logic.
- Managers → Group Manager: contains · Manager hub groups room state logic.