-
Notifications
You must be signed in to change notification settings - Fork 2
Plan Phase 1
Durva Dongre edited this page Jun 4, 2025
·
1 revision
Hereโs the revised technical blueprint with all planned APIs, including the new Supabase chat storage module, while maintaining the original structureโs rigor:
flowchart TD
A[User Query] --> B[Query Analysis]
B --> C[Data Assembly]
C --> D[Insights Generation]
D --> E[Tagged Response]
E --> F[UI Rendering]
E --> G[Encrypted Chat Storage - New]
subgraph Backend
B -->|Groq| H[Initial Intent Analysis]
C --> I[Market Data]
C --> J[Portfolio]
C --> K[Risk Engine]
D -->|Groq| L[Contextual Insights]
G -->|Supabase| M[Chat History DB - New]
end
| Component | API Path | Method | Key Parameters | Output Tags |
|---|---|---|---|---|
| Query Analyzer | /api/query |
POST | query: string |
components[], tags[]
|
| Data Assembler | /api/assemble |
POST | {components[], tags[]} |
Raw component responses |
| Insights Generator | /api/insights |
POST | {query, raw_responses[]} |
Enhanced tagged response |
| Market Data | /api/market-data |
GET |
symbols[], fields[]
|
/price, /depth, /vwap
|
| Portfolio | /api/portfolio |
GET | `segment=equity | futures` |
| Stock Screener | /api/stock-screener |
POST | {filters: {pe_max: 20}} |
/screener-result |
| Technical Analysis | /api/technical-analysis |
GET |
symbol, interval, study
|
/candlestick, /macd
|
| Fundamental Analysis | /api/fundamental-analysis |
GET |
symbol, data_type=ratios
|
/pe-ratio, /roe
|
| Risk Metrics | /api/risk-metrics |
GET |
timeframe, model=historical
|
/var, /max-drawdown
|
| Tax Engine | /api/tax-engine |
POST | {trades[], fy=2024} |
/stcg, /ltcg
|
| Chat Storage ๐ | /api/chat-storage |
POST | {session_id, messages[]} |
stored_at (timestamp) |
| Service | Location | Purpose |
|---|---|---|
| Kite Client | /lib/clients/kite.ts |
Zerodha API wrapper with OAuth 2.0 |
| Supabase Client ๐ | /lib/clients/supabase.ts |
Encrypted chat history storage (AES-256) |
| Groq Client | /lib/clients/groq.ts |
Optimized LLM query handler |
| Crypto Utils ๐ | /lib/utils/crypto.ts |
Handles message encryption/decryption |
app/
โโโ api/
โ โโโ query/route.ts # Initial intent analysis
โ โโโ assemble/route.ts # Data orchestration
โ โโโ insights/route.ts # Post-analysis
โ โโโ components/
โ โ โโโ market-data/route.ts # Real-time prices/depth
โ โ โโโ portfolio/route.ts # Holdings/positions
โ โ โโโ stock-screener/route.ts # Watchlist/filters
โ โ โโโ technical-analysis/route.ts # Charts/indicators
โ โ โโโ fundamental-analysis/route.ts # Financials
โ โ โโโ risk-metrics/route.ts # VaR/Sharpe
โ โ โโโ tax-engine/route.ts # Capital gains
โ โ โโโ chat-storage/route.ts ๐ # Encrypted chat history
โ โโโ lib/
โ โโโ clients/
โ โ โโโ kite.ts
โ โ โโโ groq.ts
โ โ โโโ supabase.ts ๐
โ โโโ utils/
โ โโโ crypto.ts ๐ # Encryption helpers
โ โโโ tags.ts
โ โโโ formatters.ts
โโโ components/
โโโ chat/
โโโ Chat.tsx
โโโ widgets/
โโโ PriceTile.tsx
โโโ RiskGauge.tsx
โโโ TextBubble.tsx
CREATE TABLE encrypted_chat_history (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
session_id TEXT NOT NULL,
encrypted_payload TEXT NOT NULL, -- AES-256 encrypted
iv TEXT NOT NULL, -- Initialization vector
user_id TEXT REFERENCES auth.users(id),
created_at TIMESTAMPTZ DEFAULT NOW()
);| Endpoint | /api/chat-storage |
|---|---|
| Method | POST |
| Input | ```json |
| { | |
| "session_id": "uuid", | |
| "messages": [ |
{
"query": "original text",
"response": "encrypted tags",
"timestamp": "ISO8601"
}
] }
| **Encryption** | AES-256 with client-side key derivation |
| **Rate Limit** | 10 requests/minute per user |
### 4.3 Flow
```mermaid
sequenceDiagram
participant UI
participant API
participant Supabase
UI->>API: POST /chat-storage (encrypted)
API->>Supabase: Store {iv, encrypted_payload}
Supabase-->>API: 201 Created
API-->>UI: {success: true}
-
Zerodha Integration
- WebSocket setup for live prices
- Session management
-
Supabase Foundation ๐
- Table configuration
- Client-side encryption setup
| Component | Key Features | Dependencies |
|---|---|---|
| Market Data | Real-time tick streaming | Kite WebSocket |
| Stock Screener | Custom filter builder | Yahoo Finance API |
| Chat Storage ๐ | E2E encrypted history | Supabase + Crypto utils |
- Chat Storage: Implement message compression before encryption
- Data Sync: Conflict resolution for offline scenarios
- Retention Policies: Auto-purge old chats after 90 days
// /lib/utils/crypto.ts
export function encryptChatMessage(
text: string,
secretKey: string
): { iv: string; encryptedData: string } {
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv('aes-256-cbc',
Buffer.from(secretKey), iv);
let encrypted = cipher.update(text);
encrypted = Buffer.concat([encrypted, cipher.final()]);
return {
iv: iv.toString('hex'),
encryptedData: encrypted.toString('hex')
};
}| Resource | Permission | Policy |
|---|---|---|
| Chat History | Read/Write | User ID match + JWT validation |
| Encryption Keys | Client-side only | Never stored server-side |
- ๐ Research
What we're actually going to build vs what we dream about - ๐บ๏ธ Roadmap
Our master plan (subject to reality checks) - ๐งฉ Components
The building blocks that hopefully work together - ๐ก API Guide
Interfaces to every modular service, from market data to tax - ๐ฐ Funding
How we keep the lights on (and the servers running) - ๐๏ธ Architecture
The technical deep dive for masochists - โ
Todo List
Whatโs pending, whatโs burning, and whoโs guilty - ๐ค Contributing
Join the chaos, we have cookies*
*Cookies not guaranteed