This project serves as a comprehensive case study and reference implementation for applying Test-Driven Development (TDD) and Behavior-Driven Development (BDD) methodologies within a modern React application.
The core objective is to demonstrate how to decouple business logic from UI concerns using Clean Architecture principles, ensuring that the domain rules are testable, maintainable, and independent of the view layer. The chosen domain for this case study is a Volleyball Scoreboard, offering sufficient complexity (set logic, tie-breaks, victory conditions) to validate the architectural approach.
The application follows a layered architecture to enforce separation of concerns:
-
Domain Layer (
src/domain):- Contains pure TypeScript functions representing business rules.
- Framework-agnostic and side-effect free.
- Tested extensively via Unit Tests.
-
Application Layer (
src/stores):- Manages application state using Zustand.
- Acts as the glue between the UI and Domain layers.
- Handles state transitions by delegating logic to the Domain layer.
-
Presentation Layer (
src/components):- React components responsible solely for rendering UI and triggering actions.
- Minimizes logic within components to enhance testability.
We utilize Cucumber.js to define high-level requirements in Gherkin syntax (.feature files). This ensures that the software behavior aligns with business requirements before implementation begins.
- Specs: Located in
tests/features/. - Execution: Scenarios drive the implementation of the UI and integration flows.
The development lifecycle follows the "Red-Green-Refactor" cycle:
- Unit Tests: Written for Domain functions using Vitest.
- Component Tests: Written for React components using React Testing Library.
- Refactoring: Continuous code improvement while maintaining test green state.
- Runtime: Node.js 20+
- Framework: React 19, Vite 7
- Language: TypeScript 5
- State Management: Zustand
- Testing:
- Vitest (Unit/Component)
- Cucumber.js (BDD/E2E)
- React Testing Library
- Styling: Tailwind CSS 4
├── src/
│ ├── domain/ # Pure business logic
│ ├── stores/ # State management (Zustand)
│ ├── components/ # React UI components
│ └── main.tsx # Entry point
├── tests/
│ ├── unit/ # Unit and Component tests
│ ├── features/ # Gherkin feature files (BDD)
│ └── steps/ # Cucumber step definitions
└── package.json
- Node.js 20 or higher
- pnpm (recommended)
pnpm installStart the development server:
pnpm devThis project emphasizes quality assurance through multiple testing layers:
-
Run Unit & Component Tests (TDD):
pnpm test -
Run BDD Scenarios:
pnpm test:bdd
-
Run All CI Checks:
pnpm ci:all
Code quality is enforced via strict linting and formatting rules:
- Linting:
pnpm lint(ESLint) - Formatting:
pnpm format:check(Prettier)
This project is open-source and available under the MIT License.