# duniagelap134/24accurate-frontend architecture

> Architecture diagram of the GitHub repository duniagelap134/24accurate-frontend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/duniagelap134/24accurate-frontend
- Repository: https://github.com/duniagelap134/24accurate-frontend

## Overview

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: [`src/pages/kampanye`](https://github.com/duniagelap134/24accurate-frontend/tree/main/src/pages/kampanye) (Campaign Flow), [`src/pages`](https://github.com/duniagelap134/24accurate-frontend/tree/main/src/pages) (Pages Router), [`src/server/app.js`](https://github.com/duniagelap134/24accurate-frontend/blob/main/src/server/app.js) (Express App), [`src/context/AuthContext.js`](https://github.com/duniagelap134/24accurate-frontend/blob/main/src/context/AuthContext.js) (Auth Context)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_pages["Pages Router<br/>next routes"]
  node_ui["UI Blocks<br/>components"]
  node_authctx["Auth Context<br/>client auth<br/>[AuthContext.js]"]
  node_apiclient["API Client<br/>HTTP client<br/>[api.js]"]
  node_toast["Toast Hook<br/>ui feedback<br/>[use-toast.js]"]
  node_account["Account<br/>user settings<br/>[akun.js]"]
end

subgraph group_backend["Backend"]
  node_appapi["API Route<br/>next api bridge<br/>[[[...path]].js]"]
  node_serverapp["Express App<br/>rest api<br/>[app.js]"]
  node_campaigns["Campaign Flow<br/>blast orchestration"]
  node_contacts["Contacts<br/>crm data<br/>[kontak.js]"]
  node_groups["Groups<br/>audience data<br/>[grup.js]"]
  node_templates["Templates<br/>message content"]
  node_reports["Reports<br/>analytics<br/>[laporan.js]"]
  node_logs["Activity Log<br/>audit trail<br/>[log-aktivitas.js]"]
  node_settings["Settings<br/>system config<br/>[pengaturan.js]"]
  node_users["Users<br/>[pengguna.js]"]
end

subgraph group_data["Data"]
  node_db[("MongoDB<br/>atlas persistence")]
end

subgraph group_delivery["Delivery"]
  node_providers["Providers<br/>delivery adapters<br/>[providers.js]"]
  node_integrations["Integrations<br/>delivery config<br/>[integrasi.js]"]
end

node_pages -->|"renders"| node_ui
node_pages -->|"uses"| node_authctx
node_pages -->|"calls"| node_apiclient
node_authctx -.->|"token"| node_apiclient
node_apiclient -->|"requests"| node_appapi
node_appapi -->|"delegates"| node_serverapp
node_serverapp -->|"reads/writes"| node_db
node_serverapp -->|"sends via"| node_providers
node_campaigns -->|"targets"| node_contacts
node_campaigns -->|"segments"| node_groups
node_campaigns -->|"personalizes"| node_templates
node_campaigns -->|"configures"| node_integrations
node_integrations -->|"binds"| node_providers
node_reports -->|"summarizes"| node_db
node_logs -->|"audits"| node_db
node_users -->|"authorizes"| node_db
node_settings -->|"updates"| node_db
node_account -->|"depends on"| node_authctx
node_toast -.->|"feedback"| node_pages

click node_pages "https://github.com/duniagelap134/24accurate-frontend/tree/main/src/pages"
click node_ui "https://github.com/duniagelap134/24accurate-frontend/tree/main/src/components"
click node_authctx "https://github.com/duniagelap134/24accurate-frontend/blob/main/src/context/AuthContext.js"
click node_apiclient "https://github.com/duniagelap134/24accurate-frontend/blob/main/src/lib/api.js"
click node_toast "https://github.com/duniagelap134/24accurate-frontend/blob/main/src/hooks/use-toast.js"
click node_appapi "https://github.com/duniagelap134/24accurate-frontend/blob/main/src/pages/api/[[...path]].js"
click node_serverapp "https://github.com/duniagelap134/24accurate-frontend/blob/main/src/server/app.js"
click node_providers "https://github.com/duniagelap134/24accurate-frontend/blob/main/src/server/providers.js"
click node_campaigns "https://github.com/duniagelap134/24accurate-frontend/tree/main/src/pages/kampanye"
click node_contacts "https://github.com/duniagelap134/24accurate-frontend/blob/main/src/pages/kontak.js"
click node_groups "https://github.com/duniagelap134/24accurate-frontend/blob/main/src/pages/grup.js"
click node_templates "https://github.com/duniagelap134/24accurate-frontend/tree/main/src/pages/template"
click node_integrations "https://github.com/duniagelap134/24accurate-frontend/blob/main/src/pages/integrasi.js"
click node_reports "https://github.com/duniagelap134/24accurate-frontend/blob/main/src/pages/laporan.js"
click node_logs "https://github.com/duniagelap134/24accurate-frontend/blob/main/src/pages/log-aktivitas.js"
click node_account "https://github.com/duniagelap134/24accurate-frontend/blob/main/src/pages/akun.js"
click node_settings "https://github.com/duniagelap134/24accurate-frontend/blob/main/src/pages/pengaturan.js"
click node_users "https://github.com/duniagelap134/24accurate-frontend/blob/main/src/pages/pengguna.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_pages,node_ui,node_authctx,node_apiclient,node_toast,node_account toneBlue
class node_appapi,node_serverapp,node_campaigns,node_contacts,node_groups,node_templates,node_reports,node_logs,node_settings,node_users toneAmber
class node_db toneMint
class node_providers,node_integrations toneRose
```

## Components

### Frontend

Next.js pages, shared UI, and browser-side state

- [Pages Router](https://github.com/duniagelap134/24accurate-frontend/tree/main/src/pages): next routes · Browser-facing routes and page shells · `src/pages`
- [UI Blocks](https://github.com/duniagelap134/24accurate-frontend/tree/main/src/components): components · Reusable cards, tables, charts, layout, and controls · `src/components`
- [Auth Context](https://github.com/duniagelap134/24accurate-frontend/blob/main/src/context/AuthContext.js): client auth · Client session state, JWT handling, and route access · `src/context/AuthContext.js`
- [API Client](https://github.com/duniagelap134/24accurate-frontend/blob/main/src/lib/api.js): HTTP client · Attaches bearer token and handles unauthorized responses · `src/lib/api.js`
- [Toast Hook](https://github.com/duniagelap134/24accurate-frontend/blob/main/src/hooks/use-toast.js): ui feedback · Shared notification helper for interaction feedback · `src/hooks/use-toast.js`
- [Account](https://github.com/duniagelap134/24accurate-frontend/blob/main/src/pages/akun.js): user settings · Profile and account-related pages · `src/pages/akun.js`

### Backend

Embedded API and server-side orchestration

- [API Route](https://github.com/duniagelap134/24accurate-frontend/blob/main/src/pages/api/[[...path]].js): next api bridge · Catch-all route that hands requests to the embedded server · `src/pages/api/[[...path]].js`
- [Express App](https://github.com/duniagelap134/24accurate-frontend/blob/main/src/server/app.js): rest api · Central REST API, authorization checks, and business logic · `src/server/app.js`
- [Campaign Flow](https://github.com/duniagelap134/24accurate-frontend/tree/main/src/pages/kampanye): blast orchestration · Builds personalized sends from contacts, groups, templates, and blacklist rules · `src/pages/kampanye`
- [Contacts](https://github.com/duniagelap134/24accurate-frontend/blob/main/src/pages/kontak.js): crm data · Core recipient records used by campaigns and reports · `src/pages/kontak.js`
- [Groups](https://github.com/duniagelap134/24accurate-frontend/blob/main/src/pages/grup.js): audience data · Recipient segmentation and targeting · `src/pages/grup.js`
- [Templates](https://github.com/duniagelap134/24accurate-frontend/tree/main/src/pages/template): message content · Reusable SMS, WhatsApp, and email message templates · `src/pages/template`
- [Reports](https://github.com/duniagelap134/24accurate-frontend/blob/main/src/pages/laporan.js): analytics · Campaign outcomes, logs, and delivery visibility · `src/pages/laporan.js`
- [Activity Log](https://github.com/duniagelap134/24accurate-frontend/blob/main/src/pages/log-aktivitas.js): audit trail · Operational history and system activity records · `src/pages/log-aktivitas.js`
- [Settings](https://github.com/duniagelap134/24accurate-frontend/blob/main/src/pages/pengaturan.js): system config · Application configuration and administrative controls · `src/pages/pengaturan.js`
- [Users](https://github.com/duniagelap134/24accurate-frontend/blob/main/src/pages/pengguna.js): admin users · Superadmin-managed user administration · `src/pages/pengguna.js`

### Data

Persistence and operational state

- **MongoDB**: atlas persistence · Cached database connections, seeded defaults, and operational records

### Delivery

External messaging providers and integrations

- [Providers](https://github.com/duniagelap134/24accurate-frontend/blob/main/src/server/providers.js): delivery adapters · Third-party SMS, WhatsApp, and email delivery integrations · `src/server/providers.js`
- [Integrations](https://github.com/duniagelap134/24accurate-frontend/blob/main/src/pages/integrasi.js): delivery config · Provider setup, credential testing, and channel selection · `src/pages/integrasi.js`

## Connections

- 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
