Frontend Architecture
This document provides a deep technical dive into the StyxPay frontend architecture, implementation details, and design decisions.
Tech Stack Details
Core Framework: Next.js 15
Why Next.js?
Server-side rendering (SSR) for better SEO
Automatic code splitting and optimization
File-based routing system
Built-in Image and Font optimization
API routes for backend functionality
Excellent developer experience
App Router vs Pages Router We use the App Router (introduced in Next.js 13+) for:
React Server Components by default
Improved data fetching patterns
Nested layouts support
Better performance characteristics
Styling: Tailwind CSS
Configuration (tailwind.config.ts):
Custom Utilities:
.glass-card- Glassmorphism effect.text-gradient- Gradient text.float- Floating animation.shooting-star- Shooting star animation
TypeScript
Configuration (tsconfig.json):
Strict mode enabled
Path aliases configured
Modern ES target
JSX preservation for Next.js
Benefits:
Type safety across the codebase
Better IDE autocomplete
Catch errors at compile time
Self-documenting code
Routing Architecture
File-Based Routing
Layout System
Root Layout (app/layout.tsx):
Applies to all pages
Contains HTML structure
Loads global fonts
Includes metadata
Custom Layouts:
app/demo/layout.tsx- Overrides root layout to remove nav/footer
Layout Hierarchy:
Component Architecture
Component Types
Page Components (
page.tsx)Default exports
Can be Server or Client Components
Define route content
Layout Components (
layout.tsx)Wrap page content
Shared UI elements
Preserve state across navigations
Shared Components (
app/components/)Navbar, Footer
Reusable across pages
Server vs Client Components
Server Components (default):
No JavaScript sent to client
Can access backend directly
Better performance
Used for: Layouts, static content
Client Components ('use client'):
Interactive elements
React hooks (useState, useEffect)
Browser APIs
Used for: Demo dashboard, interactive forms
Example:
Styling Implementation
Global Styles (globals.css)
globals.css)Structure:
Tailwind directives
CSS variables (theme)
Base styles (body, scrollbar)
Utility classes
Animations
CSS Variables:
Benefits:
Consistent theming
Easy theme switching
Tailwind integration
Animation System
Shooting Stars:
Floating:
State Management
Current Approach: React useState
For the demo dashboard:
Why no global state library?
Simple application state
No complex data flows
Local component state sufficient
Reduces bundle size
Future Considerations
As the app grows, consider:
Zustand - Lightweight state management
React Context - Shared state without prop drilling
TanStack Query - Server state management
Jotai - Atomic state management
Data Fetching
Current: Static Demo Data
Demo dashboard uses hardcoded data:
Future: API Integration
Planned architecture:
API Routes (
app/api/)Next.js server-side endpoints
Authentication middleware
Database connections
Data Fetching Patterns
Client-Side Fetching
Image Optimization
Using Next.js <Image> component:
Benefits:
Automatic WebP conversion
Responsive image sizing
Lazy loading
Blur placeholder support
Prevents layout shift
Font Loading Strategy
next/font Integration
Benefits:
Self-hosted fonts (no external requests)
Automatic font subsetting
Zero layout shift
Better performance
Performance Optimizations
1. Code Splitting
Automatic per-route splitting:
Each page is a separate bundle
Shared dependencies in common chunk
Dynamic imports for heavy components
2. Bundle Analysis
Check bundle size:
3. Image Optimization
Serve WebP/AVIF formats
Responsive images
Lazy loading below fold
4. CSS Optimization
Tailwind purges unused styles
Critical CSS inlined
CSS modules for component styles
5. Rendering Strategy
Static pages: Pre-rendered at build time
Dynamic pages: Server-side rendering
Interactive parts: Client-side hydration
Security Considerations
1. XSS Protection
React escapes content by default
Avoid
dangerouslySetInnerHTMLSanitize user input
2. CSRF Protection
SameSite cookies
CSRF tokens for forms
Verify origin headers
3. Content Security Policy
4. Environment Variables
Never expose secrets in client code
Use
NEXT_PUBLIC_prefix for public varsValidate env vars at build time
Error Handling
Error Boundaries
Not Found Pages
Testing Strategy
Planned Testing Approach
Unit Tests - Jest + React Testing Library
E2E Tests - Playwright
Visual Regression - Percy or Chromatic
Type Checking
Build & Deployment
Build Process
Steps:
TypeScript compilation
Bundle JavaScript/CSS
Optimize images
Generate static pages
Create server functions
Output
Environment Variables
.env.local (development):
.env.production (production):
Monitoring & Analytics
Planned Integrations
Vercel Analytics
Web Vitals tracking
Performance monitoring
Error Tracking
Sentry for error reporting
Source map upload
User Analytics
Privacy-focused analytics
Event tracking
Accessibility
ARIA Labels
Keyboard Navigation
Tab order follows visual hierarchy
Focus indicators visible
Escape closes modals
Screen Readers
Semantic HTML
Alt text for images
Skip to content links
Related Documentation
Last Updated: January 2026
Last updated