β¬ οΈ Back to Resources Index
Static Resources & Templates
Overview: This document explains the static resources and template handling in Smart Supply Pro.
Table of Contents
Architecture: API-Only Backend
Backend Design
Smart Supply Pro backend is a pure REST API:
Clients (Browser, Mobile, Desktop)
β
HTTP REST Requests
β
Spring Boot API
β
Returns JSON responses (not HTML)
Key Characteristics
β
Returns JSON, not HTML - Endpoints
respond with Content-Type: application/json -
Response body is JSON (not HTML pages)
β No Server-Side Rendering - No Thymeleaf or other template engines - No JSP files - No static HTML served from backend
β
No Frontend Code in Backend -
src/main/resources/static/ β Empty -
src/main/resources/templates/ β Empty
β Separation of Concerns - Backend handles: Business logic, data, security - Frontend handles: UI, user experience, layout - Clear division of responsibilities
Request/Response Example
Frontend Request:
GET /api/suppliers?page=1&size=20
Backend Response (JSON):
{
"content": [
{ "id": "SUP-001", "name": "Widget Corp", "email": "contact@widgetcorp.com" },
{ "id": "SUP-002", "name": "Gadget Inc", "email": "info@gadgetinc.com" }
],
"page": 1,
"totalPages": 5,
"totalElements": 92
}Frontend renders this JSON into HTML (using React, Vue, Angular, etc.)
Directory Structure
Actual Files in Resources
src/main/resources/
βββ application.yml # Spring Boot config (load this!)
βββ application-prod.yml
βββ application-test.yml
βββ application.properties
βββ templates/ # EMPTY (no backend templates)
β βββ (no files)
βββ static/ # EMPTY (no static files here)
β βββ (no files)
βββ logback-spring.xml # (if present, logging config)
Whatβs Actually Empty
| Directory | Purpose | Status | Why |
|---|---|---|---|
templates/ |
Thymeleaf/FreeMarker templates | β Empty | API returns JSON, not HTML |
static/ |
CSS, JavaScript, images | β Empty | Frontend handles presentation |
public/ |
Alternative static location | β Empty | Same reason |
Frontend Location
Where Frontend Code Lives
Location: /frontend directory
(project root level, not in backend)
inventory-service/ (git root)
βββ src/ # Backend (Java)
β βββ main/java
β βββ main/resources
β βββ test/
βββ frontend/ # Frontend (React/TypeScript)
β βββ src/
β β βββ components/
β β βββ pages/
β β βββ App.tsx
β βββ public/
β βββ package.json
β βββ tsconfig.json
β βββ vite.config.ts
β βββ Dockerfile
βββ docs/ # This documentation
βββ pom.xml # Backend build (Maven)
βββ docker-compose.yml
βββ fly.toml
βββ README.md
Frontend Technology Stack
| Component | Technology |
|---|---|
| Framework | React |
| Language | TypeScript |
| Build Tool | Vite |
| Package Manager | npm |
| Styling | TBD (check frontend/package.json) |
Frontend Deployment
Deployed Separately from backend: - Backend: Fly.io (Java/Spring Boot) - Frontend: Typically Vercel, Netlify, or Fly.io (as separate service)
Example deployment flow:
Push to origin/main
β
GitHub Actions triggers 2 deployments:
βββ Backend build & deploy (Java β Fly.io)
βββ Frontend build & deploy (React β Vercel)
β
Both services deployed independently
Frontend-Backend Communication
HTTP Protocol:
Frontend (React):
const response = await fetch('https://api.example.com/api/suppliers');
const data = await response.json();
// Renders data with React components
Backend (Spring Boot):
@GetMapping("/api/suppliers")
public Page<SupplierDTO> getSuppliers(...) {
return supplierService.findAll(...); // Returns JSON
}
CORS Configuration: Backend enables CORS for frontend domain
# See Security Architecture docs for CORS configWhy No Backend Templates
Historical Context
Earlier web development used server-side rendering:
Browser β Request HTML file
β
Server β Generate HTML from template + data
β
Server β Send complete HTML page
β
Browser β Render HTML
Tools: Thymeleaf, JSP, ERB, Jinja2
Modern Architecture (Used Here)
Browser β Request JSON from API
β
Server β Return JSON (no rendering)
β
Browser β Receive JSON
β
Browser β Render HTML locally with JavaScript framework
Tools: React, Vue, Angular, Svelte
Advantages of API-Only Backend
β Decoupling: - Backend and frontend teams work independently - Backend can serve multiple clients (web, mobile, desktop) - Frontend can change without backend changes
β Performance: - Frontend caching (browser cache, service workers) - Faster iteration on UI without server redeploy - Client handles rendering (less server load)
β Scalability: - Frontend served from CDN (static files) - Backend scales horizontally without UI concerns - Separate deployments prevent coupling
β Developer Experience: - Frontend developers use modern tools (Vite, npm, webpack) - Backend developers use Java/Spring tools - Clear separation of concerns - Easier testing and debugging
CORS Configuration
Because frontend and backend are separate, Cross-Origin Resource Sharing (CORS) must be configured.
What is CORS?
Frontend at: https://myapp.com (runs in browser)
Backend at: https://api.example.com
Browser blocks requests from frontend to backend
(Security feature: prevent unauthorized cross-domain requests)
Solution: Backend must explicitly allow requests from frontend
(via CORS headers)
Backend CORS Configuration
See: Security Architecture - CORS Configuration
Example:
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/api/**")
.allowedOrigins("https://myapp.com") // Frontend URL
.allowedMethods("GET", "POST", "PUT", "DELETE")
.allowedHeaders("*")
.allowCredentials(true);
}
}API Documentation for Frontend Developers
OpenAPI/Swagger
Automatic API docs generated from code:
# Access at:
http://localhost:8081/swagger-ui.htmlProvides: - Interactive API explorer - Request/response examples - Parameter documentation - Try it out functionality
Frontend Integration
Frontend uses generated API client:
// React component
import { supplierApi } from '@/api/suppliers';
export function SupplierList() {
const [suppliers, setSuppliers] = useState([]);
useEffect(() => {
supplierApi.getAll()
.then(response => setSuppliers(response.data))
.catch(error => console.error(error));
}, []);
return (
<div>
{suppliers.map(s => <SupplierCard key={s.id} supplier={s} />)}
</div>
);
}Summary
| Aspect | Backend | Frontend |
|---|---|---|
| Location | src/main/java, src/main/resources | /frontend |
| Technology | Spring Boot, Java | React, TypeScript |
| Returns | JSON | HTML (rendered by React) |
| Serves Static Files | No (empty static/ folder) | Yes (public/ folder) |
| Templates | None (REST API only) | JSX/TSX components |
| Deployed To | Fly.io | Vercel/Netlify/CDN |
| Port | 8081 (API) | 5173 (dev), 443 (prod) |
Getting Started with Frontend
Develop Locally
cd frontend
# Install dependencies
npm install
# Start dev server (Vite)
npm run dev
# Frontend runs at: http://localhost:5173
# Backend at: http://localhost:8081Build for Production
cd frontend
# Build optimized bundle
npm run build
# Output in: frontend/dist/
# This is deployed to CDN or frontend hostingFrontend Documentation
See: /frontend/README.md for
frontend-specific setup and development