How chimmykk/light-games works
Project type and purpose
• This is a full-stack, server-rendered Next.js application (“Light Game”) that lets end users generate, play, and share lightweight AI-powered games.
• It combines a React/Next.js frontend (app directory) with serverless API routes (app/api/*), a MongoDB database (Mongoose models), authentication (NextAuth.js), and external AI services for game generation.
File structure
• Top-level “app/” directory:
• page.tsx, layout.tsx, CSS, SessionProvider.tsx → React pages, global layout, session management
• app/api/*/route.ts → Next.js Serverless API endpoints (auth, game CRUD, generation, prompt-nicer, retry, etc.)
• app/explore, my-creations, p, play → feature pages
• “components/” directory:
• feature components (ExploreButton, project-generation)
• “ui/” subfolder: atomic, reusable UI primitives (buttons, dialogs, inputs, etc.)
• “lib/” for utilities and Zustand store
• “hooks/” for custom React hooks (mobile detection, toast)
• “models/” for Mongoose schemas and dbConnect
• Config files for Tailwind, Next.js, pnpm, TypeScript
README insights
• Confirms tech stack: Next.js, pnpm, MongoDB/Mongoose, Zustand, NextAuth.js, Tailwind, next-themes, lucide-react.
• Describes API endpoints and their responsibilities (game HTML generation, save, fetch, improve, retry).
a. Main components
• Client (Browser / Mobile)
– Next.js React UI (pages + components)
– Zustand store (lib/store.ts)
– ThemeProvider (next-themes)
– SessionProvider (NextAuth)
• Next.js Server (Serverless Functions)
– API layer (app/api/*)
– Server actions (app/actions.ts for saving to DB)
– Authentication (NextAuth.js handlers under api/auth)
• Business Logic
– Prompt enhancement (makeit-nicer, promptnicer)
• Database
– MongoDB Atlas (Mongoose models: GameData, Pets; dbConnect)
• External Services
– Optional: OAuth providers via NextAuth
• Static Assets & CDN
– public/ folder (images, placeholders)
b. Relationships and data flows
1. User requests page → Next.js SSR/SSG → HTML/CSS/JS returns to client
2. Client actions (e.g., “Generate Game”) → fetch(“/api/generate-game”)
3. API route handler calls AI service → receives game code/HTML
4. Client may call “/api/save-game” → server action writes to MongoDB
5. On “Play” pages: client fetches game data via “/api/games/[gameId]” → renders
6. Authentication flows: client uses SessionProvider → NextAuth API → issues session cookie/JWT → secure endpoints
c. Architectural patterns and design principles
• Monolithic serverless architecture (Next.js app + API in one codebase)
• Atomic component design (UI primitives under components/ui)
• Server Actions (Next.js 13 App Router) for direct server-side DB writes
• React hooks and global state (Zustand) to decouple UI from data-fetching logic
• Separation of concerns: UI / state / API / data models / external integrations
d. Key technologies to annotate
• Next.js 13 App Router
• React (TSX components)
• NextAuth.js (authentication)
• Tailwind CSS (styling)
• Zustand (state management)
• Mongoose + MongoDB
Capturing all critical elements
• Don’t forget the SessionProvider / NextAuth flow.
• Both “core” game-generation endpoints and “utility” endpoints (promptnicer, retry).
• Mongoose models and dbConnect as part of the data access layer.
• Component library (components/ui) as part of the frontend but note reusability.