| name | frontend/technical-spec |
| description | Frontend technical design rules including environment variables, architecture design, data flow, Nx workspace conventions, and build/testing commands. |
Technical Design Rules (Frontend)
Basic Technology Stack Policy
The frontend lives inside the Nx workspace and is orchestrated through nx. The primary customer-facing application is the Next.js project at apps/app, with shared UI primitives located in libs/frontend/*. Use Nx generators and project boundaries to keep the architecture consistent. TypeScript-based React application implementation. Architecture patterns should be selected according to project requirements and scale.
Environment Variable Management and Security
Environment Variable Management
- Use build tool's environment variable system:
process.env does not work in browser environments
- Centrally manage environment variables through configuration layer
- Implement proper type safety with TypeScript
- Properly implement default value settings and mandatory checks
const config = {
apiUrl: import.meta.env.API_URL || 'http://localhost:3000',
appName: import.meta.env.APP_NAME || 'My App',
};
const apiUrl = process.env.API_URL;
Security (Client-side Constraints)
- CRITICAL: All frontend code is public and visible in browser
- Never store secrets client-side: No API keys, tokens, or secrets in environment variables
- Do not include
.env files in Git (same as backend)
- Prohibit logging of sensitive information (passwords, tokens, personal data)
- Do not include sensitive information in error messages
Correct Approach for Secrets:
const apiKey = import.meta.env.API_KEY;
const response = await fetch(`https://api.example.com/data?key=${apiKey}`);
const response = await fetch('/api/data');
Architecture Design
Nx Workspace Conventions
- Project placement: UI features that ship to production belong in
apps/app. Reusable view logic or utilities must live under the appropriate libs/frontend/... subdirectory (components, hooks, lib, shared-ui, story-editor).
- Generators first: Scaffold new libraries or components with Nx generators (
nx g @nx/next:component, nx g @nx/react:library) to inherit workspace standards (naming, testing, linting).
- Enforce boundaries: Respect module boundary rules defined for frontend tags (
scope:frontend, type:ui, etc.). Add dependency tags before importing across feature areas.
- Project graph awareness: Use
nx graph when designing features to understand the dependency impact and to avoid unintended cross-package coupling.
Frontend Architecture Patterns
Strictly adhere to selected project patterns. Project-specific details reference docs/rules/architecture/.
React Component Architecture:
- Function Components: Mandatory, class components deprecated
- Custom Hooks: For logic reuse and dependency injection
- Component Hierarchy: Atoms -> Molecules -> Organisms -> Templates -> Pages
- Props-driven: Components receive all necessary data via props
- Co-location: Place tests, styles, and related files alongside components
State Management Patterns:
- Local State:
useState for component-specific state
- Context API: For sharing state across component tree (theme, auth, etc.)
- Custom Hooks: Encapsulate state logic and side effects
- Server State: React Query or SWR for API data caching
Unified Data Flow Principles
Client-side Data Flow
Maintain consistent data flow throughout the React application:
-
Single Source of Truth: Each piece of state has one authoritative source
- UI state: Component state or Context
- Server data: API responses cached in React Query/SWR
- Form data: Controlled components with React Hook Form
-
Unidirectional Flow: Data flows top-down via props
API Response -> State -> Props -> Render -> UI
User Input -> Event Handler -> State Update -> Re-render
-
Immutable Updates: Use immutable patterns for state updates
setUsers((prev) => [...prev, newUser]);
users.push(newUser);
setUsers(users);
Type Safety in Data Flow
- Frontend -> Backend: Props/State (Type Guaranteed) -> API Request (Serialization)
- Backend -> Frontend: API Response (
unknown) -> Type Guard -> State (Type Guaranteed)
async function fetchUser(id: string): Promise<User> {
const response = await fetch(`/api/users/${id}`);
const data: unknown = await response.json();
if (!isUser(data)) {
throw new Error('Invalid user data');
}
return data;
}
Build and Testing
Build Commands
nx dev app
nx build app
nx start app
nx run-many -t typecheck --projects components,hooks,lib,shared-ui,story-editor
Testing Commands
Frontend tests run with Jest through Nx-managed targets.
nx test app
nx run-many -t test --projects tag:scope:frontend
nx run-many -t test --projects tag:scope:frontend -- --coverage
nx test components --watch
Quality Check Requirements
Quality checks are mandatory upon implementation completion:
Phase 1-3: Basic Checks
nx run-many -t lint --projects app,tag:scope:frontend
nx run-many -t typecheck --projects tag:scope:frontend
nx build app
Phase 4-5: Tests and Final Confirmation
nx test app
nx run-many -t test --projects tag:scope:frontend --skip-nx-cache -- --coverage --runInBand
nx run-many -t lint --projects app,tag:scope:frontend --skip-nx-cache
nx run-many -t typecheck --projects tag:scope:frontend --skip-nx-cache
Coverage Requirements
- Mandatory: Unit test coverage must be 60% or higher
- Component-specific targets:
- Atoms: 70% or higher
- Molecules: 65% or higher
- Organisms: 60% or higher
- Custom Hooks: 65% or higher
- Utils: 70% or higher
Non-functional Requirements
- Browser Compatibility: Chrome/Firefox/Safari/Edge (latest 2 versions)
- Rendering Time: Within 5 seconds for major pages