Frontend Architecture
pb-ext serves static files from thepb_public/ directory, making it compatible with any static site generator. The recommended approach is SvelteKit with the static adapter.
SvelteKit Integration
Project Setup
Create a SvelteKit application in thefrontend/ directory:
- Template: Skeleton project (or your preferred template)
- Language: TypeScript (recommended)
- Adapter: static-adapter (required for pb-ext compatibility)
- Add-ons: ESLint, Prettier, Playwright (as needed)
Static Adapter Configuration
SvelteKit requires configuration for static site generation. Createfrontend/src/routes/+layout.ts:
Enable static prerendering for all routes
Ensure trailing slashes for consistent routing
Build Configuration
Ensurefrontend/svelte.config.js uses the static adapter:
svelte-gui Starter Template
For a complete, production-ready SvelteKit setup, use the svelte-gui template:Features
Authentication UI
Pre-built login, signup, and profile pages
Dashboard Layout
Responsive admin dashboard with sidebar navigation
API Integration
PocketBase SDK integration and API examples
Dark Mode
Built-in theme switching with Tailwind CSS
Components
Reusable UI components and form elements
TypeScript
Full type safety with TypeScript
pb_public/ Directory Structure
Thepb_public/ directory is where static files are served from:
Path Resolution
pb-ext searches forpb_public/ in multiple locations:
./pb_public(current directory)- Executable directory +
/pb_public - Executable directory +
/../pb_public - Executable directory +
/../../pb_public
The server logs the resolved
pb_public path on startup for debugging.Build Pipeline
Development Builds
Thepb-cli toolchain handles frontend builds automatically:
What pb-cli Does
Production Builds
Production builds optimize assets for deployment:dist/ with:
- Minified JavaScript and CSS
- Prerendered HTML pages
- Compressed assets
- Production-ready binary
Static File Serving
All files inpb_public/ are served at the root path:
| File Path | URL |
|---|---|
pb_public/index.html | http://localhost:8090/ |
pb_public/about.html | http://localhost:8090/about |
pb_public/assets/logo.png | http://localhost:8090/assets/logo.png |
Development vs Production
Development Mode
- Hot module replacement (HMR) via SvelteKit dev server
- Source maps enabled
- Verbose logging
- OpenAPI specs generated at runtime via AST parsing
Production Mode
- Minified and optimized assets
- No source maps
- Structured logging only
- OpenAPI specs read from disk (
dist/specs/) - Binary optimization with
-ldflags="-s -w"
Asset Optimization
Image Optimization
Use SvelteKit’senhanced:img for automatic optimization:
Code Splitting
SvelteKit automatically code-splits routes:Preloading
Preload critical routes for faster navigation:API Integration
Connect your frontend to pb-ext APIs:PocketBase SDK
Install the PocketBase JavaScript SDK:Client Setup
Create a PocketBase client infrontend/src/lib/pocketbase.ts:
Authentication Example
Frontend Detection
The build toolchain automatically detects frontend type:Troubleshooting
404 errors for static files
404 errors for static files
Cause: Files not in
pb_public/ or incorrect path.Solution:- Verify files exist in
pb_public/ - Check server logs for resolved
pb_publicpath - Ensure paths are relative (no leading
/)
Frontend build fails
Frontend build fails
Cause: Missing dependencies or build errors.Solution:
Assets not updating
Assets not updating
Cause: Browser cache or build cache.Solution:
- Hard refresh browser (Ctrl+Shift+R)
- Delete
pb_public/and rebuild - Clear SvelteKit cache:
rm -rf frontend/.svelte-kit
Prerender errors in SvelteKit
Prerender errors in SvelteKit
Cause: Dynamic routes without prerender configuration.Solution: Add
+page.ts with prerender config: