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

  1. Page Components (page.tsx)

    • Default exports

    • Can be Server or Client Components

    • Define route content

  2. Layout Components (layout.tsx)

    • Wrap page content

    • Shared UI elements

    • Preserve state across navigations

  3. 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)

Structure:

  1. Tailwind directives

  2. CSS variables (theme)

  3. Base styles (body, scrollbar)

  4. Utility classes

  5. 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:

  1. API Routes (app/api/)

    • Next.js server-side endpoints

    • Authentication middleware

    • Database connections

  2. Data Fetching Patterns

  3. 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 dangerouslySetInnerHTML

  • Sanitize 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 vars

  • Validate env vars at build time

Error Handling

Error Boundaries

Not Found Pages

Testing Strategy

Planned Testing Approach

  1. Unit Tests - Jest + React Testing Library

  2. E2E Tests - Playwright

  3. Visual Regression - Percy or Chromatic

  4. Type Checking

Build & Deployment

Build Process

Steps:

  1. TypeScript compilation

  2. Bundle JavaScript/CSS

  3. Optimize images

  4. Generate static pages

  5. Create server functions

Output

Environment Variables

.env.local (development):

.env.production (production):

Monitoring & Analytics

Planned Integrations

  1. Vercel Analytics

    • Web Vitals tracking

    • Performance monitoring

  2. Error Tracking

    • Sentry for error reporting

    • Source map upload

  3. 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


Last Updated: January 2026

Last updated