Development Best Practices
Guidelines for LusterCMS development.
Code Style
Python
- Follow PEP 8
- Use type hints
- Document functions with docstrings
- Keep functions small and focused
def get_entry(entry_id: str, db: Session) -> Entry | None:
"""
Retrieve an entry by ID.
Args:
entry_id: The entry UUID
db: Database session
Returns:
Entry if found, None otherwise
"""
return db.query(Entry).filter(Entry.id == entry_id).first()
TypeScript
- Use strict mode
- Prefer interfaces over types
- Document complex functions
- Use meaningful variable names
interface Entry {
id: string;
title: string;
content: string;
}
const getEntry = async (id: string): Promise<Entry | null> => {
// Implementation
};
Architecture
Separation of Concerns
routes.py → HTTP handling
services.py → Business logic
models.py → Data models
resolvers.py → GraphQL layer
Error Handling
from fastapi import HTTPException
def get_entry(entry_id: str):
entry = db.query(Entry).get(entry_id)
if not entry:
raise HTTPException(status_code=404, detail="Entry not found")
return entry
Performance
- Use caching — Redis for frequent queries
- Optimize queries — Avoid N+1 problems
- Lazy loading — Load data when needed
- Pagination — Limit result sets
Security
- Validate input — Use Pydantic models
- Sanitize output — Prevent XSS
- Use HTTPS — Encrypt in transit
- Audit logging — Track sensitive operations
Testing
- Unit tests — Test individual functions
- Integration tests — Test API endpoints
- E2E tests — Test user flows
- Coverage — Aim for 80%+
Documentation
- Code comments — Explain why, not what
- API docs — Keep GraphQL schema documented
- README — Update for new features
- Changelog — Track changes