Skip to Content
Welcome to the official DBS Documentation! πŸ“š
Getting StartedFolder Structure

Folder Structure

DBS follows a domain-driven organization within the Next.js App Router conventions. This guide explains the purpose of each directory and how they relate to each other.

prisma/ β”œβ”€β”€ schema.prisma ← Database schema (single source of truth) └── seed.ts ← Seeds roles, permissions, menus, super admin src/ β”œβ”€β”€ app/ β”‚ β”œβ”€β”€ api/ ← All REST API route handlers β”‚ └── dashboard/ ← All authenticated dashboard pages (UI) β”œβ”€β”€ components/ β”‚ β”œβ”€β”€ common/ ← Shared UI: PageHeader, EmptyState, DataLoader… β”‚ β”œβ”€β”€ common/form/ ← Form field wrappers: FormInput, FormSelect… β”‚ └── dashboard/ ← Dashboard-specific layout components β”œβ”€β”€ hooks/ ← Custom SWR-based data hooks β”œβ”€β”€ lib/ ← Core utilities and singletons β”œβ”€β”€ services/ ← Typed API client functions (client-side) └── types/ ← Shared TypeScript type definitions

prisma/

FilePurpose
schema.prismaDefines every database model: User, Role, Permission, Menu, Task, AuditLog, Notification, etc.
seed.tsPopulates the database with default roles, permissions, sidebar menus, and the initial super_admin user. Run with npm run db:seed.

src/app/api/

Every subdirectory maps to a group of REST endpoints:

RouteDescription
api/auth/[...all]Better Auth catch-all handler
api/access/RBAC: manage roles, permissions, and sync them
api/users/List users, assign or sync roles
api/teams/Teams CRUD, members, per-team permissions
api/notifications/Notifications CRUD (create, read, mark as read, delete)
api/logs/Audit log retrieval
api/settings/DB-backed system configuration
api/menus/Dynamic sidebar structure (permission-filtered)
api/stream/eventsSSE endpoint for real-time push
api/tasks/Background task creation and status polling
api/webhooks/tasks/Webhook receiver for completing background tasks
api/mail/Test email sending endpoint

src/app/dashboard/

All pages that require authentication. Each subdirectory contains a page.tsx and a _components/ folder for page-specific components.

RouteDescription
dashboard/Main dashboard with stat cards and analytics
dashboard/users/User list with role assignment
dashboard/teams/Teams management
dashboard/access/Role & permission management UI
dashboard/settings/User profile, 2FA, Passkeys, active sessions
dashboard/notifications/Notification center
dashboard/logs/Audit log viewer
dashboard/broadcast/Send system-wide broadcast messages
dashboard/analytics/Statistics and charts
dashboard/lab/UI component lab / demo playground

src/components/

common/

Reusable presentational components used across all pages:

ComponentPurpose
PageHeaderConsistent page title + description header
EmptyStateShown when a data table has no results
ErrorStateShown when a data fetch fails
DataLoaderWrapper that handles isLoading / error / empty states
PermissionAlertShown when a user lacks permission to view content

common/form/

shadcn/ui wrappers for React Hook Form that handle register, errors, and label automatically:

ComponentPurpose
FormInputText, email, password inputs
FormSelectDropdown select
FormDatePickerDate/time picker

src/hooks/

All client-side data hooks built on top of SWR:

HookPurpose
useDataGeneric SWR wrapper for any GET request
useDataTableFull-featured table hook: sort, filter, pagination, search
usePaginationLightweight pagination state management
useAuditLogsFetches and filters audit log entries
useSessionCurrent user session and refresh helper

src/lib/

Core singletons and utilities. Never import these directly from client components unless explicitly noted:

FilePurpose
prisma.tsPrisma client singleton (server-only)
auth.tsBetter Auth server configuration
auth-client.tsBetter Auth browser client
api-guard.tsAPI route protection (session + rate limit + permission)
audit-logger.tsWrite structured entries to the AuditLog table
config.tsgetSystemConfig() β€” DB-backed settings with .env fallback
email.tssendVerificationEmail() via Resend
events.tsIn-process EventEmitter bus (powers SSE)
rate-limit.tsIn-memory rate limiter
logger.tsWinston-style structured logger
role-hierarchy.tscanManageRole() β€” role elevation prevention
rbac/permission.tsPermission constant definitions
rbac/hooks/usePermission.tsClient-side permission check hook
rbac/components/RouteGuard.tsxServer-side page-level route protection
notification-package/NotificationContext, useNotifications, useTasks

src/services/

Typed API client functions for use in client components. Each file mirrors its corresponding api/ route group:

FileExported ObjectMethods
users/api.tsusersApigetUsers(), assignRole(), syncUserRoles()
teams/api.tsteamsApigetTeams(), createTeam(), addMember(), etc.
access/api.tsaccessApigetRoles(), getPermissions(), syncPermissions()
notifications/api.tsnotificationsApigetNotifications(), markAsRead(), deleteAll()
tasks/api.tstasksApicreateTask(), getTaskStatus()

Never call Prisma or server utilities from src/services/. The services layer is exclusively for fetch() calls to your own API routes, keeping the client/server boundary clean.

Last updated on