App Router Architecture
Horse Trust uses Next.js 16’s App Router, which provides file-system based routing with enhanced features like layouts, server components, and streaming.Route Structure
Root Layout
The root layout wraps all pages and provides global UI elements. Location:app/layout.tsx
app/layout.tsx
Key Features:
- Server Component: Runs on the server for optimal performance
- Cookie Access: Reads authentication state from cookies
- Metadata Export: Sets page title and description for SEO
- Global Components: Header and Footer included in all pages
Public Routes
Homepage
Route:/
File: app/page.tsx
app/page.tsx
Marketplace Listing
Route:/marketplace
File: app/marketplace/page.tsx
app/marketplace/page.tsx
- Server-side data fetching
- Dynamic rendering with
force-dynamic - Revalidation every 60 seconds
- Error handling for API failures
Dynamic Routes
Horse Detail Page
Route:/marketplace/[id]
File: app/marketplace/[id]/page.tsx
URL Example: /marketplace/123
Dynamic routes use folder names with square brackets to create parameterized URLs:
params.idcontains the dynamic segment value- Type-safe with TypeScript
- Can be used for data fetching
Authentication Routes
Login Page
Route:/login
File: app/login/page.tsx
Type: Client Component
app/login/page.tsx
Registration Page
Route:/registro
File: app/registro/page.tsx
Purpose: New user registration
Protected Routes
Dashboard
Route:/dashboard
File: app/dashboard/page.tsx
Access: Requires authentication
app/dashboard/page.tsx
- Read authentication cookie
- If cookie missing, redirect to
/login - Validate token with API
- If invalid, redirect to
/login - Render protected content
Server Actions
Server Actions provide secure server-side mutations from client components. Location:app/actions/auth.ts
app/actions/auth.ts
Navigation Patterns
Link Component
Use Next.js Link for client-side navigation:Programmatic Navigation
UseuseRouter in client components:
Server-Side Redirects
Useredirect in server components:
Route Configuration
Dynamic Rendering
Force dynamic rendering for pages that need real-time data:Revalidation
Set revalidation time for data fetching:No Cache
Disable caching for sensitive data:Path Aliases
TypeScript path aliases configured intsconfig.json:
Middleware (Future Enhancement)
Middleware can be added atmiddleware.ts for route protection:
middleware.ts

