Skip to content

Full-stack ToDo List application built with Vite, React, Fastify, Fastify Test (app.inject) and Playwright

Notifications You must be signed in to change notification settings

makevoid/vite-fastify-todolist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📝 Todo List App

Todo List Tests Coverage

A professional full-stack todo list application showcasing modern architecture patterns

Built with Node.js Fastify + React + Comprehensive Testing


🧪 Test Suite Excellence

  • 🔬 Backend API Integration Tests - Lightning fast API testing, no mocks (AI could gets confused with mocks)
  • 🌐 End-to-End Tests - Complete user workflow validation (tests via React app)

A professional full-stack todo list application built with modern web technologies and object-oriented architecture. This system demonstrates enterprise-level patterns, comprehensive testing, and clean separation of concerns across both frontend and backend.

🚀 Features

Frontend Capabilities

  • Modern UI Design: Professional business-style interface with Chakra UI v2 components
  • Real-time Updates: Instant todo modifications with optimistic updates
  • Responsive Design: Mobile-first approach with consistent styling
  • Error Handling: Comprehensive error states with user-friendly toast notifications
  • Loading States: Visual feedback for all operations with proper loading indicators
  • Form Validation: Input validation with clear error messages
  • Multiple Operations: Create, update, toggle completion, and delete todos with inline editing

Backend Capabilities

  • RESTful API: Full CRUD operations with proper HTTP methods and status codes
  • Data Persistence: SQLite database with automatic schema management
  • Error Handling: Structured error responses with detailed messages
  • Data Validation: Comprehensive input validation using Fastify schemas
  • CORS Support: Cross-origin requests enabled for development and production
  • Auto-documentation: Swagger/OpenAPI docs with Fastify

Good Code Design

  • Object-Oriented Architecture: Clean separation with services, repositories, and controllers
  • Modern React: Hooks-based components with custom hooks for business logic
  • State Management: TanStack React Query for server state with caching and synchronization
  • Testing Strategy: Multi-layered testing with unit, integration, and end-to-end tests
  • Development Experience: Vite hot reload, auto-restart, and comprehensive error feedback

🏗️ Project Structure

Backend Architecture (Node.js/Fastify)

backend/
├── main.js              # Fastify application setup and route definitions
├── models.js            # Database models using Knex query builder
├── schemas.js           # Fastify schemas for request/response validation
├── services.js          # Business logic layer with service classes
├── controllers.js       # HTTP request/response handling layer
├── repositories.js      # Data access layer with repository pattern
├── test_api.test.js     # Jest unit and integration tests
└── package.json         # Node.js dependencies

Object-Oriented Design Patterns:

  • Service Layer: TodoService handles all business logic operations
  • Repository Pattern: TodoRepository manages data access and response model conversion
  • Controller Layer: TodoController handles HTTP concerns and error translation
  • Custom Error Handling: Structured error responses with proper HTTP status codes
  • Dependency Injection: Clean separation of concerns with minimal coupling

Frontend Architecture (React/Vite)

frontend/
├── src/
│   ├── App.jsx                    # Main application component
│   ├── main.jsx                   # Application entry point with providers
│   ├── services/
│   │   ├── ApiService.js          # Base HTTP client class
│   │   └── TodoService.js         # Todo-specific API operations
│   ├── hooks/
│   │   └── useTodos.js            # Custom hook for todo operations
│   └── index.css                  # Global styles
├── package.json             # Dependencies and scripts
├── vite.config.js          # Build configuration
└── playwright.config.js    # E2E test configuration

Service-Oriented Design:

  • Base Service Class: Generic HTTP operations with error handling
  • Specialized Services: Domain-specific API operations extending base class
  • Custom Hooks: React Query integration with service layer abstraction
  • Component Separation: UI components separated from business logic
  • Type-Safe Operations: JSDoc annotations for better development experience

End-to-End Testing

e2e/
├── tests/todo.test.js   # Comprehensive user workflow tests (Playwright)
└── pyproject.toml      # Test configuration

🧪 Testing Strategy & Philosophy

🎯 Testing Excellence: 25 Tests, Zero Compromises

Test Type Count Speed Coverage
🔬 Backend Unit 12 tests ⚡ 0.45s 🎯 100% API
🌐 End-to-End 13 tests 🚀 10.4s 🎭 Full UX
🏆 Total 25 tests ⚡ < 11s 🎉 Complete

Why We Test This Way

Our testing strategy follows the Testing Pyramid principle with three distinct layers that each serve specific purposes:

🔬 Backend Unit Tests (test_api.test.js) - 12 Blazing Fast Tests

Lightning-fast API validation in under 0.5 seconds

🎯 What We Test:

  • All CRUD Operations - Create, Read, Update, Delete, Toggle
  • Error Scenarios - 404s, validation failures, edge cases
  • Data Integrity - Business rules and validation logic
  • Complex Workflows - Multi-step operations and state changes
  • Performance - Sub-second execution with database isolation

🚀 Benefits:

  • Instant feedback - Results in 0.45 seconds
  • 🔒 Perfect isolation - Fresh database per test
  • 📊 Complete coverage - Every API endpoint tested
  • 🛡️ Bulletproof reliability - Zero flaky tests

🌐 End-to-End Tests (e2e/tests/todo.test.js) - 13 Real-World Scenarios

Complete user journey validation with real browser interactions

🎭 What We Test:

  • User Workflows - Complete todo creation, editing, deletion flows
  • Visual Validation - UI state changes and visual feedback
  • Browser Integration - Real Chrome/Firefox testing with Playwright
  • Data Persistence - Changes survive page refreshes and navigation
  • Error Detection - Console error monitoring during interactions
  • Complex Scenarios - Multi-todo operations and edge cases

