A new README for the combined project with setup from the Flashpoint Ultimate torrent. New feature docs for streaming, proxy sign-in and game saves; deployment, upgrade and streaming READMEs updated for the single compose file; the project renamed throughout.
Architecture Documentation
This directory contains comprehensive architecture documentation for Flashpoint Web, detailing the system design, service communication patterns, and data flows.
Documentation Structure
1. System Architecture
Deep dive into the complete system architecture
Topics covered:
- Two-service architecture overview (Frontend, Backend with integrated game serving)
- Technology stack and rationale
- Service responsibilities and boundaries
- Database architecture (flashpoint.sqlite and user.db)
- Game content serving architecture (integrated in backend)
- Security architecture (JWT, RBAC)
- File system layout
- Scalability considerations
- Development vs production modes
- Error handling strategies
- Monitoring and logging
When to read: Start here for a high-level understanding of the entire system.
2. Service Communication
Communication patterns and protocols between Frontend and Backend
Topics covered:
- Frontend ↔ Backend communication (REST API)
- Integrated game file serving in backend
- Backend game routes (
/game-proxy/*and/game-zip/*) - API endpoints by domain
- Authentication token flow
- Request/response formats
- Error handling and retry logic
- Rate limiting
- CORS configuration
- Performance optimization
- WebSocket (future considerations)
When to read: When you need to understand how services communicate or add new API endpoints.
3. Data Flow Diagrams
Complete request/response flows with Mermaid diagrams
Topics covered:
- Game browse and search flow
- Game detail view flow
- Filter options loading
- Image loading with lazy loading
- Pagination flow
- Real-time search with debouncing
- Multi-select filter flow
- Sort order changes
- Cache management (stale-while-revalidate)
When to read: When debugging data flow issues or understanding user journeys through the system.
4. Authentication Flow
Complete authentication and authorization flow
Topics covered:
- User registration flow
- User login flow
- Protected request flow
- Token refresh flow (automatic)
- Logout flow
- Role-based access control (RBAC)
- Permission model
- JWT token structure
- Guest mode (optional authentication)
- Security best practices
- Common authentication issues
When to read: When implementing authentication features or troubleshooting auth issues.
5. Game Launch Flow
Detailed game playing flow from click to play
Topics covered:
- Game launch request flow
- ZIP mounting flow
- Game content loading (Flash and HTML5)
- HTTP proxy server request handling
- MIME type detection
- Ruffle player integration
- Full game launch example
- Error handling
- Performance optimization
When to read: When debugging game loading issues or understanding how games are served.
6. Play Tracking Flow
Session tracking and statistics aggregation
Topics covered:
- Session start flow
- Session end flow
- Statistics aggregation (per-game and per-user)
- Flashpoint database integration
- Statistics retrieval and visualization
- Abandoned session cleanup
- Database schema and indexing
- Privacy and data management
When to read: When implementing analytics features or understanding play session tracking.
Architecture Diagrams
All architecture documents include Mermaid diagrams for visual representation. These diagrams are rendered automatically in GitHub and most Markdown viewers.
Key Diagram Types
System Diagrams: Show the overall architecture and service relationships
graph TB
Frontend --> Backend
Backend --> Database
Sequence Diagrams: Show step-by-step interactions between components
sequenceDiagram
User->>Frontend: Click button
Frontend->>Backend: API call
Backend->>Database: Query
Flow Diagrams: Show decision trees and process flows
graph LR
Start --> Decision{Condition?}
Decision -->|Yes| ActionA
Decision -->|No| ActionB
Key Architectural Patterns
1. Service Layer Pattern
Routes → Middleware → Services → Database
Business logic lives in service classes, routes are thin controllers.
2. Repository Pattern (Implicit)
Database access is abstracted through DatabaseService and
UserDatabaseService.
3. Middleware Pipeline
Express middleware chains handle cross-cutting concerns:
- Authentication (JWT verification)
- Authorization (RBAC)
- Logging (activity tracking)
- Error handling
- Rate limiting
4. State Management
Frontend:
- Server state: TanStack Query
- UI state: Zustand
- URL state: React Router
- Form state: React Hook Form
Backend:
- Stateless (JWT for session)
- Database as source of truth
5. Separation of Concerns
- Backend: Metadata, authentication, business logic
- Game Service: File serving, proxying, ZIP mounting
- Frontend: UI, client-side state, routing
Technology Decisions
Why TypeScript?
- Type safety across frontend and backend
- Better IDE support and refactoring
- Shared types between services
- Reduced runtime errors
Why BetterSqlite3?
- Synchronous API (simpler code)
- Better performance than async wrappers
- Perfect for read-heavy workloads
- WAL mode for concurrent reads
Why TanStack Query?
- Automatic caching and invalidation
- Background refetching
- Optimistic updates
- Loading and error states
- Deduplication
Why Monorepo?
- Shared TypeScript types
- Coordinated development
- Single deployment
- Consistent tooling
Why Two Services?
- Clear separation of concerns
- Frontend focuses on UI and client-side state
- Backend handles all business logic and content serving
- Simplified deployment (2 containers instead of 3)
- Easier to reason about
Common Workflows
Adding a New API Endpoint
- Define types in
shared/types(if monorepo) or duplicate types - Create route in
backend/src/routes/ - Add middleware (auth, permissions, validation)
- Implement service method in
backend/src/services/ - Add API client method in
frontend/src/lib/api.ts - Create custom hook in
frontend/src/hooks/ - Use hook in component
- Update documentation
Adding a New Permission
- Add permission to database migration
- Update default role permissions
- Add middleware check in route
- Update frontend
ProtectedRouteusage - Test with different roles
Adding a New Database Table
- Create migration file in
backend/src/migrations/ - Define schema with indexes
- Add service methods for CRUD
- Add TypeScript types
- Run migration on startup
- Test with sample data
Performance Optimization
Database
- Proper indexing on frequently queried columns
- Query result caching (TanStack Query)
- Prepared statements for repeated queries
- WAL mode for concurrent reads
- Periodic VACUUM for maintenance
Frontend
- Code splitting with React.lazy
- Image lazy loading
- Virtual scrolling for large lists
- Debounced search
- Optimistic updates
Backend
- Response compression
- HTTP caching headers
- Connection pooling (future)
- Rate limiting
Game Service
- ZIP file caching (in memory)
- Streaming large files
- MIME type caching
- CDN fallback
Security Considerations
Authentication
- JWT with short expiration (15 min)
- Refresh tokens with long expiration (7 days)
- Automatic token refresh
- Secure token storage
Authorization
- Role-based access control
- Granular permissions
- Middleware enforcement
- Frontend guards
Input Validation
- Zod schemas for requests
- SQL parameterized queries
- XSS prevention
- CSRF protection (future)
Database
- Read-only Flashpoint DB
- User DB with transactions
- Foreign key constraints
- Cascade deletes
Testing Strategy
Unit Tests
- Service layer methods
- Utility functions
- Helper functions
Integration Tests
- API endpoint tests
- Database migration tests
- Auth flow tests
E2E Tests (Future)
- User registration/login
- Game search and play
- Playlist management
Debugging Tips
Backend Issues
- Check logs (
backend/logs/) - Verify environment variables
- Check database schema migrations
- Test API endpoints with Postman
- Enable DEBUG log level
Frontend Issues
- Check browser console
- Inspect TanStack Query DevTools
- Check Zustand DevTools
- Verify API responses in Network tab
- Check React DevTools
Game Service Issues
- Check if ZIP is mounted
- Verify file paths
- Check MIME types
- Test proxy directly (curl)
- Check htdocs fallback chain
Database Issues
- Verify migration version
- Check table schema
- Test queries directly in DB Browser
- Check indexes
- Verify foreign keys
Future Enhancements
Planned Features
- WebSocket Support: Real-time features (live activity, multiplayer)
- GraphQL API: Flexible queries, reduced over-fetching
- Redis Caching: Session management, API response cache
- OAuth2: Third-party authentication
- Content Security Policy: Enhanced security
- Service Worker: Offline support
- Database Sharding: Horizontal scaling
- Docker Compose: Simplified deployment
Architectural Evolution
- Microservices: Further service separation
- Event Bus: Async communication between services
- CQRS: Separate read/write models
- Read Replicas: Scale database reads
- CDN Integration: Global content delivery
Related Documentation
- Overview Documentation: High-level overview and getting started
- API Reference: Detailed API endpoint documentation (if exists)
- Development Guide: Development setup and workflows (if exists)
- Deployment Guide: Production deployment (if exists)
Contributing
When updating architecture:
- Keep diagrams in sync with code
- Update all affected documents
- Include examples
- Test all code snippets
- Get review from team
Questions?
For questions about the architecture:
- Check these docs first
- Review code examples
- Check GitHub issues
- Ask in team chat
- Create documentation issue
Last Updated: 2025-01-18
Maintainers: Dotcom Arcade Development Team