An analytics dashboard built with SvelteKit — SSR with streaming, real-time data via Server-Sent Events, form actions for mutations, Chart.js visualizations, and a responsive multi-page UI.
$state, $derived, $effect), latest reactivity modelload functions with streamed promises for fast initial paint| Component | Choice |
|---|---|
| Framework | SvelteKit + Svelte 5 |
| Language | TypeScript (strict mode) |
| Database | SQLite (better-sqlite3) |
| ORM | Drizzle ORM + Drizzle Kit |
| Charts | Chart.js 4 |
| Styling | Tailwind CSS 4 |
| Auth | Custom cookie-based (bcrypt) |
| Real-time | Server-Sent Events |
| Unit Tests | Vitest |
| E2E Tests | Playwright |
| Linting | ESLint + Prettier |
# Prerequisites: Node.js 22+
# Install dependencies
npm install
# Create and seed the database
npm run seed
# Start development server
npm run dev
Open http://localhost:5173 and log in with:
| Page | Route | Description |
|---|---|---|
| Overview | / |
KPI cards, revenue trend, activity by type |
| Sales | /sales |
Revenue by product, monthly trends, top customers with date filtering |
| Users | /users |
Signups over time, demographics, retention, customer growth |
| System | /system |
Live CPU/memory charts via SSE, error rates, active users |
src/
├── hooks.server.ts # Auth guard: validate session cookie
├── lib/
│ ├── server/ # Database, auth, SSE helpers
│ ├── components/ # Charts, layout, UI, forms
│ ├── stores/ # Theme and real-time state (Svelte 5 runes)
│ ├── utils/ # CSV, formatters, chart config
│ └── types/ # TypeScript interfaces
├── routes/
│ ├── login/ # Form action: login
│ ├── logout/ # Form action: logout
│ ├── (dashboard)/ # Auth-protected group
│ │ ├── sales/ # Sales analytics
│ │ ├── users/ # User metrics
│ │ └── system/ # System health + SSE
│ └── api/
│ ├── metrics/stream/ # SSE endpoint
│ └── export/ # CSV export endpoint
└── tests/
├── unit/ # Vitest tests
└── e2e/ # Playwright tests
Create a .env file based on .env.example:
DATABASE_URL=sqlite://data.db
SESSION_SECRET=change-me-to-a-random-secret-in-production
npm run dev # Start dev server
npm run build # Production build
npm run preview # Preview production build
npm run test # Run unit tests
npm run test:e2e # Run E2E tests
npm run lint # Check formatting and lint
npm run format # Auto-format code
npm run check # TypeScript type checking
npm run seed # Seed database with demo data
npm run migrate # Run database migrations
MIT