diff --git a/apps/engineering/content/docs/contributing/client-structure.mdx b/apps/engineering/content/docs/contributing/client-structure.mdx new file mode 100644 index 000000000..e976f286b --- /dev/null +++ b/apps/engineering/content/docs/contributing/client-structure.mdx @@ -0,0 +1,151 @@ +--- +title: Client-Side Structure +description: How to structure your PR when contributing to Unkey dashboard +--- + +# Client-Side Structure Contribution Guidelines + +## Overview + +When contributing to the Unkey dashboard or any client app in the Unkey repository, we follow a feature-based architecture. This guide will help you understand how to structure your code to maintain consistency across the project. + +## Directory Structure + +Each feature (typically corresponding to a Next.js page) should be organized as a self-contained module with the following structure: + +``` +feature-name/ +├── components/ # Feature-specific React components +│ ├── component-name/ # Complex components get their own directory +│ │ ├── index.tsx +│ │ └── sub-component.tsx +│ └── simple-component.tsx +├── hooks/ # Custom hooks for the feature +│ ├── queries/ # API query hooks +│ │ ├── use-feature-list.ts +│ │ └── use-feature-details.ts +│ └── use-feature-logic.ts +├── actions/ # Server actions and API calls +│ └── feature-actions.ts +├── types/ # TypeScript types and interfaces +│ └── feature.ts +├── schemas/ # Validation schemas +│ └── feature.ts +├── utils/ # Helper functions +│ └── feature-helpers.ts +├── constants.ts # Feature-specific constants +└── page.tsx # Main page component +``` + +## Key Principles + +1. **Feature Isolation** + + - Keep all related code within the feature directory + - Don't import feature-specific components into other features + - Use shared components from the global `/components` directory or `unkey/ui` package for common UI elements + +2. **Component Organization** + + - Simple components can be single files **(No need to break everything into 50 different files, follow your common sense)** + - Complex components should have their own directory with an index.tsx + - Keep component-specific styles, tests, and utilities close to the component + +3. **Code Colocation** + - Place related code as close as possible to where it's used + - If a utility is only used by one component, keep it in the component's directory + +## Example Page Structure + +Here's an example of how to structure a typical page component: + +```typescript +import { Navbar } from "@/components/navbar"; // Global shared component +import { PageContent } from "@/components/page-content"; +import { FeatureComponent } from "./components/feature-component"; + +export default function FeaturePage() { + // Page implementation + // This is also we where we do our server side data fetching. + return ( +