Skip to main content

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

  1. Use caching — Redis for frequent queries
  2. Optimize queries — Avoid N+1 problems
  3. Lazy loading — Load data when needed
  4. Pagination — Limit result sets

Security

  1. Validate input — Use Pydantic models
  2. Sanitize output — Prevent XSS
  3. Use HTTPS — Encrypt in transit
  4. Audit logging — Track sensitive operations

Testing

  1. Unit tests — Test individual functions
  2. Integration tests — Test API endpoints
  3. E2E tests — Test user flows
  4. Coverage — Aim for 80%+

Documentation

  1. Code comments — Explain why, not what
  2. API docs — Keep GraphQL schema documented
  3. README — Update for new features
  4. Changelog — Track changes