How moahamedlamineremini/p10_f1_front works
Project type and purpose
• This is a single-page web application frontend for an F1 betting system.
• Built with React + TypeScript, styled by Tailwind CSS, and using Apollo Client to communicate with a GraphQL backend.
• Provides user authentication (JWT), pages for races, leagues, betting forms, standings, profiles, etc.
Top-level components
A. Browser / Client Environment
• index.html (HTML shell)
• Vite Dev Server / Build Output (static assets, served via dev or CDN)
B. App Shell & Entry Point
• main.tsx: initializes React root, wraps App in <ApolloProvider> and <BrowserRouter>
• App.tsx: defines routes (React Router) mapping paths to page components
C. Presentation Layer
• Pages (src/pages/*): Login, Signup, Home, BetPage, LeaguesPage, LeagueDetailsPage, Profile, etc.
• Layout Components (Navbar, Layout) – page frame, navigation
• UI Components (Button, Card, Input, Modal, Select, LeagueCard, RaceCard)
D. State & Context
• AuthContext: stores JWT token, user state, login/logout methods
• Context boundaries: wraps the component tree for authentication data
E. Data Layer
• GraphQL folder: queries.ts & mutations.ts
• Apollo Client instance: configured with VITE_GRAPHQL_API_URL, includes auth link (attaches JWT to headers), cache policies
• HTTP network interface: communicates with external GraphQL API
F. Utilities & Types
• src/utils (dateUtils)
• src/types: shared TS types for API results, domain entities
G. Configuration & Tooling
• Vite config (vite.config.ts)
• Tailwind (tailwind.config.js)
• ESLint, TypeScript configs (tsconfig.json, etc.)
• .env for VITE_GRAPHQL_API_URL
Relationships & Data Flows
• User interacts → Browser UI (components/pages)
• UI triggers actions → Calls functions in AuthContext or uses Apollo Client hooks (useQuery, useMutation)
• Apollo Client → Sends HTTP request to GraphQL API (with JWT in Authorization header)
• API responds → Apollo updates cache → React re-renders components with new data
• AuthContext → Reads/writes JWT to localStorage → Provides token to Apollo link
• Utility functions (dateUtils) transform API data before rendering
Key architectural patterns
• Component-based UI (atomic UI components + composite page components)
• React Context for cross-cutting concerns (authentication)
• GraphQL data-driven UI with Apollo Client (cache + declarative queries)
• Route-based code organization (React Router)
• Separation of concerns: Presentation, State, Data, Config