How duniagelap134/24accurate-frontend works
1. Top-level shape
This repo is a single Next.js 14 application that contains both the browser UI and the server-side API. The frontend uses the Pages Router under src/pages, while the backend is mounted into a catch-all API route at src/pages/api/[[...path]].js, which delegates to an Express app in src/server/app.js.
2. Primary request flow
User requests hit Next.js pages first, render UI components from src/components, and then call the API through src/lib/api.js. That client automatically attaches the JWT bearer token and handles 401 responses. API requests then flow into the Express backend, which reads/writes MongoDB and calls external providers for sending messages.
3. Backend boundary
The server boundary is intentionally centralized: src/server/app.js contains the REST API, and src/server/providers.js encapsulates all third-party delivery integrations. This keeps transport logic, business logic, and provider-specific sending logic separated even though they run inside the same Next.js deployment.
4. Data layer
The persistence layer is MongoDB Atlas, and the README notes that the connection is cached across requests. The app relies on live data for contacts, groups, campaigns, templates, reports, logs, users, settings, and integrations. There is also first-connection seeding for default admin/user accounts plus starter data.
5. Authentication and session model
Authentication is handled in src/context/AuthContext.js and uses JWT stored in localStorage, with password hashing via bcrypt and a 7-day token lifetime. The client-side auth context drives route access and user state, while the backend still enforces authorization on each request.
6. Authorization model
There are two roles: superadmin and user. Role checks are enforced in the database for admin-sensitive operations, not just from token claims, which prevents privilege escalation from stale tokens. Super-admin-only capabilities include Integrasi, Pengguna, and destructive data management.
7. Core functional domains
The app is organized around CRM/broadcast domains: Dashboard, Kontak, Grup, Import, Blacklist, Kampanye, Template, Laporan, Log Aktivitas, Akun, Pengaturan, Integrasi, and Pengguna. Each page under src/pages/* maps closely to a domain in the REST API, which makes the UI and backend align by business capability rather than technical layer.
8. Messaging and provider architecture
The sending subsystem supports three channels: SMS, WhatsApp, and Email. Providers are abstracted behind the provider layer and can be swapped without redeploying via the Integrasi page. Supported backends include SMS Gateway, Twilio, EasySendSMS, Alibaba Cloud SMS, Twilio/Meta WhatsApp, and ProtonMail SMTP. Test-connection endpoints validate credentials before use.
9. Campaign execution flow
Campaigns use contacts, groups, blacklist rules, and templates to construct personalized blasts. Personalization tokens like {nama}, {nomor}, {email}, and {grup} are resolved before dispatch. The system tracks outcomes such as success, failure, and skipped recipients, and also supports test-send to a single recipient.
10. UI composition
The frontend is built from reusable UI blocks in src/components such as tables, charts, cards, sidebars, and empty states. It uses Tailwind CSS, dark-mode default theming with a toggle, and visual stats components like line and donut charts for the dashboard. Toast notifications and test IDs are also present to support interaction feedback and automated testing.
11. Operational deployment
Deployment is self-hosted on a VPS with Nginx reverse proxying to a Node process managed by PM2. The app is built and served from a single runtime, with HTTPS terminated at Nginx and MongoDB Atlas access restricted to the VPS IP. This deployment model matters because both frontend and API share the same Node process and release cycle.
12. Key boundaries to show in an architecture diagram
The most important diagram boundaries are: browser UI, Next.js routing layer, embedded Express API, MongoDB Atlas, and external delivery providers. The app’s value comes from the interaction between these boundaries: authenticated UI actions trigger API requests, API logic queries MongoDB, provider adapters send messages, and results are persisted back for reporting and logs.
Main entry points: kampanye Campaign Flow · pages Pages Router · app.js Express App · AuthContext.js Auth Context
Components 19
Frontend
Next.js pages, shared UI, and browser-side state
- Pages Router · Browser-facing routes and page shells
src/pages - UI Blocks · Reusable cards, tables, charts, layout, and controls
src/components - Auth Context · Client session state, JWT handling, and route access
src/context/AuthContext.js - API Client · Attaches bearer token and handles unauthorized responses
src/lib/api.js - Toast Hook · Shared notification helper for interaction feedback
src/hooks/use-toast.js - Account · Profile and account-related pages
src/pages/akun.js
Backend
Embedded API and server-side orchestration
- API Route · Catch-all route that hands requests to the embedded server
src/pages/api/[[...path]].js - Express App · Central REST API, authorization checks, and business logic
src/server/app.js - Campaign Flow · Builds personalized sends from contacts, groups, templates, and blacklist rules
src/pages/kampanye - Contacts · Core recipient records used by campaigns and reports
src/pages/kontak.js - Groups · Recipient segmentation and targeting
src/pages/grup.js - Templates · Reusable SMS, WhatsApp, and email message templates
src/pages/template - Reports · Campaign outcomes, logs, and delivery visibility
src/pages/laporan.js - Activity Log · Operational history and system activity records
src/pages/log-aktivitas.js - Settings · Application configuration and administrative controls
src/pages/pengaturan.js - Users · Superadmin-managed user administration
src/pages/pengguna.js
Data
Persistence and operational state
- MongoDB · Cached database connections, seeded defaults, and operational records
Delivery
External messaging providers and integrations
- Providers · Third-party SMS, WhatsApp, and email delivery integrations
src/server/providers.js - Integrations · Provider setup, credential testing, and channel selection
src/pages/integrasi.js
Connections 19
- Pages Router → UI Blocks: renders · Pages compose shared UI blocks
- Pages Router → Auth Context: uses · Route access and user state come from client auth
- Pages Router → API Client: calls · Pages submit authenticated API requests
- Auth Context → API Client: token · JWT is stored client-side and attached to requests
- API Client → API Route: requests · Browser API traffic hits the catch-all Next.js route
- API Route → Express App: delegates · The route forwards into the embedded Express app
- Express App → MongoDB: reads/writes · Business logic persists data in MongoDB
- Express App → Providers: sends via · Outbound messages are dispatched through provider adapters
- Campaign Flow → Contacts: targets · Campaigns operate on recipient data
- Campaign Flow → Groups: segments · Group membership shapes blast audiences
- Campaign Flow → Templates: personalizes · Template tokens are resolved before dispatch
- Campaign Flow → Integrations: configures · Channel/provider selection comes from integration settings
- Integrations → Providers: binds · Configured credentials map to delivery backends
- Reports → MongoDB: summarizes · Delivery results and metrics are loaded from persistence
- Activity Log → MongoDB: audits · Activity and operational events are stored in MongoDB
- Users → MongoDB: authorizes · Role-sensitive admin operations are enforced at the database boundary
- Settings → MongoDB: updates · Application settings are persisted centrally
- Account → Auth Context: depends on · Account state is driven by the client auth session
- Toast Hook → Pages Router: feedback · Shared notifications support user actions across pages