A retro-styled terminal emulator built with Vanilla JavaScript, engineered to demonstrate Object-Oriented Programming and Clean Architecture principles.
This project simulates a Linux-like terminal environment in the browser. Originally conceived as a simple script, it has been completely refactored into a robust, extensible application.
The primary goal of this refactor was to eliminate "spaghetti code" (specifically, a monolithic switch-case statement) and replace it with a modular architecture that adheres to SOLID principles, making it easy to add new commands without modifying existing core logic.
- Command-Line Interface: Fully functional CLI with a blinking cursor and typing effects.
- Command History: Navigate through previous commands using
UpandDownarrow keys. - Secret Modes: Hidden commands and password-protected features.
- Responsive Design: Optimized for both desktop and mobile devices.
- Extensible Architecture: New commands can be added by simply creating a new class file.
This project implements a simplified version of Clean Architecture to separate concerns between the UI, business logic, and data entities.
Instead of a giant if/else or switch block to handle inputs, I implemented the Command Design Pattern.
- Problem: Adding a new command required modifying the main logic file, violating the Open/Closed Principle.
- Solution: Each command is now a standalone class that extends a base
Commandclass. TheShellsimply looks up the command in a registry and executes it.
The core logic (Shell) and the commands do not depend directly on the global DOM. The UI dependencies are injected, making the system more testable and decoupled.
The codebase is organized by technical responsibility:
src/
├── domain/ # Core business rules (Contracts & Base Classes)
│ └── Command.js
├── core/ # Application Logic (Invoker)
│ └── Shell.js
├── ui/ # Interface Adapter (DOM Manipulation)
│ └── TerminalUI.js
├── commands/ # Concrete Implementations (Use Cases)
│ ├── HelpCommand.js
│ ├── SocialCommand.js
│ └── ...
└── main.js # Composition Root (Wiring everything together)
No frameworks were used. The project leverages native ES6 Modules (import/export) to manage dependencies natively in the browser.
Since this project uses ES Modules, you cannot simply open the index.html file due to CORS policies. You need a local server.
- Node.js (optional, for serving) OR Python
- Clone the repository
git clone [https://github.com/MateusPersonalProjects/terminal-portfolio.git](https://github.com/MateusPersonalProjects/terminal-portfolio.git)
cd terminal-portfolio
- Run with Python (simplest method)
# Python 3
python -m http.server 8000
- Run with Node.js (using
http-serverorlive-server)
npx http-server .
- Access
http://127.0.0.1:8000in your browser.