How iamanshkumar/book-my-event works
1. Repository shape
- This is a single Next.js App Router monolith: one frontend, one set of Route Handlers API endpoints, and one shared server-side backend layer.
- The main persistence layer is MySQL via Prisma ORM, with schema and migration history under prisma/.
2. Top-level runtime boundaries
- src/app/ contains all route segments for pages and APIs.
- src/backend/ contains the domain/service layer and Prisma/auth utilities.
- src/components/ holds reusable UI and role-specific layout shells.
- src/proxy.ts acts as the authentication/authorization boundary before requests reach protected areas.
3. Public vs authenticated areas
- The app is divided into distinct UX zones:
- Public event discovery and event detail pages.
- Auth flows under /(auth) for login, register, forgot/reset password, OTP verification.
- Attendee dashboard under /dashboard.
- Organizer workspace under /organizer.
- Admin console under /admin.
- Each area has its own nested layout.tsx, which is important for diagramming separate shells and access scopes.
4. API-first internal architecture
- Most behavior is implemented through Next.js Route Handlers in src/app/api/....
- The page layer and the API layer are decoupled: UI pages call route handlers, and route handlers delegate to backend services.
- Key API namespaces are:
- api/auth
- api/users
- api/events
- api/bookings
- api/payments
- api/organizer
- api/admin
5. Backend service layer
- src/backend/services/ is the main business-logic boundary.
- The services map cleanly to domains:
- AuthService
- BookingService
- EventService
- DashboardService
- PaymentService
- This suggests a layered structure: route handler → service → Prisma/database, rather than direct DB access from UI code.
6. Authentication and role enforcement
- Authentication is custom token-based, not a separate external identity provider.
- The proxy middleware verifies user context and forwards it through headers such as x-user-id and x-user-role.
- Role-based access control is central to the architecture, with three main roles:
- Customer/Attendee
- Organizer
- Admin
- Protected routes are separated both by URL namespace and by backend authorization checks.
7. Core data model
- Prisma migrations show the schema has evolved around:
- users and roles
- events
- ticket tiers
- bookings
- password reset tokens
- event trailer URLs
- The schema is designed for event listings with rich metadata, including categories, country/pincode fields, and multiple trailer/media links.
8. Event discovery and organizer event management
- Public endpoints support listing, search, and event detail retrieval.
- Organizer endpoints support creating and editing owned events, plus media uploads.
- Event media is not just a single image: the readme indicates banner/thumbnail upload and multiple trailer sources, so event content is a structured asset bundle rather than a simple record.
9. Booking and payment flow
- Booking is a transactional subsystem:
- seats are reserved through booking creation
- bookings can be cancelled, which releases seat inventory
- payment webhooks update payment state asynchronously
- api/payments/webhooks is the key external ingress point for payment status changes, so the booking/payment boundary is event-driven at least at webhook time.
10. Account lifecycle
- Auth endpoints cover registration, login, logout, current-user lookup, password change, forgot-password, and reset-password.
- The presence of password reset token migrations indicates token persistence in the database rather than purely stateless reset links.
- Attendee profile editing is a separate user profile path from credential changes, which is important for diagramming account management flows.
11. Organizer and admin workspaces
- Organizer APIs and pages focus on owned events, bookings, and revenue/fill-rate style dashboards.
- Admin APIs and pages operate across the whole platform: system stats, user management, role updates, and force deletion of events.
- This creates a clear split between tenant-like ownership scopes for organizers and global authority for admins.
12. Shared UI and client shells
- src/components/AttendeeLayoutClient.tsx, OrganizerLayoutClient.tsx, and AdminLayoutClient.tsx indicate distinct client-side layout wrappers per role.
- Reusable UI primitives live under src/components/ui/, with Tailwind-based styling and utility helpers in src/lib/utils.ts.
- ThemeToggle is a shared cross-cutting UI concern, not a domain subsystem.
13. Local infrastructure and deployment assumptions
- docker-compose.yml and .env.example show the repo expects a local MySQL environment for development.
- Prisma migrations are part of the deployment story, so schema changes are managed through migration files rather than ad hoc SQL.
- The app is built and served as a Next.js production bundle, not as separated frontend/backend services.
14. How to draw the architecture
- A good diagram would show:
- Browser/users entering Next.js pages
- Proxy/middleware enforcing auth and role context
- Route Handlers as the API layer
- Backend services as the business logic tier
- Prisma/MySQL as the persistence tier
- Payment webhook as an external callback into the booking/payment flow
- Separate UI/workspace boundaries for customer, organizer, and admin paths
Main entry points: prisma.ts Prisma client · proxy.ts Proxy · dashboard Attendee area · admin Admin API
Components 21
Frontend shells
Next.js pages and role-specific UI layouts
- Home · Landing and discovery entry point
src/app/page.tsx - Event pages · Public event listing and detail screens
src/app/events - Auth flows · Login, register, OTP, and password recovery screens
src/app/(auth) - Attendee area · Dashboard, profile, tickets, and credential management
src/app/dashboard - Organizer area · Owned events, bookings, and organizer dashboard
src/app/organizer - Admin area · Platform-wide admin dashboard, events, and users
src/app/admin
Route handlers
HTTP entrypoints grouped by domain
- Auth API · Login, register, logout, current user, and password lifecycle
src/app/api/auth - Event API · Public discovery plus organizer event creation and editing
src/app/api/events - Booking API · Booking creation, lookup, and cancellation
src/app/api/bookings - Payment webhooks · External payment status callbacks
src/app/api/payments/webhooks - Organizer API · Organizer dashboards, bookings, and owned events
src/app/api/organizer - Admin API · Global stats, user management, and event moderation
src/app/api/admin - User API · Profile editing and user-centric operations
src/app/api/users
Backend services
Shared business logic and persistence helpers
- AuthService · Token auth, session context, and account lifecycle
src/backend/services/AuthService.ts - EventService · Event discovery, ownership, media, and ticket tiers
src/backend/services/EventService.ts - BookingService · Seat reservation, booking cancellation, and inventory release
src/backend/services/BookingService.ts - PaymentService · Payment state updates driven by webhooks
src/backend/services/PaymentService.ts - DashboardService · Role-aware aggregates for attendee, organizer, and admin views
src/backend/services/DashboardService.ts
Data and auth
Proxy, Prisma schema, and MySQL persistence
- Proxy · Pre-route auth and role context enforcement
src/proxy.ts - Prisma client · Shared database access layer
src/backend/lib/prisma.ts - Schema · Models and migration history for users, events, bookings, and tokens
prisma/schema.prisma
Connections 26
- Proxy → Auth flows: protects · Enforces role-aware access before protected UI loads
- Proxy → Attendee area: protects · Gates customer dashboard routes
- Proxy → Organizer area: protects · Gates organizer routes
- Proxy → Admin area: protects · Gates admin routes
- Home → Event pages: navigates · Discovery leads into event detail flows
- Auth flows → Auth API: calls · Auth UI uses route handlers for account operations
- Attendee area → Booking API: calls · Ticket and booking actions are API-backed
- Attendee area → User API: calls · Profile and account edits use user endpoints
- Organizer area → Organizer API: calls · Organizer UI drives dashboard and owned-event actions
- Admin area → Admin API: calls · Admin UI drives system management actions
- Home → Event API: calls · Public event discovery is API-backed
- Event pages → Event API: calls · Event detail and search data comes from event handlers
- Auth API → AuthService: delegates · Route handlers forward auth logic to the service layer
- Event API → EventService: delegates · Event routes delegate business logic to services
- Booking API → BookingService: delegates · Booking routes rely on transactional booking logic
- Payment webhooks → PaymentService: updates · Webhook callbacks reconcile payment state
- Organizer API → DashboardService: reads · Organizer metrics and aggregates are computed centrally
- Admin API → DashboardService: reads · Admin system stats come from shared aggregates
- Admin API → EventService: delegates · Admin event moderation uses event domain logic
- User API → AuthService: delegates · Profile and credential flows reuse auth/account logic
- AuthService → Prisma client: uses · Service layer persists and reads through Prisma
- EventService → Prisma client: uses · Event domain data flows through Prisma
- BookingService → Prisma client: uses · Booking transactions hit the database through Prisma
- PaymentService → Prisma client: uses · Payment updates persist through Prisma
- DashboardService → Prisma client: uses · Aggregations query shared persistence
- Prisma client → Schema: backed by · Client operates over the versioned Prisma schema