Best Practices¶
Recommended patterns and practices for fastappkit projects.
Project Organization¶
App Design¶
- One app per feature/domain
- Keep apps focused on a single responsibility
- Group related functionality together
-
Use clear, descriptive names
-
Clear boundaries
- Keep app boundaries clear
- Minimize cross-app dependencies
-
Use internal apps for tightly coupled features
-
External apps for reusability
- Design external apps to be reusable
- Keep dependencies minimal
- Document requirements clearly
Migration Strategies¶
Internal Apps¶
- Keep migrations focused
- One migration per logical change
- Clear migration messages
-
Review migrations before applying
-
Use migration order when needed
- Only if internal apps have dependencies
-
Document dependencies clearly
-
Test migrations
- Test upgrades in development
- Test downgrades to ensure reversibility
- Review SQL with
fastappkit migrate preview
External Apps¶
- Version migrations
- Include migrations in package
- Version migrations with app version
-
Document migration requirements
-
Test independently
- Test migrations in external app project
- Test integration with core project
- Ensure compatibility
Settings Management¶
- Use environment variables
- Never hardcode sensitive values
- Use
.envfor development -
Use environment variables in production
-
Validate settings
- Use Pydantic validators
- Provide clear error messages
-
Set appropriate defaults
-
Document custom settings
- Document all custom settings
- Explain purpose and usage
- Provide examples
Testing Strategies¶
- Test apps independently
- Test external apps in isolation
- Test internal apps with core
-
Test integration
-
Use validation
- Run
fastappkit app validateregularly - Fix validation errors immediately
-
Review warnings
-
Test migrations
- Test upgrades and downgrades
- Test in development first
- Backup before production migrations
Performance Considerations¶
- Lazy loading
- Apps are loaded on startup
- Minimize startup overhead
-
Use async where appropriate
-
Database connections
- Use connection pooling
- Configure appropriately for your database
-
Monitor connection usage
-
Route organization
- Keep routes organized
- Use appropriate prefixes
- Avoid deep nesting
Security¶
- Settings security
- Never commit
.envfiles - Use secure secret management
-
Rotate secrets regularly
-
Dependency management
- Update dependency versions regularly
- Pin versions for production
-
Review security advisories
-
Input validation
- Validate all inputs
- Use Pydantic models
- Sanitize user input
Learn More¶
- Architecture - Internal architecture
- Extending FastAppKit - Customization guide