An open API service indexing awesome lists of open source software.

https://github.com/jawherkl/clean-architecture

This repository exists to bridge the gap between theory and practice in software architecture.
https://github.com/jawherkl/clean-architecture

architecture clean-architecture component dip isp lsp ocp paradigms poo solid srp

Last synced: 4 months ago
JSON representation

This repository exists to bridge the gap between theory and practice in software architecture.

Awesome Lists containing this project

README

          

# Clean Architecture Template

A practical implementation of Clean Architecture principles inspired by Robert C. Martin's "Clean Architecture" book. This repository serves as both a reference implementation and a template for new projects.

## ๐Ÿ“– Table of Contents

- [Core Principles](#-core)
- [Repository Structure](#-repository-structure)
- [Getting Started](#-getting-started)
- [Testing Strategy](#-testing-strategy)
- [Documentation](#-documentation)
- [Case Studies](#-case-studies)
- [Contributing](#-contributing)
- [License](#-license)

## ๐Ÿง  Core Principles

This implementation follows the key tenets of Clean Architecture:

1. **Independent of Frameworks**: Core business logic doesn't depend on any external libraries
2. **Testable**: Business rules can be tested without UI, DB, or external services
3. **Independent of UI**: UI can change easily without changing business rules
4. **Independent of Database**: Business rules aren't bound to any specific database
5. **Independent of External Services**: Business rules don't know about external interfaces

## ๐Ÿ—‚ Repository Structure

```
clean-architecture/
โ”‚
โ”œโ”€โ”€ docs/ # Documentation
โ”‚ โ”œโ”€โ”€ foreword.md # Foreword about the project
โ”‚ โ”œโ”€โ”€ preface.md # Project introduction and goals
โ”‚ โ”œโ”€โ”€ acknowledgments.md # Credits and acknowledgments
โ”‚ โ”œโ”€โ”€ principles/ # Architectural principles
โ”‚ โ”‚ โ”œโ”€โ”€ design/ # SOLID principles
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ srp.md # Single Responsibility Principle
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ocp.md # Open/Closed Principle
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ lsp.md # Liskov Substitution Principle
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ isp.md # Interface Segregation Principle
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ dip.md # Dependency Inversion Principle
โ”‚ โ”‚ โ”œโ”€โ”€ component/ # Component cohesion/coupling
โ”‚ โ”‚ โ””โ”€โ”€ architectural/
โ”‚ โ””โ”€โ”€ case-studies/ # Example implementations
โ”‚
โ”œโ”€โ”€ src/ # Source code
โ”‚ โ”œโ”€โ”€ core/ # Enterprise business rules
โ”‚ โ”‚ โ”œโ”€โ”€ entities/ # Business objects with critical business rules
โ”‚ โ”‚ โ”œโ”€โ”€ usecases/ # Application-specific business rules
โ”‚ โ”‚ โ””โ”€โ”€ interfaces/ # Interfaces for outward communication
โ”‚ โ”‚
โ”‚ โ”œโ”€โ”€ infrastructure/ # Outer layer: frameworks, databases, UI
โ”‚ โ”‚ โ”œโ”€โ”€ persistence/ # Database implementations
โ”‚ โ”‚ โ”œโ”€โ”€ web/ # Web framework implementations
โ”‚ โ”‚ โ”œโ”€โ”€ external-services/ # External service integrations
โ”‚ โ”‚ โ””โ”€โ”€ config/ # Configuration management
โ”‚ โ”‚
โ”‚ โ”œโ”€โ”€ application/ # Interface adapters
โ”‚ โ”‚ โ”œโ”€โ”€ controllers/ # Web controllers
โ”‚ โ”‚ โ”œโ”€โ”€ presenters/ # Presenters for response models
โ”‚ โ”‚ โ”œโ”€โ”€ gateways/ # Gateways to external services
โ”‚ โ”‚ โ””โ”€โ”€ mappers/ # Data mappers between layers
โ”‚ โ”‚
โ”‚ โ””โ”€โ”€ main/ # Composition root and entry point
โ”‚ โ”œโ”€โ”€ di/ # Dependency injection configuration
โ”‚ โ”œโ”€โ”€ config/ # Startup configuration
โ”‚ โ””โ”€โ”€ app.js|app.py|etc. # Application entry point
โ”‚
โ”œโ”€โ”€ tests/ # Test suites
โ”‚ โ”œโ”€โ”€ unit/ # Unit tests
โ”‚ โ”‚ โ”œโ”€โ”€ core/ # Tests for business rules
โ”‚ โ”‚ โ””โ”€โ”€ application/ # Tests for interface adapters
โ”‚ โ”œโ”€โ”€ integration/ # Integration tests
โ”‚ โ”œโ”€โ”€ e2e/ # End-to-end tests
โ”‚ โ””โ”€โ”€ test-api/ # Testing API utilities
โ”‚
โ”œโ”€โ”€ examples/ # Example implementations
โ”‚ โ”œโ”€โ”€ video-sales/ # Case study: Video Sales
โ”‚ โ”œโ”€โ”€ embedded/ # Clean Embedded Architecture example
โ”‚ โ””โ”€โ”€ services/ # Service architecture examples
โ”‚
โ”œโ”€โ”€ scripts/ # Utility scripts
โ”‚ โ”œโ”€โ”€ deployment/ # Deployment scripts
โ”‚ โ””โ”€โ”€ code-generation/ # Code generation utilities
โ”‚
โ”œโ”€โ”€ .github/ # GitHub specific files
โ”‚ โ”œโ”€โ”€ workflows/ # CI/CD workflows
โ”‚ โ””โ”€โ”€ ISSUE_TEMPLATE/ # Issue templates
โ”‚
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ README.md # Main project documentation
โ”œโ”€โ”€ LICENSE
โ””โ”€โ”€ Makefile|build.gradle|etc. # Build automation
```

### Key Layers:

1. **Core**: Enterprise business rules and entities
2. **Application**: Application-specific business rules and use cases
3. **Interface Adapters**: Controllers, presenters, and gateways
4. **Infrastructure**: Frameworks, databases, and external services
5. **Main**: Composition root and application entry point

## ๐Ÿš€ Getting Started

### Prerequisites

- Node.js/Python/Java (depending on your implementation)
- Docker (for containerized dependencies)
- Make (for build automation)

### Installation

```bash
git clone https://github.com/JawherKl/clean-architecture.git
cd clean-architecture
npm install # or pip install -r requirements.txt
```

### Running the Application

```bash
make run # or npm start / python main.py
```

## ๐Ÿงช Testing Strategy

We employ a multi-layered testing approach:

```bash
make test # Run all tests
make test-unit # Run unit tests only
make test-int # Run integration tests
make test-e2e # Run end-to-end tests
```

## ๐Ÿ“š Documentation

Explore our comprehensive documentation:

- [Design Principles](docs/principles/design)
- [Component Architecture](docs/principles/component)
- [Case Studies](docs/case-studies)

## ๐Ÿ— Case Studies

Practical implementations included:

1. [Video Sales System](examples/video-sales) - Complete e-commerce example
2. [Embedded Systems](examples/embedded) - Clean Architecture in constrained environments
3. [Microservices](examples/services) - Service-oriented implementations

## ๐Ÿค Contributing

We welcome contributions! Please follow these steps:

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

## ๐Ÿ“œ License

Distributed under the MIT License. See `LICENSE` for more information.

---

**Inspired by**: "Clean Architecture: A Craftsman's Guide to Software Structure and Design" by Robert C. Martin