Skip to content

A standalone, terminal-based implementation of the Nwitter social network that operates entirely offline, using local JSON files for data persistence and ANSI codes for a colorful command-line interface.

Notifications You must be signed in to change notification settings

Nikelroid/nwitter-offline-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Nwitter-Offline-CLI

Java Gradle GSON Log4j CLI

Project Description

Nwitter-Offline-CLI is a lightweight, terminal-based version of the Nwitter social ecosystem. Unlike its network-connected counterparts, this application runs entirely on the client machine without a backend server. It simulates a full-featured social media experience—including tweeting, messaging, and profile management—by reading and writing data directly to local JSON files (Twittes.json, Users.json, etc.).

This project serves as an excellent demonstration of Object-Oriented Programming (OOP) principles in Java and handling data persistence without a traditional database engine.

Features

  • Command-Line Interface: A retro-styled text interface enhanced with ConsoleColors for better readability and navigation.
  • Local Persistence: All data (users, tweets, messages) is stored in readable JSON files within the project directory.
  • User System: Full authentication flow including Login, Registration, and Profile Editing.
  • Timeline & Explorer: View tweets in a chronological feed or explore random posts from the global pool.
  • Social Interactions: Like posts, add comments, and retweet content.
  • Direct Messaging: Send and receive messages (simulated locally between users stored in Users.json).
  • Notifications: System alerts for likes, follows, and messages.

System Requirements

  • Java Development Kit (JDK): Version 11 or higher.
  • Build Tool: Gradle (optional, wrapper included).
  • Dependencies:
    • gson-2.8.6.jar (for JSON parsing)
    • log4j-core / log4j-api (for logging)

Detailed File Analysis & Description

The source code is located in src/main/java/.

🚀 Entry & UI Utilities

  • Main.java: The entry point. It initializes the application loop and directs the user to the Login/Register start screen.
  • ConsoleColors.java: A utility class containing ANSI escape sequences to colorize terminal text (e.g., Red for errors, Green for success, Blue for headers).

📱 Screens & Views

These classes handle the display logic for specific sections of the app:

  • Login.java / Register.java: Handle user input for authentication and account creation.
  • Feed.java / Home.java: Display the user's personal timeline.
  • Expelorer.java: Shows the "Explorer" page (global tweets).
  • Messenger.java / chatPage.java: Interfaces for listing chats and viewing conversation history.
  • Setting.java: Menu for changing passwords, privacy settings, or deleting the account.
  • Info.java: Displays system information or user notifications.

💾 Data Models & JSON Handling

  • obj*.java (e.g., objUser.java, objTwitte.java): Plain Java Objects representing the data models.
  • json*.java (e.g., jsonUsers.java, jsonTwittes.java): These classes are responsible for:
    1. Reading the raw .json files from the disk.
    2. Deserializing them into obj lists using GSON.
    3. Providing helper methods to find specific users or tweets.

⚙️ Logic & Action Controllers

  • submit*.java: These classes contain the business logic for user actions.
    • submitTwitte.java: Creates a new tweet object and saves it to Twittes.json.
    • submitLike.java: Toggles like status on a post.
    • submitMessage.java: Appends a new message to Message.json.
    • submitAction.java: General handler for form submissions.

📂 Local Storage Files (Root Directory)

  • Users.json: Stores user credentials and profile info.
  • Twittes.json: Stores all tweets created in the system.
  • Message.json: Stores chat logs.
  • Notifs.json: Stores pending notifications.

Installation & Running Instructions

1. Clone the Repository

git clone https://github.com/nikelroid/nwitter.git
cd nwitter

2. Build with Gradle

Use the included Gradle wrapper to build the project:

# Linux/Mac
./gradlew build

# Windows
gradlew.bat build

3. Run the Application

You can run it directly via Gradle or by compiling the Java files manually.

Option A: Via Gradle

./gradlew run

Option B: Manual Compilation (if Gradle fails) Ensure the lib folder is in your classpath.

# Compile
javac -cp "lib/*:src/main/java" src/main/java/Main.java

# Run
java -cp "lib/*:src/main/java" Main

Usage Examples

Once the application starts in your terminal:

  1. Navigation: Use the number keys (e.g., 1, 2, 3) to select menu options displayed on the screen.
  2. Login: Enter your username and password when prompted.
  3. Posting: Select the "New Tweet" option, type your text, and press Enter.
  4. Exit: Usually option 4 or 0 (depending on the specific menu) allows you to go back or exit.

Note: Since this is offline, "messaging" another user simply writes to the shared local JSON file. If you log out and log in as the other user, you will see the message.

Contributing

Pull requests are welcome. Since this project relies on specific JSON structures, please ensure any changes to the obj classes are reflected in the json parsing logic to avoid corruption of the database files.

License

Distributed under the MIT License.

Contact

Project Maintainer - GitHub Profile

About

A standalone, terminal-based implementation of the Nwitter social network that operates entirely offline, using local JSON files for data persistence and ANSI codes for a colorful command-line interface.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages