π‘ Frontend System Architecture Overview¶
(Node.js β npm β React/Vite β API β Build & Deployment)¶
The frontend layer is the bridge between users and your backend.
It manages UI, application state, and communication with your APIs β built, bundled, and served through Node.js tooling.
This document shows how the frontend development pipeline fits into your full-stack environment.
π§± 1. The Big Picture¶
User β Browser β Frontend App (React/Vite)
β
βΌ
REST / GraphQL API (Nginx β Backend)
β
PostgreSQL & Redis under the hood
````
**Frontend role:**
Present data, handle input, manage state, call backend endpoints, and render updates instantly.
---
## βοΈ 2. Core Components of Modern Frontend
| Component | Purpose | Tool |
|------------|----------|------|
| **Runtime** | JavaScript engine for tooling & builds | Node.js |
| **Package Manager** | Installs dependencies | npm / pnpm / yarn |
| **Framework** | UI logic and components | React, Vue, Svelte |
| **Bundler/Dev Server** | Hot reload, build output | Vite / Webpack |
| **State Management** | Handle UI data flow | Redux, Zustand, Context API |
| **API Layer** | Communicate with backend | Fetch / Axios |
| **Build Output** | Static assets for Nginx | `dist/` folder |
---
## π§© 3. Local Development Flow
```bash
# Install dependencies
npm install
# Start dev server
npm run dev
````
Default:
* Vite dev server on `http://localhost:5173`
* Auto-reloads when files change
* Proxy API calls to backend (e.g., `http://localhost:8080`)
**Example Vite proxy config:**
```js
// vite.config.js
export default {
server: {
proxy: {
'/api': 'http://localhost:8080'
}
}
};
π§ 4. Folder Structure¶
frontend/
ββ src/
β ββ components/
β ββ pages/
β ββ hooks/
β ββ context/
β ββ services/ # API calls, Axios configs
β ββ assets/ # images, styles
β ββ main.jsx
ββ public/
β ββ index.html
ββ package.json
ββ vite.config.js
ββ .env
β‘ 5. Environment Variables¶
Stored in .env (never committed).
Access in React:
β
Prefix with VITE_ for access in client-side code.
π§° 6. Communication with Backend¶
REST Example (Axios)¶
import axios from 'axios';
const api = axios.create({
baseURL: import.meta.env.VITE_API_URL,
});
export const fetchUsers = async () => {
const res = await api.get('/users');
return res.data;
};
GraphQL Example¶
import { request, gql } from 'graphql-request';
const API = import.meta.env.VITE_API_URL + '/graphql';
const query = gql`
query Users { users { id name } }
`;
export async function getUsers() {
return await request(API, query);
}
π§± 7. State and Caching Strategy¶
| Layer | Example | Purpose |
|---|---|---|
| React Context | AuthContext |
Manage global state |
| LocalStorage | token |
Persist login |
| SWR / React Query | useQuery() |
Cache API calls |
| Redux / Zustand | store slice | Predictable state container |
Rule of thumb:
Global state for global data, local state for local UI.
π§© 8. Building for Production¶
Outputs optimized static assets to:
Files include:
index.htmlassets/*.js,*.css
You serve these via Nginx:
server {
listen 80;
server_name example.com;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri /index.html;
}
location /api/ {
proxy_pass http://backend:8080;
}
}
π 9. Dockerizing the Frontend¶
Dockerfile:
# Build stage
FROM node:20-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
# Serve stage
FROM nginx:latest
COPY --from=build /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
docker-compose.yml:
π» 10. Frontend in IDEs (JetBrains / VS Code)¶
JetBrains (WebStorm / IntelliJ Ultimate)¶
- Built-in React + TypeScript tooling.
- Integrated terminal β run
npm run dev. - Live linting, code formatting, and Git integration.
- Debugger for browser + Node processes.
Shortcut tips:
- Shift+F10 β run dev server
- Ctrl+B β jump to component definition
- Ctrl+Shift+R β run npm script
VS Code Setup¶
Recommended extensions:
- ESLint β static analysis
- Prettier β formatting
- Vite β syntax + run configs
- Tailwind CSS IntelliSense
- REST Client β test API endpoints
π§ 11. Testing and Quality¶
Unit tests
Tools: Vitest / Jest.
E2E tests
Define flows:
- User logs in
- Calls
/api/users - Checks UI update
Lint & format
Automation ensures consistent builds across machines.
βοΈ 12. Build β Deploy Pipeline¶
Local β Staging β Production¶
| Step | Tool | Description |
|---|---|---|
| Code changes | Git | Track & commit |
| Build | Vite | Bundle assets |
| Test | Jest / Playwright | Validate functionality |
| Package | Docker | Create deployable image |
| Deploy | Nginx / CI/CD | Serve to users |
CI/CD example (GitHub Actions):
- name: Build and Push Frontend
run: |
docker build -t ghcr.io/user/frontend:${{ github.sha }} .
docker push ghcr.io/user/frontend:${{ github.sha }}
π§© 13. Communication with Backend Stack¶
| Interaction | Description |
|---|---|
| API Requests | fetch() or Axios calls to /api/ |
| Auth Tokens | Sent via Authorization: Bearer <token> headers |
| Rate Limiting | Controlled by Nginx or Redis |
| CORS | Managed by backend or Nginx |
| Real-Time Updates | WebSockets or Redis Pub/Sub bridges |
All HTTP requests pass through Nginx, which proxies to the backend and ensures security.
π§° 14. Developer Workflow Summary¶
- Pull latest code:
git pull - Run dev server:
npm run dev - Build assets:
npm run build - Serve with Docker or Nginx.
- Deploy via CI/CD or manually.
π§ 15. Frontend β Backend Integration Diagram¶
ββββββββββββββββ
β Browser β
β (React/Vite) β
ββββββββ¬βββββββββ
β
β REST/GraphQL calls
βΌ
ββββββββββββββββ
β Nginx Proxy β
ββββββββ¬βββββββββ
β forwards requests
βΌ
ββββββββββββββββ
β Backend API β
ββββββββ¬βββββββββ
β β
βΌ βΌ
PostgreSQL Redis
(storage) (cache)
β 16. Summary¶
- Node.js β runtime & package manager.
- Vite/React β fast UI development.
- Axios/Fetch β API communication.
- Docker & Nginx β consistent build + deployment.
- Git & CI/CD β version control and automation.
Together, these tools mirror the backend architecture β the same principles of reproducibility, versioning, and service boundaries apply.