A modern boilerplate for building full-stack React applications with TanStack Start, implementing Clean Architecture principles for maintainable, testable, and scalable code.
- React 19.1.1 with TypeScript
- TanStack Start 1.132.19 - Full-stack React framework
- TanStack Router 1.132.19 - Type-safe file-based routing
- Tailwind CSS 4.1.13 - Utility-first CSS framework
- shadcn/ui - High-quality accessible component library
- Radix UI - Primitive components for complex UI
- Lucide React - Beautiful icon library
- TanStack Start Server Functions - Full-stack capabilities
- Prisma - Modern database toolkit and ORM
- SQLite - Lightweight database
- Vite 7.1.7 - Lightning-fast build tool
- TypeScript 5.9.2 - Type safety and enhanced DX
- ESLint - Code linting with comprehensive presets
- Prettier - Code formatting
- Vitest - Fast unit testing framework
- Node.js (version 18 or higher)
- pnpm or yarn or pnpm
-
Clone the repository:
git clone git@github.com:felipestanzani/tanstack-start-ca.git cd tanstack-start-ca -
Install dependencies:
pnpm install
-
Set up environment variables:
Create a
.envfile in the root directory with the following content:# Database DATABASE_URL="file:./dev.db"
-
Set up the database:
Generate the Prisma client from the schema:
pnpm db:generate
Create the SQLite database and apply the schema:
pnpm db:push
pnpm devThe application will be available at http://localhost:3000
pnpm dev- Start development serverpnpm build- Build for productionpnpm preview- Preview production build
pnpm lint- Run ESLintpnpm format- Format code with Prettier
pnpm test- Run tests with Vitestpnpm test:run- Run tests oncepnpm test:watch- Run tests in watch modepnpm test:coverage- Run tests with coverage
pnpm db:generate- Generate Prisma clientpnpm db:push- Push schema changes to databasepnpm db:migrate- Create and apply migrationspnpm db:studio- Open Prisma Studio for database management
This project follows Clean Architecture principles with clear separation of concerns and dependency inversion. For detailed architecture documentation, see CLEAN_ARCHITECTURE.md.
tanstack-start-clean-architecture/
βββ prisma/ # Database schema and migrations
β βββ schema.prisma
βββ src/
β βββ core/ # Core Business Logic (Domain + Application Layers)
β β βββ domain/ # π¦ Domain Layer (Innermost)
β β β βββ entities/ # Business entities with domain logic
β β β β βββ base.entity.ts # Base entity with common properties
β β β β βββ counter.entity.ts # Counter business entity
β β β β βββ index.ts # Domain entities barrel export
β β β βββ events/ # Domain events
β β β β βββ index.ts
β β β βββ repositories/ # Repository interfaces (contracts)
β β β β βββ counter.repository.ts
β β β β βββ index.ts
β β β βββ value-objects/ # Domain value objects
β β β βββ index.ts
β β βββ application/ # π¨ Application Layer
β β βββ dtos/ # Data Transfer Objects
β β β βββ index.ts
β β βββ services/ # Application services
β β β βββ index.ts
β β βββ use-cases/ # Use cases (business operations)
β β βββ counter/
β β β βββ get-counter.use-case.ts
β β β βββ increment-counter.use-case.ts
β β β βββ index.ts
β β βββ index.ts
β βββ infrastructure/ # π© Infrastructure Layer
β β βββ di/ # Dependency Injection
β β β βββ container.ts # DI container
β β β βββ index.ts
β β βββ repositories/ # Repository implementations
β β βββ prisma-counter.repository.ts
β β βββ index.ts
β βββ presentation/ # πͺ Presentation Layer
β β βββ controllers/ # HTTP request handlers
β β βββ counter.controller.ts
β β βββ index.ts
β βββ components/ # React UI components
β β βββ theme-provider.tsx
β β βββ ui/ # shadcn/ui components
β β βββ button.tsx
β βββ lib/ # Utility functions
β β βββ utils.ts
β βββ routes/ # File-based routing (TanStack Router)
β β βββ __root.tsx # Root layout
β β βββ index.tsx # Home page
β βββ styles/ # Global styles
β β βββ app.css
β βββ tests/ # Test files organized by layer
β β βββ application/
β β β βββ use-cases/
β β β βββ get-counter.use-case.test.ts
β β βββ domain/
β β β βββ entities/
β β β βββ counter.entity.test.ts
β β βββ setup.ts
β βββ router.tsx # Router configuration
β βββ routeTree.gen.ts # Generated route tree
βββ components.json # shadcn/ui configuration
βββ package.json
βββ tsconfig.json # TypeScript configuration
βββ vite.config.ts # Vite configuration
βββ eslint.config.mjs # ESLint configuration
βββ CLEAN_ARCHITECTURE.md # Detailed architecture documentation
βββ README.md
The innermost layer containing pure business logic:
- Entities: Core business objects with domain rules (e.g.,
Counter) - Repository Interfaces: Contracts for data access
- Domain Events: Business events within the domain
- Value Objects: Immutable domain concepts
Orchestrates business operations:
- Use Cases: Application-specific business rules
- DTOs: Data transfer objects for layer communication
- Services: Application services coordinating domain objects
Handles external concerns:
- Repository Implementations: Concrete data access implementations
- Dependency Injection: DI container for managing dependencies
- External Services: Third-party integrations
User interface and API endpoints:
- Controllers: HTTP request/response handlers using TanStack Start
- Routes: Application routing with TanStack Router
- Components: React UI components
The project includes comprehensive testing organized by architecture layer:
src/tests/
βββ application/ # Application layer tests
βββ domain/ # Domain layer tests
βββ infrastructure/ # Infrastructure layer tests
βββ presentation/ # Presentation layer tests
- Unit Tests: Testing individual components and business logic
- Integration Tests: Testing layer interactions
- End-to-End Tests: Testing complete user workflows
This project uses SQLite with Prisma for data persistence.
The application uses a simple Counter table with the following structure:
model Counter {
id String @id
value Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}The counter persistence uses database storage (PrismaCounterRepository):
- Implements the
CounterRepositoryinterface - Uses SQLite for data persistence
- Supports the default counter with automatic creation
- Handles upsert operations for counter updates
- Maintains full compatibility with existing use cases
Note: The Prisma client is generated to the standard location (node_modules/@prisma/client) for better ES module compatibility with Vite/TanStack Start.
This project uses TanStack Query for all client-server state synchronization and UI data fetching. Benefits include:
- Automatic caching and background updates
- Optimistic UI for instant feedback on mutations
- Error handling and retry logic out of the box
- DevTools for query/mutation debugging
- The
QueryClientis configured insrc/lib/query-client.tsand provided at the root viaQueryClientProviderinsrc/routes/__root.tsx. - React Query DevTools are enabled in development for easy debugging.
useCounter()β Fetches the current counter valueuseIncrementCounter()β Increments the counter (with optimistic update)
See src/hooks/use-counter.ts for implementation details.
The home page demonstrates:
- Live counter value with auto-refresh
- Increment button with instant UI feedback
- Loading and error states
- Optimistic updates for a snappy user experience
- Increment the counter with instant feedback
- UI disables button during loading/mutation
- Error messages and retry options for failed requests
- Powered by TanStack Query hooks and server functions
This boilerplate includes:
- β Clean Architecture implementation
- β Type-safe routing with TanStack Router
- β Server-side rendering with TanStack Start
- β Database integration with Prisma + SQLite
- β UI components with shadcn/ui
- β Testing setup with Vitest
- β Code quality with ESLint and Prettier
- β Dependency injection container
- β Example counter feature demonstrating architecture
- β State management with TanStack Query (caching, mutations, optimistic updates)
- β React Query DevTools for development
- β Increment counter with optimistic UI
- TanStack Start Documentation
- TanStack Router Documentation
- Clean Architecture by Robert C. Martin
- Prisma Documentation
- shadcn/ui Documentation
Contributions are welcome! Please read our contributing guidelines and submit pull requests for any improvements.
This project is licensed under the MIT License - see the LICENSE file for details.
- Clean Architecture principles by Robert C. Martin
- TanStack team for amazing React tools
- shadcn for the beautiful UI components
- The open-source community for inspiration and tools