How urbanzi-solution/gym-app-version2 works
1. This repository is a single Next.js application built around a gym/fitness management domain. It uses the App Router under src/app and combines UI pages, API routes, and shared client components in one codebase.
2. The front end is organized by business area: Dashboard, Members, Trainers, Plans, Report, Settings, plus dedicated login and profile pages. Each page is mostly a composition shell that pulls in reusable components from src/components.
3. Most interactive UI is split into feature components rather than page-local logic. Examples include member/trainer forms, profile panels, list filters, attendance tables, dashboard cards, report graphs, WhatsApp modals, and settings widgets. This suggests the app is a form-heavy admin console with many data-driven views.
4. The backend is exposed through a large set of route handlers under src/app/api. These endpoints cover CRUD for members, trainers, plans, transactions, attendance, balances, blacklists, profile photos, and renewal flows, plus export/download endpoints for lists and reports.
5. Data access is centralized through src/lib/db.js, which is the shared persistence boundary for the API layer. The presence of sequence/format endpoints for member IDs, trainer IDs, and bill numbers indicates the database stores both operational records and configurable numbering rules.
6. Authentication is a first-class subsystem. The repo includes login and logout API routes, src/lib/auth.js, src/lib/jwt.js, and src/middleware.js, implying protected routes and server-side auth checks are enforced across pages and APIs.
7. Member and trainer lifecycle management are separate but parallel domains. Both support create/edit/delete flows, custom ID generation, profile pictures, biodata/profile screens, attendance tracking, and blacklist operations, showing the app manages two primary person entities with similar workflows.
8. Attendance and billing are core transaction flows. There are dedicated endpoints for member/client/trainer attendance, balance adjustments, renewals, bill customization, write-offs, and auto-fill/fetch helpers, which points to a workflow where operational actions are recorded and later surfaced in reports and profiles.
9. Reporting is split into summary and detail layers. Dashboard-specific endpoints provide stats and “expiring soon” data, while the report module has transaction feeds, stat cards, graphs, and downloadable exports. This creates a read-optimized analytics path separate from the transactional CRUD routes.
10. Profile pages are their own subsystem rather than just filtered lists. MemberProfile and TrainerProfile have dedicated client components and API endpoints for details, recent activity, active plans, attendance, and recent transactions, indicating the app supports deep per-person drill-down views.
11. Settings includes several configuration surfaces that affect downstream behavior: ID and bill format customization, notification settings, and WhatsApp settings. These are not just UI preferences; they change how IDs, receipts, and outbound messages are generated system-wide.
12. WhatsApp integration is a major external-service boundary. The src/app/api/whatsapp tree includes credentials, settings, templates, sync/create, send/test, webhook, logs, queue processing, automated triggers, and DB setup. That implies asynchronous messaging, provider synchronization, inbound webhook handling, and operational logging around Meta/WhatsApp APIs.
13. server.js suggests there may be a custom Node server entrypoint in addition to the standard Next.js runtime, but the application architecture still centers on Next.js pages plus serverless-style route handlers.
14. For an architecture diagram, the clearest decomposition is: browser/UI pages and reusable components on one side; Next.js API routes in the middle; shared DB/auth/WhatsApp libraries underneath; and the external database plus WhatsApp provider/webhook services on the far side.
Main entry points: app App shell · db.js Database · whatsapp WhatsApp API · api Plans & reports
Components 23
Next.js app
App Router pages and shared client components for the gym admin console.
- App shell · Root layout, homepage, global styles, and middleware framing the application.
src/app - Dashboard · Overview page composed from dashboard cards and expiring-soon views.
src/app/Dashboard/page.jsx - Members · Member management screen built from filters and list components.
src/app/Members/page.jsx - Trainers · Trainer management screen built from filters and list components.
src/app/Trainers/page.jsx - Plans · Membership plan management screen.
src/app/Plans/page.jsx - Report · Reporting screen for stat cards, graphs, filters, and transactions.
src/app/Report/page.jsx - Settings · Configuration surface for IDs, bills, notifications, and WhatsApp.
src/app/Settings/page.jsx - Member profile · Dedicated member drill-down view with deep activity and plan context.
src/app/MemberProfile/page.jsx - Trainer profile · Dedicated trainer drill-down view with attendance and stats.
src/app/TrainerProfile/page.jsx - Member client · Client-side member profile composition and interaction layer.
src/app/MemberProfile/MemberProfileClient.jsx - Trainer client · Client-side trainer profile composition and interaction layer.
src/app/TrainerProfile/TrainerProfileClient.jsx
API routes
Route handlers for CRUD, reporting, auth, and integrations.
- Dashboard API · Dashboard data, statistics, and expiring-soon feeds.
src/app/api/dashboard_data - Member API · Member lifecycle, profile, attendance, balance, blacklist, and exports.
src/app/api - Trainer API · Trainer lifecycle, profile, attendance, blacklist, and exports.
src/app/api - Plans & reports · Plan CRUD plus transaction and reporting read paths.
src/app/api - Settings API · ID formats, bill formats, sequence resets, and related helpers.
src/app/api - Auth API · Authentication routes for session entry and exit.
src/app/api/login - WhatsApp API · Credentials, templates, send/test, queue, webhook, and automation handling.
src/app/api/whatsapp
Shared core
Persistence, auth, and integration libraries used across the app.
- Database · Shared DB access boundary for all business data and configuration.
src/lib/db.js - Auth libs · JWT, auth, and encryption utilities supporting protected routes.
src/lib/auth.js - WhatsApp lib · Shared WhatsApp integration helpers used by the API layer.
src/lib/whatsapp.js
External systems
Database and third-party provider boundaries.
- Database · Primary persistence store for members, trainers, plans, transactions, settings, and logs.
- WhatsApp · External messaging platform, templates, and webhook source.
Connections 28
- App shell → Dashboard: routes to · App Router pages are served under the shared shell.
- App shell → Members: routes to · Member management is part of the main app surface.
- App shell → Trainers: routes to · Trainer management is part of the main app surface.
- App shell → Plans: routes to · Plan management is part of the main app surface.
- App shell → Report: routes to · Reporting is rendered within the shared shell.
- App shell → Settings: routes to · Settings is rendered within the shared shell.
- App shell → Member profile: routes to · Member profile is a dedicated route.
- App shell → Trainer profile: routes to · Trainer profile is a dedicated route.
- Member profile → Member client: composes · The page delegates interactive profile UI to the client component.
- Trainer profile → Trainer client: composes · The page delegates interactive profile UI to the client component.
- Dashboard → Dashboard API: loads data from · Dashboard views are driven by summary endpoints.
- Members → Member API: loads data from · Member pages consume list and mutation endpoints.
- Trainers → Trainer API: loads data from · Trainer pages consume list and mutation endpoints.
- Plans → Plans & reports: loads data from · Plans page uses plan CRUD routes.
- Report → Plans & reports: loads data from · Reports use transaction and analytics endpoints.
- Settings → Settings API: loads data from · Settings UI reads and writes configuration endpoints.
- App shell → Auth API: uses · Login and logout routes support the protected app shell.
- Auth API → Auth libs: uses · Auth routes rely on shared authentication helpers.
- Member API → Database: persists via · Member workflows read and write through the DB boundary.
- Trainer API → Database: persists via · Trainer workflows read and write through the DB boundary.
- Plans & reports → Database: persists via · Plans, transactions, and reports are database-backed.
- Settings API → Database: persists via · Formats and sequences are stored centrally.
- Dashboard API → Database: reads from · Dashboard metrics are assembled from stored records.
- WhatsApp API → WhatsApp lib: uses · WhatsApp routes share integration helpers.
- WhatsApp API → Database: persists via · Credentials, logs, templates, and queue state are stored in the database.
- Database → Database: connects to · Shared persistence boundary points at the primary database.
- WhatsApp lib → WhatsApp: connects to · Integration helpers communicate with the external provider.
- WhatsApp API → WhatsApp: webhooks/send · Routes handle outbound sends and inbound webhook traffic.