Skip to main content

Software Design Specification - System Architecture

2. System Architecture​

2.1 High-Level Architecture​

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Client Layer β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ Web Browser β”‚ β”‚ Mobile β”‚ β”‚ External β”‚ β”‚
β”‚ β”‚ (React) β”‚ β”‚ App β”‚ β”‚ API β”‚ β”‚
β”‚ β”‚ β”‚ β”‚ (Phase 3+) β”‚ β”‚ Clients β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ HTTPS β”‚ HTTPS β”‚ HTTPS
β–Ό β–Ό β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Load Balancer Layer β”‚
β”‚ (NGINX / Cloud LB) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β–Ό β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Frontend Service β”‚ β”‚ Backend API Service β”‚
β”‚ (Static Files) β”‚ β”‚ (FastAPI) β”‚
β”‚ β”‚ β”‚ β”‚
β”‚ - React App Bundle β”‚ β”‚ - REST API Endpoints β”‚
β”‚ - Static Assets β”‚ β”‚ - Business Logic β”‚
β”‚ - Service Worker β”‚ β”‚ - Authentication β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β–Ό β–Ό β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Cache Layer β”‚ β”‚ Database β”‚ β”‚ Task Queue β”‚
β”‚ (Redis) β”‚ β”‚ (PostgreSQL β”‚ β”‚ (Celery) β”‚
β”‚ β”‚ β”‚ TimescaleDB) β”‚ β”‚ β”‚
β”‚ - Session β”‚ β”‚ β”‚ β”‚ - Background β”‚
β”‚ - Query Cache β”‚ β”‚ - Stocks β”‚ β”‚ Jobs β”‚
β”‚ - Rate Limits β”‚ β”‚ - Prices β”‚ β”‚ - Alerts β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ - Users β”‚ β”‚ - Reports β”‚
β”‚ - Portfolios β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β–²
β”‚ Updates
β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β–Ό β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Data Pipeline β”‚ β”‚ External β”‚
β”‚ (Airflow) │◄────────────────────►│ Data APIs β”‚
β”‚ β”‚ β”‚ β”‚
β”‚ - Price β”‚ β”‚ - KRX API β”‚
β”‚ Ingestion β”‚ β”‚ - F&Guide API β”‚
β”‚ - Indicator β”‚ β”‚ - OAuth β”‚
β”‚ Calculation β”‚ β”‚ Providers β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

2.2 Architectural Patterns​

2.2.1 Layered Architecture​

Presentation Layer (Frontend)

  • React components
  • State management (Zustand)
  • API client services
  • UI/UX interactions

Application Layer (Backend API)

  • REST API endpoints
  • Request validation
  • Business logic orchestration
  • Response formatting

Domain Layer

  • Core business entities (Stock, Portfolio, Alert)
  • Business rules and validation
  • Domain services

Data Access Layer

  • Database repositories
  • Query builders
  • ORM (SQLAlchemy)
  • Cache abstraction

Infrastructure Layer

  • External API integrations
  • Email notifications
  • File storage
  • Monitoring/logging

2.2.2 Microservices-Ready Monolith​

Current implementation uses a modular monolith architecture that can be split into microservices if needed:

Module Boundaries:

β”œβ”€β”€ Stock Service (read-only public data)
β”œβ”€β”€ User Service (authentication, profiles)
β”œβ”€β”€ Portfolio Service (user-specific data)
β”œβ”€β”€ Alert Service (notifications)
β”œβ”€β”€ Screening Service (complex queries)
└── Admin Service (internal operations)

Each module has:

  • Independent database tables
  • Clear API boundaries
  • Minimal cross-module dependencies

2.3 Component Interaction​

2.3.1 Stock Screening Flow​

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Browser β”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
β”‚ 1. POST /v1/screen (filters)
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ NGINX β”‚
β”‚ (Rate Limit)β”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ 2. Forward request
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ FastAPI Backend β”‚
β”‚ β”‚
β”‚ 3. Check cache ─┼───────► β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ (Redis) β”‚ β”‚ Redis β”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ 4. Cache miss
β”‚
β”‚ 5. Build query
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ PostgreSQL β”‚
β”‚ β”‚
β”‚ 6. Execute query β”‚
β”‚ on screening_ β”‚
β”‚ view (indexed)β”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ 7. Results
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ FastAPI Backend β”‚
β”‚ β”‚
β”‚ 8. Cache resultsβ”œβ”€β”€β”€β”€β”€β”€β”€β”€β–Ί Redis (TTL: 5min)
β”‚ 9. Format JSON β”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ 10. Response
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Browser β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

2.3.2 Data Pipeline Flow​

        18:00 KST (Market Close)
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Airflow Scheduler β”‚
β”‚ Triggers: daily_price_ β”‚
β”‚ ingestion DAG β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Task 1: Fetch KRX Prices β”‚
β”‚ - HTTP GET to KRX API β”‚
β”‚ - Receive JSON/XML data β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Task 2: Validate Data β”‚
β”‚ - Check price relationships β”‚
β”‚ - Verify completeness β”‚
β”‚ - Flag invalid records β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Task 3: Load to Database β”‚
β”‚ - UPSERT to daily_prices β”‚
β”‚ - Batch commit (1000 rows) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Task 4: Check Completeness β”‚
β”‚ - Verify 95%+ stocks updated β”‚
β”‚ - Alert if threshold missed β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Task 5: Trigger Indicator β”‚
β”‚ Calculation DAG β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Indicator Calculation DAG β”‚
β”‚ - Calculate 200+ indicators β”‚
β”‚ - Update screening views β”‚
β”‚ - Duration: ~20 minutes β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

2.4 Data Flow Diagrams​

2.4.1 User Authentication Flow​

β”Œβ”€β”€β”€β”€β”€β”€β”€β”                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ User β”‚ β”‚ Backend β”‚ β”‚ Database β”‚
β””β”€β”€β”€β”¬β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
β”‚ β”‚ β”‚
β”‚ POST /auth/login β”‚ β”‚
β”‚ {email, password} β”‚ β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ίβ”‚ β”‚
β”‚ β”‚ β”‚
β”‚ β”‚ SELECT * FROM users β”‚
β”‚ β”‚ WHERE email = ? β”‚
β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ίβ”‚
β”‚ β”‚ β”‚
β”‚ β”‚ Return user row β”‚
β”‚ │◄──────────────────────────────
β”‚ β”‚ β”‚
β”‚ β”‚ bcrypt.verify(password, β”‚
β”‚ β”‚ user.password_hash) β”‚
β”‚ β”‚ β”‚
β”‚ β”‚ Generate JWT tokens: β”‚
β”‚ β”‚ - access_token (15min) β”‚
β”‚ β”‚ - refresh_token (30 days) β”‚
β”‚ β”‚ β”‚
β”‚ β”‚ INSERT INTO refresh_tokens β”‚
β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ίβ”‚
β”‚ β”‚ β”‚
β”‚ 200 OK β”‚ β”‚
β”‚ {access_token, β”‚ β”‚
β”‚ refresh_token, user} β”‚ β”‚
│◄───────────────────────────── β”‚
β”‚ β”‚ β”‚
β”‚ Subsequent requests: β”‚ β”‚
β”‚ Authorization: Bearer β”‚ β”‚
β”‚ <access_token> β”‚ β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ίβ”‚ β”‚
β”‚ β”‚ β”‚
β”‚ β”‚ Verify JWT signature β”‚
β”‚ β”‚ Check expiry β”‚
β”‚ β”‚ β”‚
β”‚ 200 OK {data} β”‚ β”‚
│◄───────────────────────────── β”‚
β”‚ β”‚ β”‚