🎯 Benefits:

  • 🎭 Real user simulation - Actual browser clicks and typing
  • 🏗️ Full system validation - Database → API → UI → User
  • 📸 Visual regression - Screenshot-based change detection
  • 🚀 Production confidence - Tests mirror real usage patterns

🚀 Quick Start

Get Running in 60 Seconds

Prerequisites

  • Node.js 18+ 📦
  • npm ⚙️

1. Clone & Setup

git clone <repository-url>
cd vite-koajs-todolist

# Backend setup 🚀
cd backend
npm install

# Frontend setup ⚛️
cd ../frontend
npm install

2. Development Mode

# Terminal 1: Backend (Port 3000) 🚀
cd backend
npm run dev

# Terminal 2: Frontend (Port 5173) ⚡
cd frontend
npm run dev

3. Run Tests 🧪

# 🔬 Backend unit tests (12 tests, fast)
cd backend
npm test

# 🌐 End-to-end tests (13 tests)
cd e2e
npm test

# ⚡ Quick smoke test
cd e2e
npm run test:e2e

📡 API Reference

All API endpoints are prefixed with /api/todos

Method Endpoint Description
GET / Get all todos
POST / Create new todo
GET /{id} Get specific todo
PUT /{id} Update todo
POST /{id}/toggle Toggle todo completion
DELETE /{id} Delete todo

Example Requests

Create Todo

POST /api/todos
Content-Type: application/json

{
  "title": "Learn FastAPI",
  "description": "Build a todo app with Python and React"
}

Toggle Todo Completion

POST /api/todos/1/toggle

🔧 Development Workflow

Day-to-Day Development

  1. Start Services: Backend (port 8000) + Frontend (port 5173)
  2. Interactive API Docs: Visit http://localhost:8000/docs for Swagger UI
  3. Hot Reload: Both services support hot reload for rapid development
  4. Testing: Run unit tests first, then E2E tests for integration validation

Key Development URLs

Project Structure Overview

vite-python-fastapi-todolist/
├── backend/          # FastAPI backend
│   ├── main.py       # App setup & routes
│   ├── models.py     # Database models
│   ├── services.py   # Business logic
│   └── test_api.py   # Unit tests
├── frontend/         # React frontend  
│   ├── src/
│   │   ├── App.jsx   # Main component
│   │   └── services/ # API services
│   └── package.json
├── e2e/             # End-to-end tests
│   └── test_todo_e2e.py
└── README.md

🎯 Key Features

Production-Ready Todo Management

🎨 Frontend Excellence

  • 🎯 Professional Chakra UI - Business-grade design system
  • ✏️ Inline Editing - Click-to-edit with save/cancel controls
  • Real-time Updates - Instant visual feedback on all operations
  • 🔔 Smart Notifications - Toast messages for user feedback
  • 📱 Responsive Design - Perfect on desktop, tablet, and mobile
  • 🎭 Loading States - Professional loading indicators throughout

🚀 Backend Powerhouse

  • 🔥 FastAPI Framework - Auto-generated OpenAPI documentation
  • 🗃️ SQLite + Knex.js - Lightweight, powerful data persistence
  • 🎯 Full CRUD Operations - Complete REST API with proper HTTP codes
  • 🛡️ Pydantic Validation - Type-safe input validation and serialization
  • 📡 CORS Ready - Cross-origin support for seamless frontend integration
  • 🔧 Structured Errors - Detailed error responses with helpful messages

🌐 API Endpoints

GET    /api/todos          # 📋 Get all todos
GET    /api/todos/{id}     # 🔍 Get specific todo  
POST   /api/todos          # ➕ Create new todo
PUT    /api/todos/{id}     # ✏️ Update todo
POST   /api/todos/{id}/toggle  # ✅ Toggle completion
DELETE /api/todos/{id}     # 🗑️ Delete todo

👨‍💻 User Experience

  • Create todos with title and optional description
  • Toggle completion with satisfying checkbox interactions
  • ✏️ Inline editing with dedicated edit mode and cancel option
  • 🗑️ Delete todos with visual confirmation feedback
  • 🎨 Visual states - Distinct styling for completed vs pending
  • 📊 Progress tracking - Live badge counters showing completion status

🔬 Technical Implementation

This todo application demonstrates several advanced development patterns:

Backend Architecture

  • Layered Architecture: Separation of controllers, services, repositories, and models
  • Repository Pattern: Data access abstraction with service integration
  • Exception Handling: Custom exceptions with proper HTTP status mapping
  • ORM Integration: Peewee ORM with SQLite for simple yet powerful data persistence

Frontend Architecture

  • Service Layer: HTTP client abstraction with TodoService extending ApiService
  • Custom Hooks: useTodos hook integrating TanStack React Query with services
  • State Management: Server state management with optimistic updates
  • Component Design: Professional UI components with consistent styling

Testing Strategy

  • Unit Testing: Backend API testing with pytest and test database isolation
  • E2E Testing: Full user workflow testing with Playwright
  • Error Monitoring: Console error detection during browser interactions
  • Test Isolation: Proper cleanup and setup for reliable test execution

📝 Contributing

  1. Development Setup: Follow the Quick Start guide
  2. Testing: Ensure all tests pass before submitting changes
    • Run backend tests: cd backend && npm test
    • Run E2E tests: python3 -m pytest test_todo_e2e.py -v
  3. Code Style: Follow existing patterns and maintain consistent formatting
  4. Documentation: Update README if adding new features or changing APIs

This todo application serves as a comprehensive example of modern full-stack development with professional patterns, thorough testing, and clean architecture.

About

Full-stack ToDo List application built with Vite, React, Fastify, Fastify Test (app.inject) and Playwright

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages