A Vue.js 3 application demonstrating clean architecture principles with TypeScript, showcasing a Pokemon card collection management system.
This project implements clean architecture in Vue.js, providing clear separation of concerns across different layers. The application manages Pokemon card collections, packs, and series with a focus on maintainability, testability, and scalability.
The project follows clean architecture principles with four distinct layers:
The core business logic layer containing:
- Entities: Core business models (
Card.ts,Pack.ts,Series.ts) - Repository Interfaces: Abstract contracts for data access
Business logic orchestration layer containing:
- Use Cases: Business logic operations (
CardUseCases.ts,PackUseCases.ts,SeriesUseCases.ts) - Stores: State management using Pinia (
CardStore.ts,PackStore.ts,SeriesStore.ts)
External dependencies and data access layer containing:
- Repository Implementations: Concrete implementations of domain repositories
- API Configuration: External service configuration
UI and user interaction layer containing:
- Views: Page components (
HomeView.vue,PackView.vue) - Components: Reusable UI components (
CardModal.vue,NavBar.vue, etc.) - Router: Navigation configuration
- UI Stores: Presentation-specific state management
- Node.js 22 or higher
- npm
# Clone the repository
git clone <repository-url>
cd vue-clean-architecture
# Install dependencies
npm install# Start development server with hot reload
npm run dev# Type-check, compile and minify
npm run build
# Preview production build
npm run previewThe project includes comprehensive testing setup:
# Run unit tests with Vitest
npm run test:unitUnit tests are located alongside source files in test/ directories and cover:
- Use cases business logic
- Store state management
- Repository implementations
- Vue components
# Run E2E tests in development mode
npm run test:e2e:dev
# Run E2E tests against production build
npm run build
npm run test:e2eE2E tests are located in cypress/e2e/ and test complete user workflows.
- Frontend Framework: Vue.js 3 with Composition API
- Type Safety: TypeScript
- State Management: Pinia with persistence
- Styling: TailwindCSS with DaisyUI components
- Build Tool: Vite
- Testing: Vitest (unit) + Cypress (E2E)
- Validation: Zod schemas
Each layer has a single responsibility, making the codebase easier to understand and maintain.
Dependencies are injected and abstracted, allowing for easy mocking and testing of individual components.
The architecture allows for easy swapping of implementations (e.g., changing from REST API to GraphQL).
New features can be added following established patterns without affecting existing code.
To add a new feature following clean architecture principles:
-
Define Domain Entity (if needed)
// src/domain/entities/NewEntity.ts export interface NewEntity { id: string; // ... other properties }
-
Create Repository Interface
// src/domain/repositories/NewEntityRepository.ts export interface NewEntityRepository { findAll(): Promise<NewEntity[]>; // ... other methods }
-
Implement Repository
// src/infrastructure/repositories-impl/NewEntityRepositoryImpl.ts export class NewEntityRepositoryImpl implements NewEntityRepository { // Implementation details }
-
Create Use Cases
// src/application/use-cases/NewEntityUseCases.ts export class GetAllNewEntitiesUseCase { constructor(private repository: NewEntityRepository) {} // Use case logic }
-
Setup Store
// src/application/stores/NewEntityStore.ts export const useNewEntityStore = defineStore('newEntity', () => { // Store implementation });
-
Create UI Components
<!-- src/presentation/views/NewEntityView.vue --> <template> <!-- Component template --> </template>
src/
├── domain/ # Core business logic
│ ├── entities/ # Business models
│ └── repositories/ # Repository interfaces
├── application/ # Business logic orchestration
│ ├── use-cases/ # Business operations
│ └── stores/ # Application state
├── infrastructure/ # External dependencies
│ ├── config/ # Configuration
│ └── repositories-impl/ # Repository implementations
└── presentation/ # User interface
├── components/ # Reusable UI components
├── views/ # Page components
├── router/ # Navigation
└── stores/ # UI-specific state
The project maintains high code quality through:
- TypeScript: Strong typing throughout the application
- Testing: Comprehensive unit and E2E test coverage
- Prettier: Code formatting consistency
- Clean Architecture: Separation of concerns and dependency inversion
- Follow the established clean architecture patterns
- Write tests for new features
- Ensure type safety with TypeScript
- Format code with Prettier:
npm run format - Run tests before submitting:
npm run test:unit
The project uses vue-tsc for TypeScript type checking with Vue files. Volar extension provides TypeScript language service support for .vue files.