How mohammedhamza0631/geogenius works
Project Type and Purpose
• GeoGenius is a full-stack interactive web application built using Next.js. Its main purpose is to provide a quiz that tests users’ knowledge of world capitals.
• The project uses React for the frontend, Tailwind CSS for styling, and Next.js API routes for handling backend logic.
• A PostgreSQL database managed through Prisma (with migrations) stores quiz data, user details, and scores.
File Structure
• Top-Level Organization:
• The "app" directory holds the main Next.js application files including pages (e.g., app/page.jsx, app/quiz/page.jsx, app/leaderboard/page.jsx), layout, styling (globals.css), and API routes (located in app/api/*).
• The "components" folder holds reusable React UI components like header, footer, quiz components (quiz-question, quiz-results, quiz-setup-form), and several UI components (in components/ui).
• The "lib" directory contains utility files that support tasks such as quiz data management (quiz-data.js), prisma connections (prisma.js), and utility functions for pin operations and cleanup.
• The "prisma" directory contains the schema and migration files for managing the PostgreSQL database.
• Configuration Files:
• Files like next.config.mjs, postcss.config.mjs, tailwind.config.js, and .eslintrc.json indicate project-specific configurations.
• The scripts folder holds additional helper scripts for tasks like cleaning up duplicates or updating high scores.
Key Components
a. Client/Frontend Layer:
• Pages and Views: Represent distinct routes such as Landing, Quiz, Start, and Leaderboard. These are defined in the "app" directory.
• UI Components: Include smaller building blocks from the "components" folder (header, footer, globe, quiz questions, results, etc.) that are rendered on the pages.
• State Management: The usage of React Context API from files like lib/quiz-context.js provides global state handling across the application.
b. Backend/API Layer:
• Next.js API Routes: Under the "app/api" directory you find various endpoints such as check-pin, check-username, set-pin, and user-scores. These endpoints handle server-side logic and data validation.
• Utility and Business Logic: The "lib" directory contains essential logic for data handling (e.g., lib/utils.js, lib/pin-utils.js) that is used by API routes.
c. Database Layer:
• PostgreSQL Database: Managed via Prisma ORM, with schema definitions in prisma/schema.prisma and migrations available in the migrations folder.
• Database Tools: Utilize the prisma.js file to connect, execute queries, and manage transactions.
Relationships and Interactions
• The Frontend (client side) sends HTTP requests to API endpoints for operations such as validating user inputs (e.g., checking username and pin), recording scores, and fetching leaderboard data.
• API endpoints process requests by using business logic from the utility libraries and interact with the PostgreSQL database via Prisma.
• The user data, quiz questions, and scores stored in the database feed back into the frontend for real-time updates (e.g., dynamic leaderboard).
Highlighting Architectural Patterns and Design Principles
• Separation of Concerns: The clear separation between frontend pages, reusable components, API routes, and business logic modularizes the application.
• Single Page Application (SPA) with Next.js: Uses client-side routing along with server-side API endpoints.
• Modular UI Design: Reusable UI components (including UI primitives from components/ui) promote a consistent and maintainable interface.
• Data Flow: Directional data flow from the user interaction layer (frontend) to the server (API routes) and then to the database ensures clarity in request handling.