How mrmoneyinthebank/zetamax works
Project Type and Purpose
• Project Type: Full-stack interactive game application.
• Purpose: ZetaMax is an interactive mathematics game designed to help users practice and improve their math skills via a real-time, engaging, and timer-driven gaming experience.
• Key Technologies: Next.js (React for frontend), Convex (for real-time backend and database management), Clerk (for authentication), TailwindCSS (with shadcn/ui for styling), and TypeScript.
Main Components
a. Frontend (Next.js Application)
• Components: Separate by directories such as /app, /components (which further break down into ui, custom, clerk, hover components), /contexts, /hooks, etc.
• Pages/Layouts: Represented by the Next.js routing structure in /src/app (pages, sign-in, sign-up, globals, etc.).
b. Backend / Real-time Database Layer (Convex)
• Files found in /convex (database schema, mutation/query functions, and generated types/API).
• API functions like addUserScore.ts, createUser.ts, etc., that map out backend logic.
c. Authentication Service (Clerk)
• Integration present in multiple parts of the project (evidenced by /src/app/api/webhooks, /components/clerk-components, and /src/webhooks/clerk).
• User management and authentication logic, including webhook handling.
d. Utility and State Management:
• Custom React hooks (in /src/hooks) for game state, timers, and local scores.
• Context providers (in /src/contexts) for managing state like localScoresContext and userContext.
• Utility functions under /src/lib and configuration under /src/utils.
e. Webhooks:
• Handling for external requests (e.g., sending events from Clerk) which is found under /src/webhooks.
Relationships and Interactions
• The Frontend (Next.js app) interacts with the backend components of Convex for real-time data (score tracking, persistent storage) using APIs defined in the convex folder.
• Authentication through Clerk is integrated into both the frontend components (see sign-in/sign-up pages and clerk-components) and backend (via webhook handlers).
• Custom hooks and contexts manage and propagate the state, coordinating between user interactions, game logic, and real-time database updates.
• Webhooks serve as integration points to interact with external services (e.g., Clerk events) and update both frontend state and backend records.
Architectural Patterns / Design Principles
• Full-stack separation: Clear demarcation between frontend (Next.js / React UI) and backend services (Convex functions).
• Modular design: Components are grouped by functionality (UI, game-specific logic, authentication).
• Real-time synchronization: Convex ensures the game scores and user data are updated in real time.
• Use of custom hooks and contexts for state management abstracts business logic away from UI components.
• External service integration: Clerk handles authentication while webhooks ensure the proper handling of external events.
Putting It All Together
• A “Client” block representing browsers running the Next.js React app.
• Inside the Client block, subdivide areas for UI Components, State Management (Hooks & Contexts), and API Interface.
• A separate “Backend” block showing the Convex layer, with links to specific functions (user scoring, data fetching, data model).
• From Client UI actions to Backend API requests.
• From Clerk’s authentication events to both backend processing (webhooks) and UI updates.
• From Convex updates back to Client state updates via the custom hooks.
• Every component is annotated with details (like the libraries used and their purposes) to allow for easy identification by other engineers.