How anshumansharma69-bit/fightclub works
1. High-level split
- The repo is a two-tier application: a Next.js frontend in client/ and an Express/MongoDB backend in server/.
- The frontend is mostly a presentation and interaction layer; the backend owns all domain logic for fighters, challenges, zones, auth, and rankings.
2. Frontend surface and routing
- The client uses the Next.js App Router with route-based pages for the main experiences: map, login/register, onboarding, leaderboard, fighter directory, and public fighter profile pages.
- Public browsing is intentionally supported: map, fighter profiles, leaderboard, and nearby fighter discovery can be viewed without login, while mutation flows require authentication.
3. Frontend state and API boundary
- client/context/AuthContext.jsx centralizes authentication state on the frontend.
- client/lib/api.js is the main boundary to the backend API; UI components call into it rather than talking to the server directly.
- Reusable UI pieces like MapView, FighterCard, ChallengeModal, NotificationsPanel, and ShareInviteModal compose the main user flows.
4. Backend structure
- The server is organized by domain: auth, fighter, challenge, zone, plus admin.
- Each domain has a route layer, controller layer, and in most cases a Mongoose model, which makes the backend the source of truth for all state transitions.
5. Authentication and user onboarding
- Authentication supports email/password plus Google OAuth via Passport.js.
- JWTs protect authenticated routes, while middleware enforces access control.
- Google sign-in can create a placeholder fighter profile that is redirected into an onboarding step before full participation in the app.
6. Core fighter domain
- Fighters are the public identity in the system, separate from raw auth users.
- The fighter API supports public profile reads, nearby fighter discovery, and authenticated updates for location, availability, and stats.
- Public profile pages expose history and ranking data without requiring login.
7. Location and map subsystem
- The app’s map experience is built around Leaflet / React-Leaflet on the client and MongoDB geospatial queries on the server.
- Fighters are stored as geographic points, while city territories are stored as GeoJSON polygons.
- This enables two important data flows: “fighters near me” queries and “which zone does this fight/location belong to?” checks.
8. Challenge and fight workflow
- Challenges are the main transactional flow: send, accept/decline, upload proof, then confirm or dispute the result.
- The backend persists challenge state in MongoDB and drives all authoritative updates to fighters, ELO, and badge ownership.
- The client uses modal-driven UI and live notifications to manage this multi-step flow.
9. Real-time communication
- The repo uses Socket.io for instant challenge and status notifications.
- The architecture is targeted rather than broadcast-oriented: events are delivered to specific fighters, which keeps the app responsive without polling.
10. Rankings and territory system
- Fighter strength is modeled with an ELO rating implemented in server/utils/elo.js.
- Territory ownership is driven by city zones and badge logic in server/utils/badge.js; zone claims can change based on fight outcomes and location.
- The leaderboard and zone pages are therefore derived views over combat outcomes and badge ownership, not independent data stores.
11. Media and proof handling
- Fight proof images are uploaded through the backend and stored in Cloudinary.
- The design keeps proof URLs in the challenge record so both fighters can review evidence during disputes or confirmation.
12. Data storage and schema boundaries
- MongoDB models are split by domain: User, Fighter, Challenge, and Zone.
- User handles auth identity, while Fighter carries public gameplay state; this separation helps the app support social login, onboarding, and game-state updates cleanly.
13. Admin and operational paths
- There is a separate admin route and middleware path, indicating privileged operations are isolated from normal fighter actions.
- Zone seeding is also treated as an operational/backend concern rather than a frontend feature.
14. External services and deployment shape
- The architecture relies on MongoDB Atlas for persistence, Cloudinary for media, Google OAuth for identity federation, and OpenStreetMap/Leaflet for maps.
- Deployment is split by layer: frontend on Vercel, backend on Render, which matches the clean API boundary between client/ and server/.
Main entry points: app App Router · index.js API Server · models Mongo Models · fighter.controller.js Fighter Logic
Components 21
Client
Next.js frontend for public browsing and authenticated gameplay flows.
- App Router · Route-based entry points for map, auth, onboarding, leaderboard, fighters, and admin pages.
client/app - Auth State · Central frontend authentication/session state.
client/context/AuthContext.jsx - API Client · Frontend gateway for calling backend endpoints.
client/lib/api.js - Map View · Leaflet-based map experience and nearby fighter discovery.
client/components/MapView.jsx - Fighter Card · Reusable fighter summary and profile presentation.
client/components/FighterCard.jsx - Challenge Modal · Modal-driven challenge send, proof, and resolution flow.
client/components/ChallengeModal.jsx - Notifications · Live challenge and status updates for targeted fighters.
client/components/NotificationsPanel.jsx - Invite Modal · Share and invitation entry point for social gameplay.
client/components/ShareInviteModal.jsx
Server
Express API and MongoDB-backed domain logic.
- API Server · Backend entrypoint wiring routes, middleware, and startup.
server/index.js - Auth Routes · Login, register, JWT, and OAuth endpoints.
server/routes/auth.routes.js - Fighter Routes · Public fighter reads and authenticated fighter updates.
server/routes/fighter.routes.js - Challenge Routes · Challenge lifecycle endpoints for battle workflow.
server/routes/challenge.routes.js - Zone Routes · City territory and zone lookup endpoints.
server/routes/zone.routes.js - Admin Routes · Privileged operational endpoints.
server/routes/admin.routes.js - Auth Logic · Credential auth, Google sign-in, onboarding handoff.
server/controllers/auth.controller.js - Fighter Logic · Public profile, nearby discovery, and fighter updates.
server/controllers/fighter.controller.js - Challenge Logic · Challenge state transitions, proof handling, and result confirmation.
server/controllers/challenge.controller.js - Zone Logic · Zone ownership, lookup, and territory operations.
server/controllers/zone.controller.js - Mongo Models · User, Fighter, Challenge, and Zone persistence models.
server/models - Auth Middleware · JWT protection and admin access control.
server/middleware/auth.middleware.js - Domain Utils · ELO, badges, geo queries, geocoding, and Cloudinary helpers.
server/utils
Connections 26
- App Router → Auth State: uses session · Pages and route flows read auth state.
- App Router → API Client: calls API · Route pages fetch and mutate through the shared API client.
- App Router → Map View: renders map · Map page composes the map subsystem.
- App Router → Challenge Modal: drives flow · Challenge flows are initiated from route pages.
- App Router → Notifications: shows alerts · Authenticated UX surfaces live updates.
- App Router → Fighter Card: shows fighters · Directory and profile pages reuse fighter cards.
- App Router → Invite Modal: invites · Invite and sharing interactions are exposed in the app.
- API Client → API Server: HTTP requests · Frontend communicates with the backend API boundary.
- API Server → Auth Routes: mounts · API server registers auth endpoints.
- API Server → Fighter Routes: mounts · API server registers fighter endpoints.
- API Server → Challenge Routes: mounts · API server registers challenge endpoints.
- API Server → Zone Routes: mounts · API server registers zone endpoints.
- API Server → Admin Routes: mounts · API server registers admin endpoints.
- Auth Routes → Auth Logic: delegates · Route handlers forward auth work to controller logic.
- Fighter Routes → Fighter Logic: delegates · Route handlers forward fighter work to controller logic.
- Challenge Routes → Challenge Logic: delegates · Route handlers forward challenge work to controller logic.
- Zone Routes → Zone Logic: delegates · Route handlers forward zone work to controller logic.
- Admin Routes → Auth Middleware: protects · Admin operations are guarded by middleware.
- Auth Logic → Mongo Models: reads/writes · Auth logic persists user identities and onboarding state.
- Fighter Logic → Mongo Models: reads/writes · Fighter logic manages public gameplay state.
- Challenge Logic → Mongo Models: reads/writes · Challenge logic persists battle state.
- Zone Logic → Mongo Models: reads/writes · Zone logic persists territory data.
- Challenge Logic → Domain Utils: uses · Challenge outcomes depend on ELO, badges, geolocation, and media services.
- Fighter Logic → Domain Utils: uses · Fighter discovery and location updates use geo utilities.
- Zone Logic → Domain Utils: uses · Zone logic uses geospatial and badge helpers.
- API Server → Auth Middleware: applies · API server applies authentication and access control middleware.