The Problem

Marketing teams juggle CRM data, outreach sequences, content calendars, analytics, and automation approvals. Switching between SaaS tools creates manual hand‑offs, inconsistent state, and delayed reporting. A single, locally‑hosted control surface that persists its own SQLite store can eliminate the integration friction and keep sensitive data off third‑party clouds.

What This Does

The repo delivers a self‑hosted dashboard built with Next.js 16 (App Router) and React 19. UI components live under src/components/ (e.g., layout/layout-content.tsx, ui/badge.tsx). Business logic is in src/lib/db.ts abstracts SQLite, auth.ts implements session cookies and optional Google OAuth, while cron-templates.ts and analytics.ts orchestrate scheduled jobs and KPI calculations. API endpoints under src/app/api/ expose CRUD actions for CRM, outreach, content, and agent workflows, all consumed by the front‑end pages in src/app/.

How It Is Wired

Execution starts when Next.js launches via pnpm dev (see next.config.ts). The framework loads each route handler in src/app/api/**/route.ts. A typical request flow is:

  1. Request entry – Next.js calls the exported handler in src/app/api/<resource>/route.ts.
  2. Auth checksrc/lib/auth.ts (verifySession) validates the session cookie or API key.
  3. Business logic – The handler delegates to a library module, e.g., src/lib/db.ts for reads/writes, src/lib/analytics.ts for KPI aggregation, or src/lib/cron-templates.ts for scheduling. src/lib/db.ts is the most fan‑in module (6 incoming imports, 2 outgoing) and therefore the primary point of state mutation.
  4. Side effects – Modules may call external connectors (src/lib/ga4.ts, src/lib/linkedin.ts, src/lib/plausible.ts) or enqueue jobs via src/lib/cron-jobs.ts.
  5. Response – Data is returned to the front‑end page (src/app/<section>/page.tsx) which renders UI components.

The state store (src/store/index.ts) uses Zustand to cache in‑memory slices that mirror the SQLite tables. UI components read from this store, while API routes update both the DB and the store, keeping the UI in sync without a separate data‑fetch layer.

The internal call graph shows no circular dependencies across 162 modules, simplifying refactoring. The highest‑instability module is src/components/layout/layout-content.tsx (imports 5 modules, no inbound), indicating it is a leaf UI piece with limited impact if changed.

How To Use It

# Clone the upstream repository
git clone https://github.com/moses-y/marketing-dashboard
cd marketing-dashboard

# Enable corepack (pnpm 10 required)
corepack enable

# Install exact dependencies
pnpm install --frozen-lockfile

# Bootstrap environment variables from the example
pnpm env:bootstrap   # creates .env.local from .env.example

# Edit .env.local – at minimum set:
#   AUTH_USER, AUTH_PASS, API_KEY, AUTH_COOKIE_SECURE
# (see .env.example for all keys)

# Start the dev server
pnpm dev

Open http://localhost:3000. The first login uses the seeded AUTH_USER/AUTH_PASS. Subsequent users are managed via the /api/auth/* endpoints.

Real‑World Use

A mid‑size B2B team runs the dashboard on a private VM. Lead data from their existing CRM is imported once via the /api/crm/route.ts endpoint. Agents interact with OpenClaw through src/lib/agent-workspace.ts, updating status in real time. Weekly KPI reports are generated by src/lib/analytics.ts and displayed on /app/analytics/page.tsx, eliminating manual spreadsheet merges.

Code Health & Issues

  • High – Pin third‑party GitHub Actions to a commit SHA (.github/workflows/ci.yml).
  • Medium – Declare least‑privilege GITHUB_TOKEN permissions (.github/workflows/ci.yml).
  • Medium – Enable Dependabot or Renovate (.github/dependabot.yml missing).
  • Medium – Add a dependency‑vulnerability scan step in CI.
  • Medium – Set persist-credentials: false on the checkout step.
  • Medium – Expand test coverage (8 test files vs. 162 source files).
  • Low – Define job timeout-minutes in CI.
  • Low – Add repository convention files (.editorconfig, .gitattributes, formatter config).

Additional findings from static analysis: deep nesting (max depth 8) in several pages, duplicated 6‑line blocks across multiple route files, high branching density in auth and cron modules, and three oversized page files (> 800 lines). Refactoring these hotspots will improve readability and reduce change‑impact risk.

The Bottom Line

The repository provides a functional, locally‑first marketing operations hub with a clear separation of API, DB, and UI layers. It is ready to run with minimal setup, but the codebase shows signs of technical debt (deep nesting, duplication) and modest test coverage. Teams comfortable maintaining a Node/Next.js stack and willing to invest in refactoring and CI hardening will find it a solid foundation for internal marketing workflows.