How mohamed-ehab-dev/store works
1. This repository is a single Next.js App Router application that combines the public site, authenticated user areas, admin console, and all backend API routes in one codebase. It is not split into a separate frontend/backend service; the browser-facing UI and server-side request handling live under the same app/ tree.
2. The application is organized by route groups:
- app/(main) for marketing/content pages like homepage, pricing, blog, FAQs, templates, support, policies
- app/(auth) for sign-in and registration
- app/(dashboard) for logged-in end-user account pages
- app/(admin) for staff/admin operations
- app/(user) for user-specific utilities like favorites
- app/banned and app/not-found for special states
3. The backend is a large REST-style API surface under app/api/. These handlers cover:
- content domains: blogs, categories, FAQs, templates
- account domains: users, favorites, preferences, profile/password changes
- commerce/download flows: purchased templates, downloads
- support/ticketing: tickets, messages, admin moderation
- analytics/telemetry: tracking, stats, visitor records
- moderation/admin operations: bulk update/delete, bans, logs, notifications
4. The central domain model layer lives in lib/models/ and lib/validations/. This strongly suggests a database-backed architecture with schema models for entities like User, Template, Order, Ticket, Message, Review, Blog, Category, FAQ, Notification, Visitor, and log records. Request handlers appear to validate input first, then persist/query through these models.
5. Authentication and authorization are a major boundary. lib/auth.ts, middleware/auth.ts, proxy.ts, and the route-group layouts indicate role-based access control for public, authenticated, and admin-only areas. There are explicit flows for login/logout, registration, ban/unban, password changes, account deletion, and online/offline presence.
6. The main product domain appears to be a template marketplace/content platform. Public pages and APIs revolve around browsing templates, featured templates, search, downloads, reviews, and user favorites. The same domain is mirrored in the admin console for creating/editing templates, categories, blogs, and FAQs.
7. The support system is its own subsystem, with both user and admin views plus ticket-message endpoints. The presence of Ticket, TicketMessage, and client components for ticket details implies a conversational support workflow, likely with near-real-time updates. The hooks/useSocket.ts and store/useSocketStore.ts files reinforce a socket-based live communication layer.
8. Analytics and operational visibility are first-class. There are API routes and admin pages for analytics, visitor tracking, download logs, error logs, and support stats. context/AnalyticsContext.tsx, hooks/useAnalyticsStats.ts, and store/useAnalyticsStore.ts suggest telemetry is collected on the client and aggregated server-side for dashboards.
9. Media handling is integrated through Cloudinary. lib/cloudinary.ts, app/api/cloudinary/sign/route.ts, and hooks/useCloudinaryUpload.ts indicate signed uploads rather than direct file storage in the app. This is important for architecture because asset upload is delegated to an external service, while the app controls signing and metadata.
10. The UI is heavily componentized by domain and shared interaction patterns. components/Admin, components/Dashboard, components/Support, components/home, components/singleTemplate, and components/shared map closely to product areas, while components/ui contains reusable primitives. Most complex pages likely stitch together server-rendered route pages and client-side “Client” components for tables, forms, dialogs, and live interactions.
11. State management is split across React context and client stores. context/UserContext.tsx and context/AnalyticsContext.tsx provide app-wide context, while store/useUserStore.ts, store/useAnalyticsStore.ts, and store/useSocketStore.ts indicate local/global client state for auth, metrics, and realtime state. This reduces prop drilling across the large dashboard/admin surface.
12. There is a distinct SEO/content delivery layer. app/robots.ts, app/sitemap.ts, components/SEO/StructuredData.tsx, and markdown utilities support crawlable marketing pages and content-heavy pages like blog and templates. Static assets, fonts, videos, screenshots, and PWA files in public/ suggest the public site is optimized for rich media and search visibility.
13. Operationally, the repo includes cache invalidation and refresh tooling. actions/revalidateTag.ts and the /admin/refresh page imply server-side cache/tag invalidation to keep content lists and detail pages fresh after edits. This matters because many admin actions likely need to propagate immediately to public listings.
14. Supporting infrastructure is bundled into the app: image utilities, markdown helpers, notification utilities, payment helpers, and a broad set of validations. The overall architecture is a modular monolith with clear domain boundaries, server-rendered pages for most screens, API routes for data mutation/query, and a few external dependencies for media and live support.
Main entry points: models Domain models · components Domain UI · auth.ts Auth boundary · user Account API
Components 22
App routes
Next.js route groups and special pages
- Public site · Marketing, content, and product browsing pages
app/(main) - Auth pages · Sign-in and registration flows
app/(auth) - Dashboard · Authenticated user account area
app/(dashboard) - Admin console · Staff operations and management screens
app/(admin) - User tools · User-specific utilities like favorites
app/(user) - Special states · Banned and not-found handling
app/banned
API surface
REST handlers organized by domain
- Account API · Login, registration, profile, presence, favorites, preferences
app/api/user - Content API · Blogs, categories, FAQs, templates, search, featured content
app/api - Template API · Template detail, download, search, stats, and listing endpoints
app/api/template - Support API · Tickets, messages, and support workflows
app/api/support - Admin API · Moderation, bulk ops, analytics, logs, users, visitors
app/api/admin - Telemetry API · Client tracking and aggregated stats
app/api/analytics - Media signing · Signed upload flow for external media storage
app/api/cloudinary/sign
Core domain
Models, validation, auth, and infrastructure
- Auth boundary · Session, role checks, proxy, and route protection
lib/auth.ts - Domain models · Persistent entities for users, templates, tickets, logs, and content
lib/models - Validation layer · Input schemas for API and form handling
lib/validations - Database · Shared database connection and query access
lib/database.ts - Cloudinary · Image and asset storage outside the app
lib/cloudinary.ts - Payments · Purchase and download-related business support
lib/payments.ts
Client layer
Shared UI, contexts, stores, and domain components
- Domain UI · Admin, dashboard, support, home, templates, and shared UI
components - Client state · User, analytics, and socket state across the app
context - Client hooks · Socket, analytics, and upload integrations
hooks
Connections 28
- Public site → Domain UI: renders · Public pages compose shared and domain UI
- Auth pages → Auth boundary: guards · Auth pages rely on shared identity and session logic
- Auth pages → Domain UI: uses forms · Sign-in and registration screens use form components
- Dashboard → Auth boundary: protects · Dashboard routes require authenticated access
- Dashboard → Domain UI: renders · Dashboard screens use dashboard-specific components
- Admin console → Auth boundary: restricts · Admin routes are role-protected
- Admin console → Domain UI: renders · Admin console uses admin client components and tables
- User tools → Auth boundary: protects · User utility routes require login
- User tools → Domain UI: renders · Favorites and similar utilities use shared UI
- Account API → Auth boundary: authenticates · User endpoints handle login, logout, and account actions
- Account API → Validation layer: validates · Account mutations are schema-validated
- Account API → Domain models: persists · User state, favorites, and preferences use domain models
- Content API → Domain models: queries · Content endpoints read blogs, categories, FAQs, and templates
- Content API → Validation layer: validates · Content mutations validate payloads
- Template API → Domain models: reads/writes · Template browsing, stats, and download flows use models
- Template API → Payments: supports · Purchase/download flows connect to commerce helpers
- Support API → Domain models: threads · Tickets and messages are stored as domain records
- Support API → Client hooks: realtime · Support conversations pair with socket-based live updates
- Admin API → Domain models: administers · Moderation and bulk operations act on persisted entities
- Admin API → Auth boundary: restricts · Admin APIs are authorization-bound
- Telemetry API → Client state: collects · Telemetry is captured from client state and context
- Telemetry API → Domain models: aggregates · Stats and visitor records are stored server-side
- Media signing → Cloudinary: signs · Uploads are delegated to Cloudinary via signed requests
- Domain UI → Client state: consumes · UI components depend on shared app state
- Client hooks → Cloudinary: uploads · Upload hooks integrate with Cloudinary signing
- Domain models → Database: uses · Models are backed by the shared database connection
- Validation layer → Account API: fronts · Validation is the first boundary before persistence and actions
- Validation layer → Admin API: fronts · Admin mutations are validated before model access