@qlover/create-app 0.7.14 → 0.7.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/templates/next-app/README.en.md +131 -0
  5. package/dist/templates/next-app/README.md +115 -20
  6. package/dist/templates/next-app/docs/en/api.md +387 -0
  7. package/dist/templates/next-app/docs/en/component.md +544 -0
  8. package/dist/templates/next-app/docs/en/database.md +496 -0
  9. package/dist/templates/next-app/docs/en/development-guide.md +727 -0
  10. package/dist/templates/next-app/docs/en/env.md +563 -0
  11. package/dist/templates/next-app/docs/en/i18n.md +287 -0
  12. package/dist/templates/next-app/docs/en/index.md +166 -0
  13. package/dist/templates/next-app/docs/en/page.md +457 -0
  14. package/dist/templates/next-app/docs/en/project-structure.md +177 -0
  15. package/dist/templates/next-app/docs/en/router.md +427 -0
  16. package/dist/templates/next-app/docs/en/theme.md +532 -0
  17. package/dist/templates/next-app/docs/en/validator.md +478 -0
  18. package/dist/templates/next-app/docs/zh/api.md +387 -0
  19. package/dist/templates/next-app/docs/zh/component.md +544 -0
  20. package/dist/templates/next-app/docs/zh/database.md +496 -0
  21. package/dist/templates/next-app/docs/zh/development-guide.md +727 -0
  22. package/dist/templates/next-app/docs/zh/env.md +563 -0
  23. package/dist/templates/next-app/docs/zh/i18n.md +287 -0
  24. package/dist/templates/next-app/docs/zh/index.md +166 -0
  25. package/dist/templates/next-app/docs/zh/page.md +457 -0
  26. package/dist/templates/next-app/docs/zh/project-structure.md +177 -0
  27. package/dist/templates/next-app/docs/zh/router.md +427 -0
  28. package/dist/templates/next-app/docs/zh/theme.md +532 -0
  29. package/dist/templates/next-app/docs/zh/validator.md +476 -0
  30. package/package.json +1 -1
  31. package/dist/templates/next-app/docs/env.md +0 -94
