Skip to content

Commit 8e2b3d5

Browse files
authored
Merge pull request #320 from deploystackio/feat/html-serializer
docs: update API documentation with troubleshooting and configuration…
2 parents e39803a + 59ead6c commit 8e2b3d5

File tree

5 files changed

+369
-70
lines changed

5 files changed

+369
-70
lines changed

development/backend/api/index.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -968,17 +968,17 @@ await server.register(fastifySwagger, {
968968
});
969969
```
970970

971-
## Troubleshooting
971+
### Common Configuration Issues
972972

973-
### "Route already declared" Error
973+
#### "Route already declared" Error
974974

975975
This happens when trying to manually add routes that Swagger UI already provides. The `/documentation/json` and `/documentation/yaml` endpoints are automatically created.
976976

977-
### "Failed to fetch API spec" Error
977+
#### "Failed to fetch API spec" Error
978978

979979
Ensure the server is fully started before trying to fetch the specification. The generation script includes a 2-second delay to allow for complete initialization.
980980

981-
### Missing Route Documentation
981+
#### Missing Route Documentation
982982

983983
Routes without schema definitions will appear in the specification but with minimal documentation. Add schema objects to routes for complete documentation.
984984

development/backend/api/pagination.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ export function usePagination<T>(
508508
}
509509
```
510510

511-
## Best Practices
511+
## Implementation Guidelines
512512

513513
### 1. Consistent Parameter Validation
514514

development/backend/global-settings.mdx

Lines changed: 64 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ DEPLOYSTACK_ENCRYPTION_SECRET=your-very-secure-32-character-secret-key-here
7777

7878
**Important**: Use a strong, unique secret in production. This key is used to derive the encryption key for all sensitive settings.
7979

80+
### Security Guidelines
81+
82+
Follow these guidelines when working with sensitive settings:
83+
84+
- **Always encrypt sensitive data**: Passwords, API keys, tokens, and secrets must be encrypted
85+
- **Use descriptive descriptions**: Help administrators understand what each setting does and why it's sensitive
86+
- **Group sensitive settings**: Keep all sensitive settings for a service in the same group for easier management
87+
- **Regular audits**: Review settings periodically for unused or outdated values
88+
- **Environment separation**: Use different encryption secrets for different environments (development, staging, production)
89+
8090
## Database Schema
8191

8292
```sql
@@ -103,6 +113,18 @@ CREATE TABLE globalSettings (
103113
);
104114
```
105115

116+
## Naming Conventions
117+
118+
When creating global settings, follow these conventions for consistency:
119+
120+
- **Dot notation for hierarchy**: Use `category.subcategory.setting` structure (e.g., `smtp.host`, `api.openai.key`)
121+
- **Lowercase with underscores**: Use lowercase letters with underscores for readability (e.g., `smtp.max_retry_count`)
122+
- **Be descriptive but concise**: Use clear names without redundancy (e.g., `api.openai.key` not `api.openai.api_key`)
123+
- **Group related settings**: Keep related configuration together (e.g., `database.host`, `database.port`, `database.name`)
124+
- **Hierarchical keys within groups**: Use dot notation for subcategories (e.g., `group.subcategory.setting`)
125+
- **Keep all related settings in the same group**: Maintain group consistency for better organization
126+
- **Provide clear descriptions**: Help administrators understand the purpose of each setting
127+
106128
## API Endpoints
107129

