How luisregardiz/caida-game works
1. Project shape
- This is a Next.js App Router application in TypeScript.
- The repo is organized around a client/server split: route files and server helpers on one side, interactive game screens and hooks on the other.
2. Primary user-facing routes
- src/app/page.tsx is the landing entry point.
- src/app/login/page.tsx handles authentication.
- src/app/lobby/page.tsx is the pre-game hub.
- src/app/mesa/[id]/page.tsx is the table/game room view, with TableClient.tsx doing the interactive work.
- The route names and assets strongly suggest a multiplayer card game flow centered on joining a table.
3. Shell and cross-cutting UI
- src/app/layout.tsx, src/components/layout/Navbar.tsx, and AuthProvider.tsx define the shared application shell.
- globals.css is the global styling entry.
- These pieces are the common frame around all routes, likely handling navigation, session awareness, and app-wide layout.
4. Authentication and session boundary
- src/config/supabase/client.ts, server.ts, and middleware.ts show that Supabase is the main backend/auth boundary.
- src/proxy.ts and the middleware layer imply route/session enforcement before users can access protected areas like the lobby or table.
- useSupabaseAuth.ts is the client-side auth hook that likely hydrates user state into the app.
5. Realtime/game-room collaboration boundary
- useTablePresence.ts suggests the app tracks who is currently in a table, which is typically powered by Supabase realtime/presence.
- The lobby-to-table transition likely depends on backend state: discover or join a room in the lobby, then subscribe to presence/state once inside /mesa/[id].
6. Game state management
- src/store/gameStore.ts, gameLogicStore.ts, and userStore.ts separate application state into focused domains.
- userStore likely holds the authenticated user and profile-related state.
- gameStore likely holds table/game session state.
- gameLogicStore likely coordinates rule evaluation, turn progression, or action validation.
7. Rules engine and domain logic
- src/lib/caidaRules.ts and src/hooks/useCaidaEngine.ts indicate a dedicated game rules engine for “caida.”
- This is the core non-UI domain boundary: rules are separated from rendering so the same logic can drive table interactions, validation, and state transitions.
- The caida.types.ts file reinforces that this is a first-class domain model, not just incidental UI logic.
8. Page-level composition
- The route pages are thin composition layers that mount specialized client components such as LobbyClient.tsx and TableClient.tsx.
- This suggests server components are used mainly for routing/bootstrapping, while actual interactivity is pushed into client components and hooks.
- That separation is important for an architecture diagram: page → client screen → hooks/stores → Supabase/rules engine.
9. Data model and type safety
- src/types/database.types.ts implies generated or hand-maintained Supabase database typings.
- game.types.ts and caida.types.ts model the game domain.
- Type definitions are a key contract layer between UI, stores, and backend data access.
10. Static assets and presentation
- public/cards/** contains card artwork organized by suit and additions.
- This is a clear presentation asset boundary: the game UI renders from fixed static imagery rather than generated card graphics.
- In diagram terms, assets are consumed by the table/game UI layer, not by the backend.
11. Technology/runtime signals that matter
- The repo uses Next.js, React, TypeScript, and Supabase.
- eslint.config.mjs, postcss.config.mjs, and next.config.ts indicate standard frontend tooling and build-time configuration.
- Nothing in the tree suggests a separate custom backend service; Supabase appears to be the main external platform.
12. End-to-end flow
- A user enters the app, session is checked through middleware/proxy and Supabase auth.
- After login, the lobby provides table discovery/joining.
- Entering a table loads the dynamic /mesa/[id] screen, which combines presence, game state, and rule evaluation.
- The UI renders card assets while stores and hooks manage live interaction and state synchronization.
Main entry points: TableClient.tsx Table client · useCaidaEngine.ts Engine hook · layout.tsx App shell · useSupabaseAuth.ts Auth hook
Components 24
App shell
Next.js routes and shared UI frame
- Home · Landing entry route
src/app/page.tsx - App shell · Global app layout wrapper
src/app/layout.tsx - Navbar · Shared navigation bar
src/components/layout/Navbar.tsx - Auth provider · Provides session-aware UI context
src/components/layout/AuthProvider.tsx
Game room
Lobby and table interaction surfaces
- Login · Authentication entry page
src/app/login/page.tsx - Lobby · Pre-game hub page
src/app/lobby/page.tsx - Lobby client · Lobby interactions and table join flow
src/app/lobby/LobbyClient.tsx - Table route · Dynamic table room page
src/app/mesa/[id]/page.tsx - Table client · Main in-table gameplay UI
src/app/mesa/[id]/TableClient.tsx
State layer
Client state and hooks
- Auth hook · Hydrates client auth state
src/hooks/useSupabaseAuth.ts - Presence hook · Tracks table occupancy and presence
src/hooks/useTablePresence.ts - Engine hook · Connects UI to caida rules
src/hooks/useCaidaEngine.ts - Game store · Table and session state
src/store/gameStore.ts - Logic store · Turn and action coordination
src/store/gameLogicStore.ts - User store · Authenticated user state
src/store/userStore.ts
Auth boundary
Supabase client/server and route protection
- Supabase auth · Client-side Supabase auth setup
src/config/supabase/client.ts - Server auth · Server-side Supabase session access
src/config/supabase/server.ts - Middleware · Protects routes and sessions
src/config/supabase/middleware.ts - Proxy · Additional request/session enforcement
src/proxy.ts
Domain logic
Rules engine and types
- Caida rules · Core game rules and validation
src/lib/caidaRules.ts - Caida types · Game domain model
src/types/caida.types.ts - Game types · Shared gameplay types
src/types/game.types.ts - DB types · Supabase database typings
src/types/database.types.ts
Connections 23
- Home → App shell: renders in · Home route is wrapped by the shared app shell
- Login → App shell: renders in · Login page uses the shared shell
- Lobby → Lobby client: mounts · Server route composes the interactive lobby client
- Lobby client → Auth hook: reads session · Lobby needs authenticated user state
- Lobby client → Game store: updates · Lobby selection and join flow feed game state
- Table route → Table client: mounts · Dynamic table route composes the gameplay client
- Table client → Presence hook: subscribes · Table view tracks who is present in the room
- Table client → Engine hook: drives · Gameplay UI delegates rule-driven actions to the engine hook
- Engine hook → Caida rules: evaluates · Hook applies caida validation and turn logic
- Engine hook → Logic store: coordinates · Engine updates gameplay coordination state
- Engine hook → Game store: syncs · Engine keeps table state in sync with UI
- Table client → Card assets: renders · Table UI uses static card artwork
- App shell → Navbar: includes · Shared layout includes navigation
- App shell → Auth provider: wraps · App shell provides auth context
- Auth provider → Auth hook: uses · Provider likely hydrates auth from the client hook
- Auth hook → Supabase auth: connects to · Client hook talks to Supabase auth
- Auth hook → User store: hydrates · Authenticated user state is stored locally
- Middleware → Server auth: protects via · Middleware relies on server-side session access
- Proxy → Middleware: routes through · Proxy adds request-level enforcement ahead of app access
- Server auth → DB types: typed by · Server access uses Supabase database typings
- Game store → Game types: typed by · Game state follows shared gameplay types
- Logic store → Caida types: typed by · Logic store uses domain-specific caida model
- Caida rules → Caida types: defines · Rule engine operates on the caida domain types