This document outlines the architecture and implementation plan for the frontend interface of the Sprite Service. The goal is to provide a user-friendly web interface for uploading images, monitoring processing status, and downloading results, while strictly enforcing security so that the backend API is only accessible via this frontend.
- Framework: Nuxt 3 (Vue 3 based meta-framework)
- Selected for its strong server-side rendering (SSR) capabilities and built-in server engine (Nitro), which is crucial for the security requirements.
- UI Library: Nuxt UI (based on Tailwind CSS and Headless UI)
- Provides modern, accessible components (Buttons, Progress bars, Cards) out of the box.
- State Management: Pinia (if complex state is needed, though simple
useStatemight suffice for this scope). - Containerization: Podman / Docker (Node.js 18+ Alpine image).
To satisfy the requirement that "only this frontend can call the API", we will implement the Backend for Frontend (BFF) pattern using Nuxt's server capability (Nitro).
Browser -> [Python API (Port 8000)]
- Risk: Anyone with network access can hit port 8000 directly.
Browser -> [Nuxt Frontend (Port 3000)] -> [Nuxt Server Proxy (Internal)] -> [Python API (Internal Port 8000)]
- Network Isolation:
- The Python API service in
docker-compose.ymlwill stop exposing port 8000 to the host machine. - It will only listen on the internal Docker network.
- The Python API service in
- Server-Side Proxy:
- The browser will never know the address of the Python API.
- The Browser sends requests to Nuxt Server Routes (e.g.,
/api/upload). - Nuxt (running inside the Docker network) forwards the request to the Python API container (e.g.,
http://api:8000). - This ensures that only the code running on the Nuxt server can communicate with the Python backend.
- Image Upload:
- Drag and drop interface.
- Support for PNG/JPG.
- Client-side validation (file size/type).
- Processing Status:
- Real-time (polling) progress bar or status indicator (Pending -> Processing -> Success/Failure).
- Visual feedback for errors.
- Result Display:
- Preview of the generated sprites (if feasible via zip stream or temp URL).
- "Download Zip" button.
Nuxt will expose the following endpoints to its own frontend:
POST /api/proxy/process: Receivesmultipart/form-data, forwards to PythonPOST /process.GET /api/proxy/status/:id: Forwards to PythonGET /status/{task_id}.GET /api/proxy/download/:id: Forwards to PythonGET /download/{task_id}and streams the response to the client.
- Initialize Nuxt 3 project in
./frontend. - Install
tomcat,@nuxt/ui. - Create
frontend/Dockerfile. - Update root
docker-compose.ymlto include the frontend service and configure internal networking.
- Modify
docker-compose.ymlto removeports: - "8000:8000"from theapiservice. - Ensure
apiandfrontendshare a networkbackend_network.
- Create
server/api/upload.post.ts: Handle file parsing and upstream forwarding. - Create
server/api/status.get.ts: Handle status polling proxy. - Create
server/api/download.get.ts: Handle stream proxying.
- Layout: Basic dashboard layout using Nuxt UI.
- Components:
FileUploader.vue: UI for selecting files.StatusCard.vue: Shows task state and progress.ResultPreview.vue: Shows download button.
- Page:
index.vueorchestrating the flow.
frontend/nuxt.config.ts
export default defineNuxtConfig({
modules: ['@nuxt/ui'],
runtimeConfig: {
// Private keys (server-side only)
apiUrl: 'http://api:8000', // Internal Docker URL
// Public keys (exposed to client)
public: {}
}
})