Skip to content

A real-time collaborative text editor built in Java that allows multiple users to edit documents simultaneously over a network using a multithreaded client-server architecture.

License

Notifications You must be signed in to change notification settings

kareem1207/CollabEditor

Repository files navigation

Collaborative Text Editor

A real-time collaborative text editor built in Java that allows multiple users to edit documents simultaneously over a network connection. The application features live text synchronization, user typing indicators, and persistent document storage.

App preview

🌟 Features

  • Real-time Collaboration: Multiple users can edit the same document simultaneously
  • Live Text Synchronization: Changes are instantly synchronized across all connected clients
  • User Typing Indicators: Visual feedback showing when other users are typing
  • Document Persistence: Automatic saving and loading of documents
  • File Locking: Prevents conflicts during document operations
  • User-friendly GUI: Intuitive Swing-based interface
  • Client-Server Architecture: Robust networking with automatic connection handling
  • Cross-platform Compatibility: Works on any Java-supported platform

πŸ› οΈ Technology Stack

  • Programming Language: Java 8+
  • Build Tool: Apache Maven
  • GUI Framework: Java Swing
  • Networking: Java Socket Programming (TCP)
  • File Operations: Java NIO
  • Concurrency: Java Threading and Executors
  • Testing Framework: JUnit 4.11

πŸ“ Project Structure

collab-editor/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main/
β”‚   β”‚   └── java/
β”‚   β”‚       └── com/
β”‚   β”‚           └── kareem/
β”‚   β”‚               └── collab/
β”‚   β”‚                   β”œβ”€β”€ App.java                    # Main application entry point
β”‚   β”‚                   β”œβ”€β”€ networking/
β”‚   β”‚                   β”‚   β”œβ”€β”€ Server.java             # Server implementation
β”‚   β”‚                   β”‚   β”œβ”€β”€ Client.java             # Client implementation
β”‚   β”‚                   β”‚   └── ClientHandler.java      # Server-side client handling
β”‚   β”‚                   β”œβ”€β”€ ui/
β”‚   β”‚                   β”‚   β”œβ”€β”€ Home.java               # Main menu interface
β”‚   β”‚                   β”‚   β”œβ”€β”€ TextEditor.java         # Text editor interface
β”‚   β”‚                   β”‚   └── Ui.java                 # UI controller
β”‚   β”‚                   └── utils/
β”‚   β”‚                       β”œβ”€β”€ DocumentManager.java    # Document persistence
β”‚   β”‚                       └── FileUtils.java          # File utilities
β”‚   └── test/
β”‚       └── java/
β”‚           └── com/
β”‚               └── kareem/
β”‚                   └── collab/
β”‚                       └── AppTest.java
β”œβ”€β”€ pom.xml                                             # Maven configuration
└── README.md

πŸš€ How It Works

Architecture Overview

The application follows a client-server architecture with the following components:

1. Server (Server.java)

  • Listens on port 8080 for incoming client connections
  • Manages document state and persistence
  • Coordinates message broadcasting between clients
  • Handles graceful shutdown and resource cleanup

2. Client (Client.java)

  • Connects to the server via TCP socket
  • Sends text updates and receives real-time changes
  • Handles message encoding/decoding for network transmission
  • Manages connection lifecycle

3. Client Handler (ClientHandler.java)

  • Server-side component managing individual client connections
  • Processes incoming messages and broadcasts to other clients
  • Maintains global document state
  • Handles client join/leave events

4. Text Editor (TextEditor.java)

  • Swing-based GUI for text editing
  • Real-time text synchronization with other clients
  • User typing indicators and status updates
  • Document change detection and network communication

5. Document Manager (DocumentManager.java)

  • Persistent storage of document content
  • Thread-safe file operations
  • Automatic document loading on server startup
  • Cleanup on application shutdown

Communication Protocol

The application uses a custom text-based protocol over TCP:

  • TEXT Messages: TEXT|username|isTyping|encodedContent
  • Server Messages: SERVER: prefix for system notifications
  • Message Encoding: Special characters are escaped for safe transmission

Synchronization Flow

  1. User types in editor β†’ Document change detected
  2. Client sends update β†’ Message encoded and sent to server
  3. Server receives message β†’ Validates and updates global document state
  4. Server broadcasts β†’ Sends update to all other connected clients
  5. Clients receive update β†’ Decode message and update local editor
  6. Document saved β†’ Server persists changes to disk

🎯 Getting Started

Prerequisites

  • Java 8 or higher
  • Apache Maven 3.6+
  • Network connectivity for multi-user collaboration

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd collab-editor
  2. Build the project:

    mvn clean compile
  3. Run tests:

    mvn test

Running the Application

Option 1: Using Maven

Start the application:

mvn exec:java -Dexec.mainClass="com.kareem.collab.App"

Or run the server separately:

mvn exec:java -Dexec.mainClass="com.kareem.collab.networking.Server"

Option 2: Using JAR file

Build executable JAR:

mvn package

Run the application:

java -jar target/collab-editor-1.0-SNAPSHOT.jar

Usage Instructions

  1. Launch the application - The main menu will appear

  2. Choose an option:

    • "Create New Document": Opens a local text editor
    • "Join Existing Document": Connects to a collaborative session
  3. For collaborative editing:

    • Ensure the server is running (port 8080)
    • Click "Join Existing Document"
    • Enter server address (default: localhost)
    • Provide your username
    • Start editing collaboratively!

πŸ”§ Configuration

Server Configuration

  • Default Port: 8080 (can be modified in Server.java)
  • Document Storage: ../../collab/temp/document.txt
  • Connection Timeout: Configurable in client implementation

Network Settings

  • Protocol: TCP
  • Encoding: UTF-8
  • Message Format: Custom text-based protocol
  • Retry Logic: Built-in connection retry mechanism

πŸ—οΈ Development

Building from Source

# Clean and compile
mvn clean compile

# Run tests
mvn test

# Package application
mvn package

# Run with debugging
mvn exec:java -Dexec.mainClass="com.kareem.collab.App" -Dexec.args="-debug"

IDE Setup

The project is compatible with any Java IDE:

  • Eclipse: Import as Maven project
  • IntelliJ IDEA: Open pom.xml as project
  • VS Code: Open folder with Java extension pack

πŸ§ͺ Testing

Run the test suite:

mvn test

For manual testing:

  1. Start the server: java com.kareem.collab.networking.Server
  2. Launch multiple client instances
  3. Test real-time synchronization across clients

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ› Known Issues

  • Document path is relative and may need adjustment based on execution context
  • Server requires manual startup for collaborative features
  • Limited error handling for network interruptions

πŸš€ Future Enhancements

  • User authentication and authorization
  • Multiple document support
  • Syntax highlighting for different file types
  • Version control and change history
  • Enhanced UI with modern look and feel
  • WebSocket support for better real-time performance
  • File import/export functionality
  • Collaborative cursors and selections

πŸ‘¨β€πŸ’» Author

Developed by Kareem - A collaborative text editing solution built with Java.

πŸ“ž Support

For support and questions:

  • Create an issue in the repository
  • Check existing issues for solutions
  • Review the code documentation

Happy Collaborative Editing! πŸŽ‰

About

A real-time collaborative text editor built in Java that allows multiple users to edit documents simultaneously over a network using a multithreaded client-server architecture.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published