Architecture Diagram
Monorepo Structure
Drift uses Turborepo for efficient monorepo management:Workspace Configuration
The monorepo is managed via npm workspaces:Technology Stack
Frontend (Next.js)
- Framework: Next.js 14 with App Router
- UI Library: React 18 with TypeScript
- Styling: Tailwind CSS + shadcn/ui components
- 3D Graphics: Three.js + React Three Fiber
- Charts: Recharts for data visualization
- State Management: TanStack Query for server state
- API Client: Axios
Backend (Express)
- Runtime: Node.js with TypeScript
- Framework: Express.js
- Validation: Zod schemas
- Development: tsx watch for hot reload
- Testing: Jest + ts-jest
Simulation Engine (Python)
- Language: Python 3.10+
- Numeric Computing: NumPy for vectorized operations
- Validation: Pydantic v2 for type safety
- Parallelization: multiprocessing with worker pools
- AI Integration: OpenAI for goal parsing
Key Components
1. Frontend Layer
The Next.js frontend provides:- Interactive UI for financial goal input
- Real-time Monte Carlo visualization with Three.js particles
- Recharts-based result dashboards
- Plaid Link integration for bank connectivity
- Voice input via ElevenLabs
2. API Layer
The Express API orchestrates:- Simulation Routes: Trigger Python Monte Carlo engine
- Financial Data: Aggregate Plaid/Nessie account data
- AI Services: Goal parsing with Gemini, voice with ElevenLabs
- HPC Integration: Cluster job submission for large simulations
- What-If Analysis: Sensitivity testing
3. Simulation Engine
The Python engine performs:- Monte Carlo Simulations: 100k+ scenarios with NumPy vectorization
- Multiprocessing: Parallel execution across CPU cores
- Account-Aware Modeling: Per-card credit interest, loan amortization
- Dynamic Parameters: Derived from real Plaid account data
- Sensitivity Analysis: Test impact of income/spending/timeline changes
Data Flow
Simulation Request Flow
Development Workflow
Local Development
Start all services concurrently:apps/webon http://localhost:3000apps/apion http://localhost:3001
Turborepo Task Pipeline
Defined inturbo.json:
Turborepo caches build outputs for faster incremental builds across the monorepo.
Deployment Architecture
Production Setup
- Frontend: Deployed to Vercel with edge caching
- API: Node.js server on cloud provider (AWS/GCP/Render)
- Python Engine: Co-located with API or separate compute cluster
- Database: Not currently used (stateless simulations)
Environment Variables
Required configuration:Security Considerations
API Security
- CORS: Configured to allow frontend origin only
- Rate Limiting: Should be implemented for production
- Input Validation: Zod schemas validate all API inputs
- Plaid Access Tokens: Stored in memory, not persisted
Data Privacy
- No Database: Simulations are stateless, no user data stored
- Plaid Integration: Uses OAuth for secure bank linking
- Financial Data: Processed in-memory, not logged
Performance Characteristics
Simulation Performance
- 100k simulations: ~2-5 seconds (4 workers)
- Vectorization: NumPy operations ~100x faster than Python loops
- Parallelization: Linear scaling up to CPU core count
- Memory: ~200MB for 100k simulations
Frontend Performance
- Initial Load: Next.js SSR for fast First Contentful Paint
- Particle Animation: 60 FPS canvas rendering (150 particles)
- Code Splitting: Automatic route-based chunking
Next Steps
Explore the detailed architecture of each layer:Frontend Architecture
Next.js app structure, components, and Three.js visualization
Backend Architecture
Express API routes, services, and integration layer
Simulation Engine
Python Monte Carlo engine internals and algorithms