┌─────────────────────────────────────────────────────────────┐
│ FRONTEND (SPA) │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ Next.js 14 + React + TypeScript │ │
│ │ ┌────────────┐ ┌────────────┐ ┌────────────┐ │ │
│ │ │ Pages │ │ Components │ │ Hooks │ │ │
│ │ │ (SSR/CSR) │ │ (shadcn) │ │ (WebSocket)│ │ │
│ │ └────────────┘ └────────────┘ └────────────┘ │ │
│ │ │ │
│ │ ┌────────────┐ ┌────────────┐ ┌────────────┐ │ │
│ │ │ Services │ │ Theme │ │ Types │ │ │
│ │ │ (API Calls)│ │ Provider │ │(TypeScript)│ │ │
│ │ └────────────┘ └────────────┘ └────────────┘ │ │
│ └──────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
│ HTTP/HTTPS + WebSocket
▼
┌─────────────────────────────────────────────────────────────┐
│ BACKEND (API) │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ Express.js + Node.js Server │ │
│ │ ┌────────────┐ ┌────────────┐ ┌────────────┐ │ │
│ │ │ Routes │ │ Middleware │ │ WebSocket │ │ │
│ │ │ (REST API) │ │(CORS/Auth) │ │ Server │ │ │
│ │ └────────────┘ └────────────┘ └────────────┘ │ │
│ │ │ │
│ │ ┌────────────┐ ┌────────────┐ ┌────────────┐ │ │
│ │ │ Validation │ │ Database │ │ Swagger │ │ │
│ │ │ (Zod) │ │ (Drizzle) │ │ Docs │ │ │
│ │ └────────────┘ └────────────┘ └────────────┘ │ │
│ └──────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
│ SQL Queries
▼
┌─────────────────────────────────────────────────────────────┐
│ DATABASE │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ PostgreSQL (Neon Cloud) │ │
│ │ ┌────────────┐ ┌────────────┐ │ │
│ │ │ Matches │ │ Commentary │ │ │
│ │ │ Table │──────────────────│ Table │ │ │
│ │ └────────────┘ └────────────┘ │ │
│ └──────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
- Next.js 14+ (App Router)
- Server-Side Rendering (SSR)
- Static Site Generation (SSG)
- Client-Side Rendering (CSR)
- File-based routing
- API routes support
- TypeScript 5+
- Full type safety
- IntelliSense support
- Compile-time error checking
- Interface definitions
-
Tailwind CSS v4
- Utility-first CSS
- Custom design system
- Responsive breakpoints
- Dark mode support
-
shadcn/ui
- Radix UI primitives
- Accessible components
- Customizable
- Copy-paste components
-
Radix UI
- Accessible primitives
- Unstyled components
- Keyboard navigation
- ARIA compliant
-
Lucide React
- Modern icon library
- Tree-shakeable
- Consistent design
- 1000+ icons
-
next-themes
- Dark/Light mode
- System preference
- Persistent storage
- No flash on load
-
React Hooks
- useState, useEffect
- Custom useWebSocket
- useRouter, useParams
-
class-variance-authority
- Component variants
- Type-safe props
- Style composition
-
clsx + tailwind-merge
- Conditional classes
- Merge Tailwind classes
- Conflict resolution
-
Node.js 20+
- Modern JavaScript
- ES modules
- Async/await
- Event-driven
-
Express.js 5
- Fast, unopinionated
- Middleware support
- Routing
- HTTP utilities
-
PostgreSQL (Neon Cloud)
- Relational database
- ACID compliance
- JSON support
- Full-text search
-
Drizzle ORM
- Type-safe queries
- SQL-like syntax
- Migration support
- Schema definition
- WebSocket (ws)
- Bidirectional communication
- Low latency
- Event-based
- Auto-reconnect (client)
- Zod
- TypeScript-first
- Runtime validation
- Type inference
- Error messages
- Swagger/OpenAPI
- Interactive API docs
- Request testing
- Schema definitions
- Auto-generated
-
Arcjet
- Rate limiting
- Bot protection
- Security rules
- DDoS protection
-
CORS
- Cross-origin requests
- Credential support
- Origin whitelisting
-
dotenv
- Environment variables
- Configuration management
- Secrets protection
-
Node --watch
- Hot reload
- Auto-restart
- Development mode
User visits /
↓
Next.js renders page (SSR)
↓
Client component mounts
↓
useEffect calls matchesService.getMatches()
↓
API client sends GET /api/matches
↓
Backend validates & queries database
↓
Returns matches array
↓
Component updates state
↓
UI re-renders with match cards
Component mounts
↓
useWebSocket hook connects to ws://localhost:8000/ws
↓
Connection established
↓
Backend broadcasts new match/commentary
↓
Client receives message
↓
Hook updates lastMessage state
↓
useEffect detects change
↓
Component updates matches array
↓
UI re-renders with new data
User clicks match card
↓
Router navigates to /match/[id]
↓
Page component extracts id from params
↓
Parallel API calls:
- matchesService.getMatch(id)
- commentaryService.getCommentary(id)
↓
Backend fetches from database
↓
Returns match + commentary data
↓
Component updates state
↓
UI renders match details + commentary list
- Environment Variables: Secrets not in code
- HTTPS Ready: Production SSL support
- XSS Protection: React escapes by default
- Type Safety: TypeScript prevents errors
- CORS: Origin whitelisting
- Rate Limiting: Arcjet protection
- Input Validation: Zod schemas
- SQL Injection: Drizzle ORM parameterized queries
- Environment Variables: dotenv for secrets
- SSR: Faster initial page load
- Code Splitting: Automatic by Next.js
- Image Optimization: Next.js Image component
- CSS Optimization: Tailwind purges unused
- Lazy Loading: Dynamic imports
- WebSocket: Efficient real-time updates
- Connection Pooling: Database connections
- JSON Parsing: Only when needed
- Middleware Order: Optimized for performance
- Query Optimization: Indexed database columns
- Caching Ready: Can add Redis
Mobile: < 640px (sm)
Tablet: 640-1024px (md, lg)
Desktop: > 1024px (xl, 2xl)- Mobile-First: Base styles for mobile
- Progressive Enhancement: Add features for larger screens
- Flexible Grid: CSS Grid & Flexbox
- Fluid Typography: Responsive font sizes
- Touch-Friendly: Large tap targets
- Primary: Action buttons, links
- Secondary: Supporting elements
- Accent: Highlights
- Muted: Background, subtle text
- Destructive: Errors, warnings
- Success/Warning/Info: Status badges
- Headings: Bold, clear hierarchy
- Body: Readable, optimal line height
- Mono: Code, technical data
- Cards: Match displays, commentary
- Buttons: Actions, navigation
- Badges: Status indicators
- Tabs: Content filtering
- React useState: Component-level state
- React useEffect: Side effects
- Custom Hooks: Reusable logic (useWebSocket)
- API Services: Fetch data from backend
- WebSocket: Real-time updates
- No Redux: Simple enough without it
- Unit Tests: Jest + React Testing Library
- Integration Tests: Playwright/Cypress
- Type Checking: TypeScript compiler
- Linting: ESLint
- Unit Tests: Jest/Mocha
- Integration Tests: Supertest
- API Tests: Swagger/Postman
- Database Tests: Test database
- Single server deployment
- Direct database connection
- WebSocket per connection
- Load Balancer: Nginx/HAProxy
- Horizontal Scaling: Multiple backend instances
- Redis: Caching + WebSocket pub/sub
- CDN: Static asset delivery
- Database: Read replicas, connection pooling
- Monitoring: Logging, metrics, alerts
- Start backend:
cd backend && npm run dev - Start frontend:
cd frontend && npm run dev - Edit code (hot reload enabled)
- Test in browser
- Check API docs:
http://localhost:8000/api-docs
- Build frontend:
npm run build - Set environment variables
- Deploy backend to Node hosting (Heroku, Railway, Render)
- Deploy frontend to Vercel/Netlify
- Configure environment URLs
- Test live deployment
- Co-location: Related files together
- Feature-based: Group by feature
- Reusability: Shared components in ui/
- Type Safety: Types in types/
- Separation: Logic in services/, UI in components/
- Layered Architecture: Routes → Validation → Database
- Single Responsibility: Each file has one purpose
- Modularity: Easy to add new features
- Configuration: Environment-based settings
- Next.js App Router with React Server Components
- Fast initial page load
- SEO friendly
- Progressive enhancement
- next-themes for theme management
- CSS variables for colors
- System preference detection
- Smooth transitions
- WebSocket connection
- Auto-reconnect on disconnect
- Event-based messaging
- Optimistic UI updates
- Tailwind breakpoints
- Mobile-first approach
- Flexible layouts
- Touch-optimized
- Type Safety: TypeScript everywhere possible
- Component Composition: Reusable, composable components
- Error Handling: Try-catch blocks, user feedback
- Loading States: Skeleton screens, spinners
- Accessibility: ARIA labels, keyboard navigation
- Performance: Code splitting, lazy loading
- Security: Input validation, CORS, environment variables
- Documentation: Code comments, README files
- Consistency: Naming conventions, file structure
- Scalability: Modular design, easy to extend
This architecture provides a solid foundation for a modern, scalable, and maintainable sports tracking application! 🚀