This document describes the high-level architecture of the frontend monorepo, how applications interact, and the design patterns used throughout the codebase.
This is a monorepo containing multiple Next.js applications that share code, components, and infrastructure while maintaining clear boundaries for independent operation.
┌─────────────────────────────────────────────────────────┐
│ Frontend Monorepo │
├─────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Personal │ │ Discart-me │ │ QRACK │ │
│ │ Website │ │ (Marketplace)│ │ (Inventory) │ │
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
│ │ │ │ │
│ └──────────────────┼──────────────────┘ │
│ │ │
│ ┌──────────────────▼──────────────────┐ │
│ │ Shared Infrastructure │ │
│ │ • Components (UI, Features) │ │
│ │ • Utilities (API clients, hooks) │ │
│ │ • Types & Interfaces │ │
│ │ • Design System (Tailwind) │ │
│ └──────────────────┬──────────────────┘ │
│ │ │
│ ┌──────────────────▼──────────────────┐ │
│ │ Backend APIs │ │
│ │ • REST (Discart-me) │ │
│ │ • GraphQL (QRACK, BoxHub) │ │
│ └──────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────┘
Router: Pages Router (/pages)
State Management: Local component state, React Context
Data Fetching: Static generation, API routes
Purpose: Public-facing portfolio and blog
Key Characteristics:
Router: App Router (/app/discart-me)
State Management: Context API (DiscartAuthContext)
Data Fetching: REST API with fetch
Purpose: Community marketplace
Key Characteristics:
Router: App Router (/app/qrack)
State Management: Generic Auth Provider (QrackAuthProvider)
Data Fetching: GraphQL API
Purpose: Container and inventory management
Key Characteristics:
Location: /src/components and /components
Organization:
/components/ui — Generic, reusable UI primitives (Button, Input, Modal, Loading)/src/components/discart-me — Discart-me specific components/src/components/qrack — QRACK specific components/components — Shared layout components (Navbar, Footer, etc.)Guidelines:
/components/ui follow strict guidelines (see UI Base Guidelines)Location: /src/features
Feature modules encapsulate related functionality:
auth/ — Generic authentication system
AuthProvider.tsx — Generic auth contextuseAuth.ts — Generic auth hookQrackAuthProvider)discart-me/ — Discart-me specific features
hooks/useImageProcessor.ts — Image processing for uploadsqrack/ — QRACK specific features
hooks/useCreateContainer.ts — Container creation logiccomponents/ — QRACK feature componentsPattern:
features/
{domain}/
components/ # Feature-specific UI
hooks/ # Feature-specific logic
types.ts # Feature-specific types
Location: /src/lib
Core Libraries:
api/core/graphqlClient.ts — Shared GraphQL clientqrackApi.ts — QRACK GraphQL API clientdiscartMeApi.ts — Discart-me REST API clientboxhubApi.ts — BoxHub GraphQL API clientimage/ — Shared image processing library
processImage.ts — Resize, compress, format conversionutils.ts — Validation, formattingconstants.ts — Image presets (marketplace, container, avatar)Utilities:
upload.ts — File upload helpersutils.ts — General utilities (class merging, etc.)toast.ts — Toast notification systemUser Login
│
├─► Domain-specific auth provider (e.g., QrackAuthProvider)
│ │
│ ├─► Calls generic AuthProvider with domain config
│ │
│ ├─► API call (REST or GraphQL)
│ │
│ ├─► Token stored in localStorage
│ │
│ └─► User data stored in context
│
└─► Protected routes check auth status
Discart-me (REST):
Component
│
├─► Calls function in discartMeApi.ts
│ │
│ ├─► fetch() with Authorization header
│ │
│ ├─► Parse JSON response
│ │
│ └─► Return typed data
QRACK (GraphQL):
Component
│
├─► Calls function in qrackApi.ts
│ │
│ ├─► Uses shared graphqlClient.ts
│ │ │
│ │ ├─► Constructs GraphQL query
│ │ ├─► Adds Authorization header
│ │ ├─► Handles errors
│ │ └─► Returns typed response
Used by: Discart-me, QRACK
Structure:
app/
{domain}/
layout.tsx # Domain-specific layout
page.tsx # Home page
{route}/
page.tsx # Route page
layout.tsx # Nested layout (optional)
Benefits:
Used by: Personal website
Structure:
pages/
index.tsx # Home page
{route}.tsx # Route page
api/
{endpoint}.tsx # API route
Migration Plan: Gradually migrate to App Router (future work)
Most components use useState for local, component-scoped state.
Used for:
Pattern:
// Create context
const MyContext = createContext<MyContextValue | null>(null);
// Provider component
export function MyProvider({ children }: { children: ReactNode }) {
const [state, setState] = useState<State>(initialState);
const value = useMemo(() => ({ state, setState }), [state]);
return <MyContext.Provider value={value}>{children}</MyContext.Provider>;
}
// Custom hook
export function useMyContext() {
const context = useContext(MyContext);
if (!context) throw new Error('Must be used within MyProvider');
return context;
}
Some features use @tanstack/react-query for server state management (e.g., comments, ratings). This will be expanded for consistent data fetching patterns.
GraphQL:
errors arraygraphqlClient.tsREST:
Authorization: Bearer headerCurrent State: Manual testing, no automated tests yet
Future Plans:
The current architecture supports: