π¨ Frontend Overview
This document outlines the frontend architecture of the application, including its component structure, routing, state management, and architectural philosophies.
π§ App Flow & Component Hierarchy
Hereβs what happens when a user interacts with the UI:
- AppEntry (
main.tsx
):- Initializes the React app, wraps it in context providers, and renders the router.
- Routing:
- Client-side routing is handled via React Router.
- Public and private routes are wrapped with guards (
GuestRoute
,PrivateRoute
).
- Layout Components:
- Top-level layout components (e.g.
AuthLayout
) define consistent page structure.
- Top-level layout components (e.g.
- Page Components:
- Each page (
Login
,Register
,Dashboard
, etc.) is a top-leavel route component.
- Each page (
- UI Components:
- Reusable UI primitives like
Input
,Button
, andBack
are used across the app.
- Reusable UI primitives like
- Hooks:
- Custom React hooks like
useLoginUser
,useAuthenticatedUser
, etc. manage logic and data fetching.
- Custom React hooks like
- Context:
- Auth state is managed via React Context (
AuthContext
) and shared globally.
- Auth state is managed via React Context (
π Folder Structure
src/
βββ components/ # Reusable UI components (Input, Button, etc.)
βββ contexts/ # React contexts (AuthContext, etc.)
βββ features/ # Feature-specific logic (auth, dashboard, etc.)
β βββ auth/
β βββ components/ # Auth-specific components (Login, Register, etc.)
β βββ hooks/ # Hooks like useLoginUser, useRegisterUser
β βββ pages/ # Page-level components
β βββ validationSchema.ts
βββ lib/ # Utility libraries (e.g., Axios instance)
βββ routes/ # Route definitions and guards (PrivateRoute, GuestRoute)
βββ types/ # Global TypeScript types (e.g., User)
βββ App.tsx # Root component
βββ main.tsx # App entry point
βββ vite.config.ts # Vite configuration
tests/
βββ ... # Vitest test files (unit & integration)
public/
βββ index.html # Static HTML entry point
π§Ό Code Organization Philosophy
- Modular Features: Each domain (lik
auth
) contains its own components, hooks, and pages for better isolation. - Composable UI: UI components are kept atomic and reusable. Larger components are built from smaller ones.
- Hook-Driven Logic: Data fetching and business logic live in custom hooks.
- Context-Scoped State: Auth and session state live in
AuthContext
and are consumed viauseAuth()
. - Type-Safe: TypeScript enforces correctness across components, hooks, and API responses.
π¨ Styling Standards
- Tailwind CSS:
- Utility-first CSS for fast and consistent styling.
- Classnames use logical grouping for readability.
- Fonts & Colors:
- Inter font for consistent typography.
- Custom color palette includes primary, secondary, etc.
- Accessibility:
- Focus states, aria-labels, and semantic HTML are prioritized.
π§ͺ Testing Philosophy
- Vitest + Testing Library for unit and integration tests
- Coverage for components, hooks, and page logic
- Mocked API respones via
vi.mock()
- Tests colocated with the feature being tested