Syntropy Health - Development Best Practices
Overview
Syntropy Health is a healthtech application that manages sensitive health data. As such, it requires strict adherence to software development best practices to ensure reliability, security, and maintainability.Architecture Principles
1. Type Safety
All data structures use strict typing:- TypedDict schemas for state management (not DB models)
- Pydantic models for API validation
- SQLModel for database models with proper relationships
2. Schema Separation
- DB models have relationships that can’t serialize to Reflex state
- TypedDicts provide type hints for
rx.foreachand other Reflex components - Keeps concerns separated (persistence vs presentation)
3. Reflex-Specific Patterns
rx.foreach Type Safety
Reflex’srx.foreach requires explicit type casting:
State Management
- Use
@rx.varfor computed properties - Use
@rx.eventfor state mutations - Use
@rx.event(background=True)for async DB operations - Always use
async with self:when updating state in background events
Testing Strategy
Unit Tests
Located intests/unit/:
- Schema validation tests
- State logic tests
- Utility function tests
Integration Tests
Located intests/integration/:
- Database seeding tests
- API endpoint tests
- State + DB interaction tests
Running Tests
Code Quality
Linting & Formatting
Pre-commit Checks
Before committing:uv run reflex run- Verify app compilesuv run pytest- Run test suiteuv run ruff check syntropy_journals/app/- Lint check
Security Considerations
HealthTech Compliance
- Data Encryption: All health data encrypted at rest and in transit
- Authentication: Clerk-based auth with session management
- Audit Logging: All data access logged for compliance
- Input Validation: Strict schema validation on all inputs
Environment Variables
Never commit secrets. Required env vars:REFLEX_DB_URL- Database connection stringCLERK_SECRET_KEY- AuthenticationOPENAI_API_KEY- AI features (if applicable)
Deployment
Railway Deployment
Health Checks
- Backend:
GET /health - Frontend: Reflex handles automatically
Completed Optimizations
2026-02-02: Chat Schema Refactoring
Problem:rx.foreach failed with nested TypedDict access
- Flattened
ChatMessageDictschema (removed nestedmessagefield) - State converts DB models to flat dicts in
current_chat_messages - Added
.to(list[ChatMessageDict])cast in foreach
syntropy_journals/app/models/syntropy/schemas/chat.py- Flattened schemasyntropy_journals/app/states/chat/chat.py- Flatten in state varsyntropy_journals/app/components/chat/message_bubble.py- Direct accesssyntropy_journals/app/components/chat/interface.py- Type cast
Deprecation Warnings to Address
| Warning | Location | Fix |
|---|---|---|
check_circle icon invalid | Multiple files | Use circle-check |
codeblock deprecated | landing/message_bubble.py | Use pre |
RouterData.page deprecated | navbar.py, sidebar.py | Use RouterData.url |
rx.Base deprecated | External package | Update reflex_audio_capture |