Architecture
Here is the complete architecture of a Zap.ts application compared to a traditional Next.js application.
Overview
Zap.ts architecture is designed to be modular, scalable, and easy to maintain. It leverages the power of TypeScript and modern web development practices to provide a robust foundation for building applications.
Since Zap.ts is built on top of Next.js, it inherits all the features and benefits of the Next.js framework while introducing its own conventions and best practices.
Below, we will compare the architecture of a Zap.ts application with that of a traditional Next.js application.
Dependency Overview
Zap.ts builds on top of Next.js, extending its classic dependencies and adding many more for enhanced features, developer experience, and scalability. Dependencies are grouped below for clarity.
Classic Dependencies
next
: The core React framework for server-side rendering, routing, and static site generation.react
: The foundational library for building user interfaces.react-dom
: Provides DOM-specific methods for React.tailwindcss
: Utility-first CSS framework for rapid UI development.
Zap.ts Additional Dependencies
@ai-sdk/openai
: Integrates OpenAI models for AI features.@ai-sdk/mistral
: Integrates Mistral models for AI features.@ai-sdk/react
: React bindings for AI SDK.@bprogress/next
: Progress bar for Next.js apps.@flags-sdk/posthog
: Feature flags and analytics integration.@hookform/resolvers
: Validation resolvers for React Hook Form.@mdx-js/loader
,@mdx-js/react
: MDX integration for JSX in Markdown.@neondatabase/serverless
: Serverless PostgreSQL driver for scalable DB access.@next/bundle-analyzer
: Bundle analysis for Next.js apps.@orpc/client
,@orpc/react-query
,@orpc/server
: oRPC for typed remote procedure calls and API integration.@polar-sh/better-auth
,@polar-sh/sdk
: Payment processing integrated with Better Auth.@react-email/components
: Build and send emails with React components.@tanstack/react-query
,@tanstack/react-query-devtools
: Powerful data fetching and caching for React.@types/mdx
: TypeScript types for MDX.@vercel/analytics
,@vercel/speed-insights
: Analytics for Vercel-hosted apps and performance monitoring.ai
: Vercel AI SDK for LLMs and generative AI features.better-auth
: Authentication solution for modern apps.class-variance-authority
: Utility for managing class names and variants in React.client-only
: Next.js component for client-only rendering.clsx
: Utility for constructing className strings conditionally.cmdk
: Command menu component for React.date-fns
: Modern date utility library.dotenv
: Loads environment variables from.env
files.drizzle-orm
: TypeScript ORM for SQL databases, with migration and schema tools.embla-carousel-react
: Carousel component for React.flags
: Feature flagging and remote config.gray-matter
: Parse front matter from Markdown files.input-otp
: One-time password input component for React.lucide-react
: Icon library for React.motion
: Animation library for React.next-mdx-remote
: Load MDX content remotely in Next.js.next-sitemap
: Sitemap generation for Next.js apps.next-themes
: Theme switching for Next.js apps.nuqs
: Type-safe URL search params for React.pg
: PostgreSQL client for Node.js.posthog-js
,posthog-node
: Analytics and event tracking.radix-ui
: Primitives for building accessible UI components.react-day-picker
: Date picker component for React.react-email
: Email templates and sending with React.react-hook-form
: Form management for React.react-resizable-panels
: Resizable panel UI for React.react-syntax-highlighter
: Syntax highlighting for code blocks.recharts
: Charting library for React.resend
: Email sending service.schema-dts
: TypeScript types for schema.org.serialize-javascript
: Serialize JS data for transfer.server-only
: Next.js component for server-only rendering.sonner
: Toast notification library for React.tailwind-merge
: Merge Tailwind CSS classes intelligently.tailwindcss-animate
: Animation utilities for Tailwind CSS.vaul
: Drawer component for React.web-push
: Push notifications for web apps.zod
: TypeScript-first schema validation.zustand
: State management for React.
Classic Dev Dependencies
@biomejs/biome
: Fast linter and formatter for TypeScript/JavaScript.@tailwindcss/postcss
: PostCSS plugin for Tailwind integration.@types/*
: TypeScript type definitions for Node, React, etc.typescript
: Type-safe JavaScript development.
Zap.ts Additional Dev Dependencies
@react-email/preview-server
: Development server for previewing React Email templates.create-zap-app
: CLI for creating and managing Zap.ts projects.cross-env
: Run scripts that set and use environment variables across platforms.drizzle-kit
: CLI for Drizzle ORM migrations and schema generation.react-scan
: Library to automatically detects performance issues in your React app.ultracite
: AI-powered linter/formatter for collaborative coding between humans and AI.
Zap.ts also includes many dev tools and scripts for database management, email previews, code analysis, and more, making it a full-featured boilerplate for modern web apps.
Files & Folders
In the below section, we explain all files and folders present in a typical Zap.ts project structure compared to a standard Next.js project. Next to each file, you'll find a color code (green, yellow, and red) indicating its status.
- 🟢 Added
- 🟡 Modified
- 🔴 Removed
Root & Public
Removed Vercel default files and added standard files for a better SEO (Search Engine Optimization).
Added a service worker for PWA (Progressive Web App) support with push notification capabilities.
Added custom fonts for the project such as Geist.
Replaced default Next.js favicon with Zap.ts favicon.
Replaced default Next.js layout with a custom layout in Zap.ts with shadcn/ui integration, Geist font, additional metadata for better SEO (Search Engine Optimization), custom providers injection and Vercel analytics support depending on the environment.
Metadata
Added Apple Touch Icon for better SEO (Search Engine Optimization).
Configuration file for Geist font to be used in the application.
Added standard icon for better SEO (Search Engine Optimization).
Dynamic Open Graph image generation route using OG Image to create social media preview images on the fly.
Configuration file for the Web App Manifest to provide metadata for the application when installed on a device or added to the home screen as a PWA (Progressive Web App).
Error Handling
Global error handling component for the application with a sophisticated error messages management.
Beautiful custom 404 page for handling "Not Found" errors in the application.
IDE-Specific Files
Contains MCP (Model Context Protocol) that allows LLMs in Cursor to get more context with external services such as Supabase, PostHog, and more.
Similar to .gitignore
, this file specifies which files and directories should be ignored by Cursor.
Contains Visual Studio Code specific settings and configurations such as MCP (Model Context Protocol), debugging configurations, and more.
Contains Windsurf specific settings and configurations such as MCP (Model Context Protocol).
Docker Files
Similar to .gitignore
, this file specifies which files and directories should be ignored by Docker.
Contains the instructions for building a Docker image provisioning a PostgreSQL database along with the application.
Contains the instructions for building a Docker image for the application following Next.js Docker best practices.
Contains the configuration for Docker Compose to define and run multi-container Docker applications (such as Zap.ts and PostgreSQL).
Configurations
Configuration file for Next.js that includes additional settings for CSP (Content Security Policy) and Permissions Policy, sets up Typed Routes by default, adds extra security headers, configures sw.js, and supports MDX along with Bundle Analyzer.
Configuration file for npm with additional scripts for Biome, Drizzle ORM, Next.js, React Email and more. Also includes lint-staged configuration with Ultracite preset.
TypeScript configuration file with paths and settings optimized for Zap.ts such as strictNullChecks
.
Configuration file for shadcn/ui, a set of accessible and customizable React components.
Configuration file for Drizzle ORM in development mode.
Configuration file for Drizzle ORM in production mode.
Configuration file for next-sitemap, a sitemap generation tool for Next.js applications.
Specifies which files and directories should be ignored by Git, modified to include additional files and directories.
Pages
Added protected routes for authenticated users with a sidebar layout. This includes pages for account management, notifications, settings, and billing. Included pages are: /app
, /app/account
(WIP), /app/notifications
(WIP), /app/settings
(WIP).
Added billing routes for user billing information and a billing success page. Included pages are: /app/billing
, /app/billing/success
.
Added public authentication routes for user login, registration, password recovery, and mail verification. Included pages are: /forgot-password
, /login
, /mail-verified
, /register
, and /reset-password
.
Added public legal routes for cookie policy, privacy policy, and terms of service. Included pages are: /cookie-policy
, /privacy-policy
, and /terms-of-service
.
Added public blog routes for displaying blog posts and a blog landing page. This includes dynamic routing for individual blog posts based on their slug. Included pages are: /blog
, /blog/[slug]
.
Public landing page for the application.
Waitlist page for users to join the waitlist. Included pages are: /waitlist
.
Default Next.js homepage, replaced by a custom homepage in Zap.ts.
Routes
Authentication API route for handling all auth-related requests with Better Auth.
RPC API route for handling all RPC-related requests with oRPC.
Components
Hooks
Custom hook for detecting mobile devices and handling mobile-specific logic. This is needed by shadcn/ui.
Custom hook for managing body scroll locking in modals and other components.
Custom hook for implementing cooldowns on actions (e.g., mail ratelimits).
Libraries
Custom fetch wrapper for making API requests with Zod validation and error handling, it works in Edge and Node.js environments.
Plugin management library for handling Zap.ts plugins.
Utility functions such as cn
(class names) that is needed by shadcn/ui.
Emails
Contains email templates and allows for easy customization and management of email content through a mail server using React Email.
Middleware
Custom middleware for handling requests and responses in Zap.ts. It integrates plugins in its logic to provide a seamless experience across the application.
Providers
Theme provider for managing light and dark themes in the application with next-themes.
Instrumentation
Instrumentation for the Edge runtime environment.
Instrumentation for the Node.js runtime environment.
Shared instrumentation code for both Edge and Node.js environments, following Next.js instrumentation guidelines.
Zap.ts Specific
Configuration files for Zap.ts.
Type definitions for Zap.ts configuration.
Zap.ts plugin directories such as auth
, blog
, and waitlist
. Each plugin contains its own routes, components, hooks, and other necessary files to provide specific functionality to the application.
Last updated on