Application Architecture
This document outlines the core architecture of the ShipKit application, built with Next.js 13+ App Router, TypeScript, and modern React patterns.
Core Technologies
- Framework: Next.js 13+ with App Router
- Language: TypeScript 5.x
- Styling: Tailwind CSS with Shadcn/UI
- Database: PostgreSQL with Drizzle ORM
- CMS: Payload CMS and Builder.io
- Authentication: NextAuth/AuthJS v5
- Email: Resend
- Package Manager: PNPM
App Router Structure
The application uses Next.js 13+ App Router, organized in the /src/app
directory:
Special Files
layout.tsx
- Root layout with providers
not-found.tsx
- Custom 404 page
error.tsx
- Error boundary component
loading.tsx
- Loading states
robots.ts
- Search engine configuration
sitemap.ts
- Dynamic sitemap
manifest.ts
- PWA configuration
Component Organization
Components are organized by feature and responsibility:
Server Architecture
Server-side code follows a clear separation of concerns:
Server Actions
All mutations are handled through server actions:
Services
Business logic is encapsulated in service modules:
Database Layer
Using Drizzle ORM with PostgreSQL:
Migrations
Authentication
Using NextAuth/AuthJS v5 with multiple providers:
Content Management
Dual CMS approach:
- Payload CMS: For structured content and admin
- Builder.io: For visual page building
Type System
Comprehensive type safety throughout:
Performance Optimizations
-
Route Segments:
- Parallel routes for loading states
- Intercepting routes for modals
- Dynamic imports for code splitting
-
Caching:
-
Static Generation:
Security Measures
-
Input Validation:
-
CSRF Protection:
- Built-in Next.js CSRF protection
- Custom token validation
-
Rate Limiting:
Development Guidelines
-
Component Rules:
- Use Server Components by default
- Client Components for interactivity
- Keep state close to where it's used
-
Code Style:
- Strict TypeScript
- ESLint + Prettier
- Conventional Commits
-
Testing Strategy:
- Vitest for unit tests
- Playwright for E2E
- MSW for API mocking
Notes
- All routes use React Server Components by default
- State management through React Context and Server Components
- API routes minimized in favor of Server Actions
- Strong focus on type safety and validation
- Performance optimizations built into architecture
- Security measures implemented at all levels