Architecture
ByteBox is a local-first Next.js application with optional Docker and Electron runtime targets.
System Layout
Section titled “System Layout”- Frontend and API live in one Next.js App Router project.
- API routes are implemented under
src/app/api/*. - Persistence uses Prisma with SQLite.
- UI is componentized by domain (
cards,layout,ui,settings).
Main Layers
Section titled “Main Layers”- Presentation
React components under
src/components/*and pages undersrc/app/*. - State and behavior
Hooks and contexts under
src/hooks/*andsrc/contexts/*. - Data access
DB abstraction in
src/lib/db/queries.ts. - Storage
SQLite via
better-sqlite3and Prisma schema inprisma/schema.prisma.
Runtime Targets
Section titled “Runtime Targets”- Web development:
npm run devonhttp://localhost:1334. - Docker: containerized Next.js server with persistent volume-backed SQLite.
- Electron: desktop shell that points to local Next dev server in dev, and in production starts a bundled Next server plus migrations.
Request and Data Flow
Section titled “Request and Data Flow”- User interaction in the dashboard triggers local state updates.
- CRUD operations call route handlers in
src/app/api. - Route handlers call DB helpers in
src/lib/db. - Prisma persists entities in SQLite.
- Updated payloads hydrate UI immediately.
Why This Design Works
Section titled “Why This Design Works”- Single codebase for web + desktop keeps behavior aligned.
- Local SQLite keeps startup and reads fast.
- Route handlers provide a stable contract for UI and future integrations.
- Prisma migrations keep schema evolution manageable across releases.
Key Source Files
Section titled “Key Source Files”src/app/page.tsxsrc/app/api/cards/route.tssrc/lib/db/queries.tsprisma/schema.prismaelectron/main.tsdocker-entrypoint.sh