108130
### Authentication
@@ -580,6 +602,23 @@ const apiSettings = await GlobalSettingsService.getByGroup('api-keys');
580602
const openaiKey = apiSettings.find(s => s.key === 'api.openai.key')?.value;
581603
```
582604

605+
### Error Handling
606+
607+
When working with global settings, implement proper error handling:
608+
609+
```typescript
610+
try {
611+
const setting = await GlobalSettingsService.get('api.openai.key');
612+
if (!setting) {
613+
throw new Error('OpenAI API key not configured');
614+
}
615+
// Use the setting
616+
} catch (error) {
617+
logger.error('Failed to retrieve setting:', error);
618+
// Handle the error appropriately
619+
}
620+
```
621+
583622
## Auto-Initialization System
584623

585624
### Overview
@@ -693,35 +732,29 @@ When the server starts:
693732

694733
#### SMTP Settings (Group ID: `smtp`)
695734

696-
| Key | Default | Required | Encrypted | Description |
697-
|-----|---------|----------|-----------|-------------|
698-
| `smtp.host` | `''` ||| SMTP server hostname |
699-
| `smtp.port` | `'587'` ||| SMTP server port |
700-
| `smtp.username` | `''` ||| SMTP authentication username |
701-
| `smtp.password` | `''` ||| SMTP authentication password |
702-
| `smtp.secure` | `'true'` ||| Use SSL/TLS connection |
703-
| `smtp.from_name` | `'DeployStack'` ||| Default sender name |
704-
| `smtp.from_email` | `''` ||| Default sender email |
735+
**Source**: [services/backend/src/global-settings/smtp.ts](https://github.com/deploystackio/deploystack/blob/main/services/backend/src/global-settings/smtp.ts)
736+
737+
Email server configuration for sending notifications and system emails. Includes SMTP host, port, authentication credentials (encrypted password), SSL/TLS settings, and default sender information.
705738

706739
#### GitHub OAuth Settings (Group ID: `github-oauth`)
707740

708-
| Key | Default | Required | Encrypted | Description |
709-
|-----|---------|----------|-----------|-------------|
710-
| `github.oauth.client_id` | `''` ||| GitHub OAuth client ID |
711-
| `github.oauth.client_secret` | `''` ||| GitHub OAuth client secret |
712-
| `github.oauth.enabled` | `'false'` ||| Enable GitHub OAuth |
713-
| `github.oauth.callback_url` | `'http://localhost:3000/api/auth/github/callback'` ||| OAuth callback URL |
714-
| `github.oauth.scope` | `'user:email'` ||| OAuth requested scopes |
741+
**Source**: [services/backend/src/global-settings/github-oauth.ts](https://github.com/deploystackio/deploystack/blob/main/services/backend/src/global-settings/github-oauth.ts)
742+
743+
GitHub OAuth application credentials for user authentication. Includes client ID, client secret (encrypted), enabled flag, callback URL, and requested OAuth scopes.
715744

716745
#### Global Settings (Group ID: `global`)
717746

718-
| Key | Default | Required | Encrypted | Description |
719-
|-----|---------|----------|-----------|-------------|
720-
| `global.page_url` | `'http://localhost:5173'` ||| Base URL for the application frontend |
721-
| `global.send_mail` | `'false'` ||| Enable or disable email sending functionality |
722-
| `global.enable_login` | `'true'` ||| Enable or disable all login functionality |
723-
| `global.enable_email_registration` | `'true'` ||| Enable or disable email registration |
724-
| `global.enable_swagger_docs` | `'true'` ||| Enable or disable Swagger API documentation endpoint (/documentation) |
747+
**Source**: [services/backend/src/global-settings/global.ts](https://github.com/deploystackio/deploystack/blob/main/services/backend/src/global-settings/global.ts)
748+
749+
Application-wide configuration settings. Controls frontend URL, email functionality toggle, login/registration enablement, and API documentation visibility.
750+
751+
#### User Display Settings (Group ID: `user-display`)
752+
753+
**Source**: [services/backend/src/global-settings/user-display.ts](https://github.com/deploystackio/deploystack/blob/main/services/backend/src/global-settings/user-display.ts)
754+
755+
Controls UI element visibility for users across the application. Manages header buttons like Discord community link and feedback form.
756+
757+
**Special behavior**: These settings are automatically included in the `/api/users/me` endpoint response, making them immediately available to the frontend without additional API calls.
725758

726759
### Helper Methods
727760

@@ -874,37 +907,18 @@ const maintenanceMode = (await GlobalSettingsService.get('system.maintenance_mod
874907
const maxUploadSize = parseInt((await GlobalSettingsService.get('system.max_upload_size'))?.value || '5242880');
875908
```
876909

877-
## Best Practices
910+
## Group Design Guidelines
878911

879-
### Key Naming Conventions
912+
When designing setting groups for your application, follow these guidelines:
880913

881-
- Use dot notation for hierarchy: `category.subcategory.setting`
882-
- Use lowercase with underscores for readability: `smtp.max_retry_count`
883-
- Be descriptive but concise: `api.openai.key` not `api.openai.api_key`
884-
- Group related settings: `database.host`, `database.port`, `database.name`
914+
- **Logical grouping**: Group related settings together (e.g., all SMTP settings in one group)
915+
- **Clear names**: Use descriptive group names that are clear for frontend display
916+
- **Consistent icons**: Use consistent iconography across groups for better UX
917+
- **Proper ordering**: Set `sort_order` values to control tab display sequence in the frontend
885918

886-
### Group Design
919+
## Performance Considerations
887920

888-
- **Logical Grouping**: Group related settings together (e.g., all SMTP settings)
889-
- **Clear Names**: Use descriptive group names for frontend display
890-
- **Consistent Icons**: Use consistent iconography across groups
891-
- **Proper Ordering**: Set sort_order to control tab display sequence
892-
893-
### Setting Organization
894-
895-
- **Hierarchical Keys**: Use dot notation within groups: `group.subcategory.setting`
896-
- **Group Consistency**: Keep all related settings in the same group
897-
- **Clear Descriptions**: Provide helpful descriptions for administrators
898-
899-
### Security Guidelines
900-
901-
- **Always encrypt sensitive data**: Passwords, API keys, tokens, secrets
902-
- **Use descriptive descriptions**: Help other administrators understand the purpose
903-
- **Group sensitive settings**: Keep all sensitive settings for a service in one group
904-
- **Regular audits**: Review settings periodically for unused or outdated values
905-
- **Environment separation**: Use different encryption secrets for different environments
906-
907-
### Performance: In-Memory Cache
921+
### In-Memory Cache
908922

909923
The global settings system uses an **in-memory cache** to eliminate database queries for read operations. This is critical for high-frequency endpoints like health checks (`/`) and Swagger documentation (`/documentation`).
910924

@@ -969,21 +983,6 @@ if (GlobalSettingsCache.isInitialized()) {
969983
- **Batch operations**: Use bulk endpoints when creating multiple related settings
970984
- **Group retrieval**: Use `getGroupValues()` to fetch all settings in a group at once
971985

972-
### Error Handling
973-
974-
```typescript
975-
try {
976-
const setting = await GlobalSettingsService.get('api.openai.key');
977-
if (!setting) {
978-
throw new Error('OpenAI API key not configured');
979-
}
980-
// Use the setting
981-
} catch (error) {
982-
logger.error('Failed to retrieve setting:', error);
983-
// Handle the error appropriately
984-
}
985-
```
986-
987986
## Migration and Setup
988987

989988
### Initial Setup

0 commit comments

Comments
 (0)