@@ -0,0 +1,287 @@
1
+ # Internationalization (i18n) Guide
2
+
3
+ This document details the implementation of internationalization in the project, including API error messages, page content, and all text content requiring multi-language support.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Basic Configuration](#basic-configuration)
8
+ - [API Error Message Handling](#api-error-message-handling)
9
+ - [Page Content Internationalization](#page-content-internationalization)
10
+ - [Usage Guidelines](#usage-guidelines)
11
+
12
+ ## Basic Configuration
13
+
14
+ The project uses next-intl for internationalization management, with configuration located in `config/i18n/i18nConfig.ts`:
15
+
16
+ ```typescript
17
+ export const i18nConfig = {
18
+ localeNames: {
19
+ en: 'English',
20
+ zh: '中文'
21
+ },
22
+ fallbackLng: 'en',
23
+ supportedLngs: ['en', 'zh'],
24
+ localeDetection: true
25
+ };
26
+ ```
27
+
28
+ All supported languages are defined in `supportedLngs`, with the default language specified by `fallbackLng`.
29
+
30
+ ## API Error Message Handling
31
+
32
+ The internationalization process for API error messages is as follows:
33
+
34
+ 1. API Response Format:
35
+
36
+ ```typescript
37
+ interface AppApiErrorInterface {
38
+ success: false;
39
+ id: string; // i18n key
40
+ message?: string; // Optional direct display message
41
+ }
42
+ ```
43
+
44
+ 2. Error Handling Process:
45
+ - API requests are processed through `AppApiPlugin`
46
+ - If the response indicates an error, it's converted to `ExecutorError`
47
+ - `DialogErrorPlugin` handles displaying error messages
48
+ - If the error message is in i18n key format (e.g., "namespace_key"), it's translated through the i18n service before display
49
+ - If not in i18n key format, the original message is displayed directly
50
+
51
+ Example:
52
+
53
+ ```typescript
54
+ // API returns error
55
+ {
56
+ success: false,
57
+ id: "error_invalid_password"
58
+ }
59
+
60
+ // DialogErrorPlugin will automatically translate and display the error message in the appropriate language
61
+ ```
62
+
63
+ ## Page Content Internationalization
64
+
65
+ ### PageI18nInterface
66
+
67
+ `PageI18nInterface` is a core interface defining internationalization content and SEO metadata for pages. This interface provides a complete page metadata structure, including basic SEO information, Open Graph, Twitter Card, etc.
68
+
69
+ ```typescript
70
+ interface PageI18nInterface {
71
+ // Basic metadata properties
72
+ title: string; // Page title
73
+ description: string; // Page description
74
+ content: string; // Page content
75
+ keywords: string; // Page keywords
76
+
77
+ // Canonical link
78
+ canonical?: string; // Optional canonical link
79
+
80
+ // Crawler control
81
+ robots?: {
82
+ index?: boolean; // Allow indexing
83
+ follow?: boolean; // Follow links
84
+ noarchive?: boolean; // Allow archiving
85
+ };
86
+
87
+ // Open Graph metadata
88
+ og?: {
89
+ title?: string; // OG title
90
+ description?: string; // OG description
91
+ type?: string; // Content type
92
+ image?: string; // Image URL
93
+ url?: string; // Page URL
94
+ siteName?: string; // Site name
95
+ locale?: string; // Language locale
96
+ };
97
+
98
+ // Twitter Card metadata
99
+ twitter?: {
100
+ card?: 'summary' | 'summary_large_image' | 'app' | 'player'; // Card type
101
+ site?: string; // Twitter site
102
+ creator?: string; // Creator
103
+ title?: string; // Twitter title
104
+ description?: string; // Twitter description
105
+ image?: string; // Twitter image
106
+ };
107
+
108
+ // Additional metadata
109
+ author?: string; // Author
110
+ publishedTime?: string; // Publication time
111
+ modifiedTime?: string; // Modification time
112
+ }
113
+ ```
114
+
115
+ Usage Notes:
116
+
117
+ 1. All string type values can be:
118
+ - i18n key: Will be translated to the current language
119
+ - Direct string: Will be used directly, without translation
120
+ 2. Optional fields (with `?`) indicate metadata that pages may not include
121
+ 3. This interface is typically used for:
122
+ - Defining page SEO information
123
+ - Generating meta tags
124
+ - Providing social media sharing information
125
+ - Controlling search engine crawler behavior
126
+
127
+ ### Using PageI18nInterface in Pages
128
+
129
+ Here's a complete page example showing how to use PageI18nInterface:
130
+
131
+ ```typescript
132
+ // 1. First define the page's i18n interface
133
+ export const homeI18n = Object.freeze({
134
+ title: i18nKeys.PAGE_HOME_TITLE,
135
+ description: i18nKeys.PAGE_HOME_DESCRIPTION,
136
+ content: i18nKeys.PAGE_HOME_DESCRIPTION,
137
+ keywords: i18nKeys.PAGE_HOME_KEYWORDS,
138
+
139
+ welcome: i18nKeys.HOME_WELCOME,
140
+ getStartedTitle: i18nKeys.HOME_GET_STARTED_TITLE,
141
+ getStartedDescription: i18nKeys.HOME_GET_STARTED_DESCRIPTION,
142
+ getStartedButton: i18nKeys.HOME_GET_STARTED_BUTTON
143
+ });
144
+
145
+ // 2. Use in page
146
+ export async function generateMetadata({ params }: { params: PageParamsType }): Promise<Metadata> {
147
+ const pageParams = new PageParams(await params);
148
+ // Get page SEO metadata
149
+ return await pageParams.getI18nInterface(homeI18n);
150
+ }
151
+
152
+ export default async function HomePage({ params }: PageParamsProps) {
153
+ const pageParams = new PageParams(await params!);
154
+ // Get page translation content
155
+ const tt = await pageParams.getI18nInterface(homeI18n);
156
+
157
+ return (
158
+ <BaseLayout>
159
+ <section>
160
+ <h1>{tt.welcome}</h1>
161
+ <p>{tt.description}</p>
162
+ <div>
163
+ <h2>{tt.getStartedTitle}</h2>
164
+ <p>{tt.getStartedDescription}</p>
165
+ <Button>{tt.getStartedButton}</Button>
166
+ </div>
167
+ </section>
168
+ </BaseLayout>
169
+ );
170
+ }
171
+ ```
172
+
173
+ This example demonstrates:
174
+
175
+ 1. How to define page-specific i18n interfaces
176
+ 2. How to use `getI18nInterface` to get translated content
177
+ 3. How to use i18n in page metadata
178
+ 4. How to use translated content in page components
179
+
180
+ ### Implementing Page Internationalization
181
+
182
+ Page content internationalization is primarily implemented through:
183
+
184
+ 1. Page i18n Interface Definition:
185
+
186
+ ```typescript
187
+ // config/i18n/HomeI18n.ts
188
+ export const homeI18n = Object.freeze({
189
+ title: i18nKeys.PAGE_HOME_TITLE,
190
+ description: i18nKeys.PAGE_HOME_DESCRIPTION,
191
+ welcome: i18nKeys.HOME_WELCOME
192
+ // ...
193
+ });
194
+ ```
195
+
196
+ 2. Getting Translated Content:
197
+
198
+ ```typescript
199
+ // In page component
200
+ const messages = await getMessages({ locale });
201
+ // Or using PageParams
202
+ const i18nContent = await pageParams.getI18nInterface(homeI18n);
203
+ ```
204
+
205
+ 3. Language Handling in Dynamic Routes:
206
+
207
+ ```typescript
208
+ // src/app/[locale]/layout.tsx
209
+ export default async function RootLayout({ children, params }) {
210
+ const pageParams = new PageParams(params);
211
+ const locale = pageParams.getI18nWithNotFound();
212
+ // ...
213
+ }
214
+ ```
215
+
216
+ ## Usage Guidelines
217
+
218
+ 1. **All Text Content Must Use i18n Keys**:
219
+ - Don't write fixed text directly in code
220
+ - All text should be defined in i18n configuration files
221
+ - Use meaningful key names, e.g., `PAGE_HOME_TITLE`, `ERROR_INVALID_INPUT`
222
+
223
+ 2. **i18n Key Naming Conventions**:
224
+ - Use uppercase letters and underscores
225
+ - Use meaningful prefixes to indicate categories, such as:
226
+ - `PAGE_` prefix for page-related content
227
+ - `ERROR_` prefix for error messages
228
+ - `COMMON_` prefix for common text
229
+
230
+ 3. **Translation File Organization**:
231
+ - Translation files located in `public/locales/` directory
232
+ - Categorized by language code: `en.json`, `zh.json`
233
+ - Maintain consistent keys across all language files
234
+
235
+ 4. **Type Safety**:
236
+ - Use TypeScript interfaces to define i18n content
237
+ - All i18n keys should be defined in the `config/Identifier/` directory
238
+ - Use `Object.freeze` to ensure i18n objects aren't modified
239
+
240
+ 5. **Best Practices**:
241
+ - Use `PageParams` class for page language-related logic
242
+ - Use `useTranslations` hook in components to get translations
243
+ - Prioritize i18n keys for API error messages over hardcoded messages
244
+ - Ensure all user-visible text supports multiple languages
245
+
246
+ ## Examples
247
+
248
+ 1. Using i18n in Page Components:
249
+
250
+ ```typescript
251
+ export function LoginForm(props: { tt: LoginI18nInterface }) {
252
+ const { tt } = props;
253
+
254
+ return (
255
+ <form>
256
+ <h1>{tt.title}</h1>
257
+ <p>{tt.description}</p>
258
+ {/* ... */}
259
+ </form>
260
+ );
261
+ }
262
+ ```
263
+
264
+ 2. API Error Handling:
265
+
266
+ ```typescript
267
+ // Backend returns error
268
+ throw new AppErrorApi({
269
+ id: 'ERROR_INVALID_CREDENTIALS',
270
+ success: false
271
+ });
272
+
273
+ // Frontend automatically handles and displays translated error message
274
+ ```
275
+
276
+ 3. Dynamic Content:
277
+
278
+ ```typescript
279
+ const t = await getTranslations({
280
+ locale: pageParams.getLocale(),
281
+ namespace: 'common'
282
+ });
283
+
284
+ const message = t('welcome', {
285
+ name: userName
286
+ });
287
+ ```
@@ -0,0 +1,166 @@
1
+ # Next.js Full-Stack Application Documentation
2
+
3
+ ## Introduction
4
+
5
+ This is a full-stack application template based on Next.js, implementing a clear layered architecture using an interface-driven design pattern. This template provides a complete full-stack development solution, including server-side API, client-side state management, authentication and authorization, internationalization, and other core features.
6
+
7
+ ### Key Features
8
+
9
+ - 🏗️ **Full-Stack Architecture**: Based on Next.js app router and API routes
10
+ - 🔌 **Interface-Driven**: Complete interface-oriented programming practice
11
+ - 🎨 **Theme Customization**: Theme system based on Tailwind CSS
12
+ - 🌍 **Internationalization**: Multi-language support based on next-intl
13
+ - 🔄 **Dependency Injection**: TypeScript-based IOC container
14
+ - 🛡️ **Authentication**: Complete authentication and authorization solution
15
+ - 📡 **Layered Design**: Clear front-end and back-end layered architecture
16
+ - 🎮 **State Management**: Controller pattern-based state management
17
+ - 🔗 **Data Access**: Flexible database access layer
18
+
19
+ ## Quick Start
20
+
21
+ ```bash
22
+ # Install dependencies
23
+ pnpm install
24
+
25
+ # Development environment startup
26
+ pnpm dev
27
+ # cross-env APP_ENV=localhost next dev --turbopack --port 3100
28
+ # Automatically loads .env.localhost -> .env
29
+
30
+ # Staging environment startup
31
+ pnpm dev:staging
32
+ # cross-env APP_ENV=staging next dev --turbopack --port 3100
33
+ # Automatically loads .env.staging -> .env
34
+
35
+ # Build production version
36
+ pnpm build
37
+ ```
38
+
39
+ ## Architecture Overview
40
+
41
+ ### 1. Client-Side Architecture
42
+
43
+ #### Interface Definitions (src/base/port)
44
+
45
+ - AppUserApiInterface: User API interface
46
+ - AdminPageInterface: Admin page interface
47
+ - AsyncStateInterface: Asynchronous state interface
48
+ - RouterInterface: Router management interface
49
+
50
+ #### Core Implementation
51
+
52
+ - Controller Layer: State and business logic management
53
+ - Service Layer: API calls and data processing
54
+ - UI Components: Reusable presentation components
55
+
56
+ ### 2. Server-Side Architecture
57
+
58
+ #### Interface Definitions (src/server/port)
59
+
60
+ - ServerAuthInterface: Authentication interface
61
+ - DBBridgeInterface: Database operation interface
62
+ - UserRepositoryInterface: User repository interface
63
+ - ValidatorInterface: Data validation interface
64
+
65
+ #### Core Implementation
66
+
67
+ - API Route Layer: Request handling and response
68
+ - Service Layer: Business logic implementation
69
+ - Data Access Layer: Repository and database interaction
70
+
71
+ ## Development Guide
72
+
73
+ ### 1. API Development Process
74
+
75
+ 1. Define interface (src/server/port)
76
+ 2. Implement validator (src/server/validators)
77
+ 3. Implement service layer (src/server/services)
78
+ 4. Implement data access (src/server/repositorys)
79
+ 5. Create API route (src/app/api)
80
+
81
+ ### 2. Page Development Process
82
+
83
+ 1. Create page component (src/app/[locale])
84
+ 2. Implement page controller
85
+ 3. Add API service
86
+ 4. Register IOC container
87
+
88
+ ### 3. Best Practices
89
+
90
+ #### Interface-First Development
91
+
92
+ - Define interfaces before implementing concrete classes
93
+ - Maintain single responsibility for interfaces
94
+ - Use dependency injection to manage dependencies
95
+
96
+ #### Layering Principles
97
+
98
+ - Maintain clear boundaries between layers
99
+ - Communicate between layers through interfaces
100
+ - Avoid direct cross-layer calls
101
+
102
+ #### State Management
103
+
104
+ - Use controllers to manage complex state
105
+ - Maintain state immutability
106
+ - Unified state update process
107
+
108
+ ## Core Feature Documentation
109
+
110
+ ### Basic Architecture
111
+
112
+ - [Project Structure](./project-structure.md)
113
+ - [Development Guidelines](./development-guide.md)
114
+ - [Environment Configuration](./env.md)
115
+
116
+ ### Server-Side Development
117
+
118
+ - [API Development Guide](./api.md)
119
+ - [Authentication & Authorization](./auth.md)
120
+ - [Data Access Layer](./database.md)
121
+ - [Validator Development](./validator.md)
122
+
123
+ ### Client-Side Development
124
+
125
+ - [Page Development Guide](./page.md)
126
+ - [Component Development](./component.md)
127
+
128
+ ### Feature Modules
129
+
130
+ - [Internationalization Development](./i18n.md)
131
+ - [Theme System](./theme.md)
132
+ - [Router Management](./router.md)
133
+
134
+ ## FAQ
135
+
136
+ ### 1. Development Environment Setup
137
+
138
+ - Node.js >= 16
139
+ - pnpm >= 8.0
140
+ - VSCode + recommended extensions recommended
141
+
142
+ ### 2. Development Related
143
+
144
+ - Interface design specifications
145
+ - Dependency injection usage
146
+ - Controller development guidelines
147
+
148
+ ### 3. Deployment Related
149
+
150
+ - Environment variable configuration
151
+ - Build optimization
152
+ - Deployment process
153
+
154
+ ## Changelog
155
+
156
+ View [CHANGELOG.md](../../CHANGELOG.md) for detailed update history.
157
+
158
+ ## Support and Help
159
+
160
+ - Submit Issues
161
+ - View Wiki
162
+ - Join Discussions
163
+
164
+ ## License
165
+
166
+ This project is open-sourced under the [ISC License](../../LICENSE).