Skip to content

Overall Architecture

This document describes the overall architecture design of the HaloLight project, including directory structure, layered design, and core patterns.

Directory Structure Specification

Standard Directory Layout

src/
├── app/                    # Page routes (Next.js) or views/ (Vue)
│   ├── (admin)/           # Admin route group
│   │   ├── dashboard/     # Dashboard
│   │   ├── users/         # User management
│   │   ├── roles/         # Role management
│   │   ├── permissions/   # Permission management
│   │   ├── settings/      # System settings
│   │   └── profile/       # User profile
│   └── (auth)/            # Auth route group
│       ├── login/         # Login
│       ├── register/      # Register
│       ├── forgot-password/
│       └── reset-password/
├── components/            # Reusable components
│   ├── ui/               # Basic UI components (shadcn/ui)
│   ├── layout/           # Layout components
│   ├── dashboard/        # Dashboard components
│   ├── charts/           # Chart components
│   └── shared/           # Shared business components
├── hooks/ (composables/)  # Reusable logic
├── stores/               # State management
├── services/             # API service layer
├── lib/                  # Utility library
├── types/                # TypeScript type definitions
├── styles/               # Global styles
└── mocks/                # Mock data

Layered Architecture

Four-Layer Architecture Design

┌─────────────────────────────────────────────────┐
│                   View Layer                     │
│        Pages / Views / Routes                    │
├─────────────────────────────────────────────────┤
│                Component Layer                   │
│     UI Components / Layout / Dashboard          │
├─────────────────────────────────────────────────┤
│                  State Layer                     │
│     Stores / Composables / Hooks                │
├─────────────────────────────────────────────────┤
│                 Service Layer                    │
│     API Services / Data Fetching / Cache        │
└─────────────────────────────────────────────────┘

Layer Responsibilities

LayerResponsibilityFramework Implementation
View LayerPage routing, layout assemblyNext.js Pages / Vue Views
Component LayerUI rendering, user interactionReact/Vue/Svelte Components
State LayerApplication state, business logicZustand / Pinia / Stores
Service LayerAPI calls, data cachingTanStack Query / Axios

Provider Hierarchy

React/Next.js Provider Chain

tsx
<ThemeProvider>
  <MockProvider>
    <QueryClientProvider>
      <AuthProvider>
        <PermissionProvider>
          <WebSocketProvider>
            <ErrorProvider>
              <ToastProvider>
                {children}
              </ToastProvider>
            </ErrorProvider>
          </WebSocketProvider>
        </PermissionProvider>
      </AuthProvider>
    </QueryClientProvider>
  </MockProvider>
</ThemeProvider>

Vue Plugin Registration Order

ts
app.use(pinia)
app.use(router)
app.use(i18n)
app.use(mockPlugin)
app.use(queryPlugin)
app.use(permissionPlugin)

Layout System

AdminLayout Structure

┌──────────────────────────────────────────────────────┐
│                     Header                            │
│  [Logo] [Breadcrumb]           [Search] [User] [Settings]
├────────────┬─────────────────────────────────────────┤
│            │                                          │
│  Sidebar   │              Content                     │
│            │                                          │
│  - Menu    │   ┌──────────────────────────────────┐  │
│  - Nav     │   │        Page Content               │  │
│            │   │                                   │  │
│            │   └──────────────────────────────────┘  │
│            │                                          │
├────────────┴─────────────────────────────────────────┤
│                     Footer                            │
└──────────────────────────────────────────────────────┘

AuthLayout Structure

┌──────────────────────────────────────────────────────┐
│                                                       │
│                    ┌────────────┐                    │
│                    │            │                    │
│                    │  Auth Form │                    │
│                    │            │                    │
│                    └────────────┘                    │
│                                                       │
└──────────────────────────────────────────────────────┘

Route Configuration Specification

Route Meta Information

ts
interface RouteMeta {
  title: string           // Page title
  icon?: string          // Menu icon
  permission?: string    // Required permission
  hidden?: boolean       // Hidden in menu
  keepAlive?: boolean    // Cache component
  breadcrumb?: boolean   // Show breadcrumb
}

Standard Route Table

PathPagePermission
/dashboardDashboarddashboard:view
/usersUser listusers:list
/users/createCreate userusers:create
/users/:idUser detailusers:view
/users/:id/editEdit userusers:update
/rolesRole listroles:list
/permissionsPermission managementpermissions:list
/settingsSystem settingssettings:view
/profileUser profile- (authenticated)

Environment Variable Specification

Variable Naming Convention

PrefixFrameworkDescription
NEXT_PUBLIC_Next.jsClient-side visible
VITE_Vue/ViteClient-side visible
PUBLIC_SvelteKitClient-side visible
No prefixAllServer-side only

Required Environment Variables

bash
# API Configuration
*_API_BASE_URL=http://localhost:3000/api
*_API_TIMEOUT=30000

# Authentication Configuration
*_AUTH_SECRET=your-secret-key
*_TOKEN_EXPIRES=7d

# Mock Toggle
*_ENABLE_MOCK=true

# Feature Toggles
*_ENABLE_WEBSOCKET=true
*_ENABLE_ANALYTICS=false

Code Organization Principles

1. Feature First

Organize code by feature modules, not by file types:

# Recommended ✅
features/
├── users/
│   ├── components/
│   ├── hooks/
│   ├── services/
│   └── types/

# Avoid ❌
components/
├── UserList.tsx
├── UserForm.tsx
hooks/
├── useUsers.ts
services/
├── userService.ts

2. Proximity Principle

Place component-specific styles, types, and utilities in the component directory:

components/
└── UserCard/
    ├── index.tsx
    ├── UserCard.module.css
    ├── UserCard.types.ts
    └── useUserCard.ts

3. Shared Extraction

Extract code used in multiple places to shared locations:

# Used by 2+ components → Extract to components/shared/
# Used in 3+ places → Extract to lib/ or utils/

4. Specification First

When adding or modifying features, first clarify interfaces, constraints, and directory structure in halolight/docs, then sync to halolight and halolight-vue to avoid implementation divergence.