A minimal and extensible terminal-based implementation of the classic 2048 game written in Python 3.13 using Clean Architecture principles — with no external dependencies.

The architecture follows the Dependency Rule:
domain <- application <- presentation
Each layer depends only on higher-level layers, not on outer ones:
- Domain: Business logic and entities (
Board
,Game
,TileSpawner
) - Application: Use cases and application logic (
GameUseCase
) - Presentation: Presenters and Views — currently implemented for UNIX CLI (Linux/macOS)
Additionally:
- Entrypoints: Contains Dependency Injection (DI) configuration and application entrypoint for CLI version
- Infrastructure: Placeholder for external integrations (currently unused)
- Python >= 3.13 (no external libraries required)
Clone the repository:
git clone https://github.com/csmqbusy/2048-clean-architecture.git
cd 2048-clean-architecture
Set up a virtual environment (recommended):
python3.13 -m venv .venv
source .venv/bin/activate
Or if you using uv
:
uv sync
Run the application:
python src/main.py
src/
├── domain/
│ └── Core business logic (entities, interfaces)
├── application/
│ └── Use cases and interface ports
├── presentation/
│ └── CLI presenter and view
├── entrypoints/
│ └── CLI entrypoint with Dependency Injection
Each layer communicates only with the inner layer via clearly defined interfaces.
Currently supports UNIX CLI (Linux/macOS).
Easily extensible to other platforms (e.g., GUI, Web) by implementing the existing interfaces in application.ports
.
- Fully working 2048 logic
- Clean and testable architecture
- Easy to extend (new UI, AI player, etc.)
- No external dependencies
This project is licensed under the MIT License.
You are free to use, modify, and distribute it with attribution.