Architecture
Frontend Architecture
Detailed architecture of the Next.js frontend — components, pages, styling, and glassmorphism design system.
Frontend Architecture
The BAP frontend is a Next.js application with React, using Tailwind CSS and a glassmorphism design system.
Technology Stack
| Component | Technology |
|---|---|
| Framework | Next.js 16, React 19 |
| Language | TypeScript 5.9 |
| Styling | Tailwind CSS 4 |
| UI Components | shadcn/ui, Radix UI |
| Animations | Framer Motion, GSAP |
| State Management | React hooks/context |
| HTTP Client | Custom ApiClient (lib/api.ts) |
Project Structure
web/
├── src/
│ ├── app/ # Next.js App Router
│ │ ├── (auth)/
│ │ │ ├── login/
│ │ │ └── register/
│ │ ├── (dashboard)/
│ │ │ ├── dashboard/
│ │ │ ├── settings/
│ │ │ ├── survivors/
│ │ │ ├── will/
│ │ │ └── liveness/
│ │ ├── survivor/
│ │ │ └── [willId]/
│ │ ├── layout.tsx
│ │ └── page.tsx
│ ├── components/
│ │ ├── ui/ # shadcn components
│ │ │ ├── button.tsx
│ │ │ ├── input.tsx
│ │ │ ├── card.tsx
│ │ │ └── ...
│ │ ├── forms/ # Form components
│ │ ├── layout/ # Layout components
│ │ └── survivors/ # Survivor-specific
│ ├── lib/
│ │ ├── api.ts # API client
│ │ ├── auth.ts # Auth utilities
│ │ └── utils.ts
│ ├── hooks/ # Custom hooks
│ ├── types/ # TypeScript types
│ └── styles/
│ └── globals.css
├── public/
├── tailwind.config.ts
├── next.config.js
└── package.jsonDesign System
Glassmorphism Theme
BAP uses a glassmorphism design:
/* Glass effect */
.glass {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
}Color Palette
| Role | Color |
|---|---|
| Background | Dark gradient (#0f0f23 → #1a1a3e) |
| Primary | Electric blue (#3b82f6) |
| Secondary | Purple (#8b5cf6) |
| Accent | Cyan (#06b6d4) |
| Text Primary | White (#ffffff) |
| Text Secondary | Gray (#9ca3af) |
Typography
- Headings: Inter Bold
- Body: Inter Regular
- Monospace: JetBrains Mono (for codes)
Pages
Authentication Pages
/login— Host login/register— Host registration
Host Dashboard
/dashboard— Overview, quick actions/settings— Profile, connectors, storage/settings/connectors— Manage connectors/settings/storage— Manage storage/settings/liveness— Liveness configuration/survivors— Manage survivors/will— View/create will/will/upload— Upload documents/will/liveness— Liveness history
Survivor Portal
/survivor/[willId]— Survivor portal entry- Authentication flow
- Document access
Components
UI Components (shadcn/ui)
Based on Radix UI primitives:
- Button
- Input
- Card
- Form
- Dialog
- Dropdown
- Tabs
- Table
- Badge
Custom Components
src/components/
├── forms/
│ ├── LoginForm.tsx
│ ├── RegisterForm.tsx
│ ├── ConnectorForm.tsx
│ ├── SurvivorForm.tsx
│ └── WillUpload.tsx
├── layout/
│ ├── Sidebar.tsx
│ ├── Header.tsx
│ └── Footer.tsx
├── dashboard/
│ ├── StatsCard.tsx
│ ├── WillStatus.tsx
│ └── LivenessCheck.tsx
└── survivor/
├── SurvivorList.tsx
├── OTPScreen.tsx
└── DocumentList.tsxState Management
React Context
// Auth context
useAuth() -> { user, login, logout }
// Will context
useWill() -> { will, status, documents }
// Transfer context
useTransfer() -> { transfer, authenticated, threshold }Form State
Using React Hook Form:
const form = useForm({
defaultValues: {
email: '',
password: ''
}
});API Integration
API Client
Centralized API client with:
- Base URL configuration
- Authentication header injection
- Error handling
- Response type transformation
// lib/api.ts
const api = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL
});
api.interceptors.request.use((config) => {
const token = getToken();
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
});Data Fetching
Using React Query or SWR for server state:
const { data, isLoading } = useQuery({
queryKey: ['will'],
queryFn: fetchWill
});Authentication Flow
Host Authentication
- User submits login form
- POST to
/api/auth/login - Receive JWT tokens
- Store tokens (httpOnly cookie or secure storage)
- Redirect to dashboard
Survivor Authentication
- Visit survivor portal link
- Select name from list
- POST to
/api/survivor-auth/select - Receive OTP
- Verify OTP
- Access granted when threshold met
Responsive Design
Mobile First
- Tailwind responsive classes
- Breakpoints: sm, md, lg, xl, 2xl
- Touch-friendly targets (44px minimum)
Example
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{/* Cards */}
</div>Performance
Optimization
- Server-side rendering (SSR)
- Static generation for public pages
- Image optimization
- Code splitting
- Lazy loading
Bundle Size
- Tree shaking
- Minimal dependencies
- shadcn/ui (import on demand)
Accessibility
WCAG 2.1 AA
- Semantic HTML
- ARIA labels
- Keyboard navigation
- Focus management
- Color contrast (4.5:1)
Environment Variables
NEXT_PUBLIC_API_URL=http://localhost:8080/apiNext Steps
- Database Architecture — Schema design
- Connector Architecture — Notification system
- Storage Architecture — Storage abstraction