Frontend Development Guide
Docklift uses Next.js 16 (App Router) for its frontend.
Directory Structure (frontend/app/)
- •
page.tsx: Dashboard (Home). - •
layout.tsx: Root layout (includes ThemeProvider, AuthProvider, Toaster). - •
projects/: Project management routes.- •
[id]/: Project detail view (nested layout). - •
new/: Project creation wizard.
- •
- •
settings/: Global settings. - •
sign-in/: Login page.
Key Architectures
1. Client vs Server Components
- •"use client": Used extensively for interactive dashboards (
useState,useEffect). - •Server Components: Used for static layouts or initial data fetching where possible (though this app relies heavily on client-side API fetching due to auth token storage in localStorage).
2. State Management
- •Local State:
useStatefor UI toggles. - •Global State: Minimal.
AuthContexthandles user session. - •Data Fetching:
useEffect+axios/fetchpattern.- •Standard: Fetch data on mount, show loader, handle error.
3. Streaming Logs
- •Uses Server-Sent Events (SSE).
- •Endpoint:
/api/deployments/:id/logs. - •Frontend:
EventSourceAPI handles real-time updates.
4. File Editor (Monaco)
- •Found in
components/FileEditor.tsx. - •Used for editing
docker-compose.ymland project files directly in the browser.
Common Tasks
Adding a New Page
- •Create
app/new-feature/page.tsx. - •Add
"use client"if it needs interaction. - •Import
HeaderandFooter.
Connecting to Backend
Use the helper in lib/utils.ts or lib/auth.ts:
typescript
import { API_URL } from "@/lib/utils";
import { getAuthHeaders } from "@/lib/auth";
// Fetch
fetch(`${API_URL}/api/resource`, { headers: getAuthHeaders() });
Debugging
- •Hydration Errors: Usually caused by malformed HTML (e.g.,
<div>inside<p>) or dates rendering differently on server/client. - •Auth Issues: Check
Application > Local Storagein devtools fordocklift_token.