System Architecture
Chronos Calendar is a modern full-stack SaaS application built with a React frontend and FastAPI backend, leveraging Supabase for authentication and database, with Google Calendar integration for real-time synchronization.Frontend
React 18 with Zustand state management and IndexedDB for offline-first experience
Backend
FastAPI REST API with Supabase PostgreSQL and Google Calendar OAuth integration
Security
Multi-layered security with encryption, CSRF protection, and secure session management
Real-time Sync
Bidirectional sync between local IndexedDB and Google Calendar via webhooks
Architecture Diagram
Core Technology Stack
- Frontend
- Backend
- Infrastructure
- Framework: React 18.3.1 with TypeScript
- State Management: Zustand 5.0.9
- Server State: TanStack Query 5.90
- Local Database: Dexie.js 4.2.1 (IndexedDB wrapper)
- UI Components: Radix UI primitives
- Styling: Tailwind CSS 4.1
- Date Handling: date-fns 4.1.0 + rrule 2.8.1
- Build Tool: Vite 5.4
Design Principles
1. Offline-First Architecture
Chronos Calendar uses an offline-first approach where all calendar data is stored locally in IndexedDB. This provides:- Instant UI responsiveness
- Offline functionality
- Reduced API calls
- Better user experience with optimistic updates
The app syncs with Google Calendar in the background, ensuring data consistency while maintaining fast local operations.
2. Security by Design
Multiple layers of security protect user data:- End-to-end encryption for sensitive calendar fields
- CSRF token validation on all mutating requests
- Origin validation and Fetch Metadata Policy
- Rate limiting on authentication endpoints
- Secure session management with HTTP-only cookies
3. Real-time Synchronization
Bidirectional sync keeps data consistent across devices:- Client → Server: Local changes pushed via REST API
- Server → Client: Google Calendar webhooks notify of external changes
- Conflict Resolution: Last-write-wins based on
updatedtimestamp
Webhooks are registered per calendar and automatically renewed before expiration.
4. Scalable State Management
State is organized into specialized Zustand stores:- Calendar Store: View state, navigation, selected events
- Accounts Store: Google account management
- Sync Store: Synchronization status tracking
- Todo Store: Task list selection and editing
Data Flow
Event Synchronization Flow
Webhook Update Flow
API Structure
The backend exposes three main router modules:/auth
OAuth flow, session management, CSRF tokens
/calendar
Events, calendars, accounts, webhooks, sync
/todos
Todo lists and items management
Key Endpoints
GET /health- Health checkPOST /auth/web/login- Initiate OAuth flowGET /auth/web/callback- OAuth callbackPOST /auth/logout- Clear sessionGET /calendar/events- Fetch events with sync tokenPOST /calendar/events- Create eventPUT /calendar/events/{id}- Update eventDELETE /calendar/events/{id}- Delete eventPOST /calendar/webhook- Google Calendar webhook receiver
Performance Optimizations
Frontend
- Virtual scrolling for large event lists (TanStack Virtual)
- Lazy loading components with React.lazy
- Debounced search and input handlers
- Memoized selectors in Zustand stores
- Query caching with TanStack Query
Backend
- GZIP compression for responses >1KB
- Batch encryption/decryption for multiple fields
- Connection pooling via HTTPX async client
- Indexed database queries on Supabase
- Rate limiting to prevent abuse
Deployment Architecture
- Web Application
- Desktop Application
- Frontend built with Vite and deployed as static assets
- Backend deployed as FastAPI application with Uvicorn
- Environment-specific configuration via
.envfiles - CORS configured for production domains
- HTTPS enforced in production
Configuration Management
All sensitive configuration is managed through environment variables:COOKIE_SECURE=true in production).
Next Steps
Frontend Architecture
Deep dive into React components, state management, and IndexedDB
Backend Architecture
Explore FastAPI routers, Supabase integration, and Google Calendar sync
Security Features
Learn about encryption, CSRF protection, and session management