# anshsrihan/ticker2 architecture

> Architecture diagram of the GitHub repository anshsrihan/ticker2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anshsrihan/ticker2
- Repository: https://github.com/anshsrihan/ticker2

## Overview

##### Project Type and Purpose
- This is a full-stack, Django-based web application augmented with Celery for background processing.
- It provides real-time stock quotes, technical indicators, corporate filings, news integration, price alerts, and watchlists.

##### Break Down the Main Components
a. Client Layer
- Web Browser (User Interface)
- Static Assets: HTML templates under `templates/`, CSS/JS under `staticfiles/`
- Keyboard shortcuts & search overlay (JS code in `staticfiles/js/main.js`)
b. Web Tier
- Nginx (optional, for production static & reverse proxy)
- Gunicorn/uWSGI serving the Django app (`manage.py`, `stock_ticker/wsgi.py`)
- Django Application
– URL routing (`stock_ticker/urls.py`, `stocks/urls.py`)
– Views & REST Endpoints (`stocks/views.py`, DRF serializers in `stocks/serializers.py`)
– Business logic & services (`stocks/services.py`)
– Database models (`stocks/models.py`)
c. Data Persistence
- Primary Database (PostgreSQL recommended)
- Redis
– Caching stock data for quick access
– Celery broker & backend
d. Background Processing
- Celery Workers (`stocks/tasks.py`, `celery_app.py`)
- Celery Beat (scheduler for periodic tasks)
- Redis as broker/scheduler backend
- Periodic jobs: price updates, alert checks, news fetching, data cleanup
e. External Systems
- Yahoo Finance API & `yfinance` library (real-time & historical prices)
- NSE website scraping (corporate filings)
- News sources: RSS feeds, financial news APIs
- Email SMTP server (Gmail) for sending price-alert emails

##### Relationships & Data Flows
- Browser ↔ Nginx ↔ Gunicorn ↔ Django views
- Views ↔ Database (read/write)
- Views ↔ Redis (cache queries, session data)
- Views ↔ External APIs (data fetch via `services.py`)
- Celery Beat → Redis → Celery Workers →
- External APIs/scrapers → Database
- Database ← price alerts → Email server
- Reactivity: WebSocket or polling for real-time updates (if implemented; otherwise periodic AJAX)
- API endpoints (`/api/search/`, `/api/stock/<symbol>/price/`) consumed by frontend

##### Architectural Patterns & Principles
- MVC/MVT (Django’s Model-View-Template)
- Layered Architecture: Presentation, Application, Data
- Event-driven background processing with Celery
- Separation of concerns: services layer for external calls, tasks for scheduled jobs
- Cache-aside pattern (Redis caching)

- URL Router
- Views & DRF Endpoints
- Services Layer
- Models Layer
- Yahoo Finance API, NSE Scraper, RSS/News APIs, SMTP.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Browser["Web Browser"]:::static
        Templates["HTML Templates"]:::static
        JS["JavaScript (main.js)"]:::static
        CSS["CSS Styles"]:::static
    end

    %% Web Tier
    subgraph "Web Tier"
        Nginx["Nginx\n(HTTP 80/443)"]:::compute
        Gunicorn["Gunicorn/uWSGI"]:::compute
        subgraph "Django App"
            Router["URL Routing"]:::compute
            Views["Views & REST Endpoints"]:::compute
            Serializers["DRF Serializers"]:::compute
            Services["Business Logic & External-Service Wrappers"]:::compute
            Models["Database Models"]:::compute
            WSGI["WSGI Entry Point"]:::compute
            Manage["manage.py"]:::compute
            Migrations["DB Migrations"]:::compute
            Admin["Django Admin Config"]:::compute
            Populate["populate_stocks Cmd"]:::compute
            TestNews["test_news Cmd"]:::compute
        end
    end

    %% Data Persistence
    subgraph "Data Persistence"
        Postgres["PostgreSQL"]:::dataStore
        Redis["Redis\n(Cache & Broker)"]:::dataStore
    end

    %% Background Processing
    subgraph "Background Processing"
        Beat["Celery Beat\n(periodic scheduler)"]:::compute
        Worker["Celery Worker"]:::compute
    end

    %% External Services
    subgraph "External Services"
        Yahoo["Yahoo Finance API"]:::external
        NSE["NSE Scraper"]:::external
        NewsAPI["RSS/News APIs"]:::external
        SMTP["SMTP Server (SMTP 587)"]:::external
    end

    %% Connections
    Browser -->|"HTTP"| Nginx
    Nginx -->|"proxy"| Gunicorn
    Gunicorn -->|"calls"| WSGI
    Gunicorn -->|"runs"| Manage
    Gunicorn -->|"routes to"| Router
    Router -->|"dispatch"| Views
    Views -->|"uses"| Serializers
    Views -->|"calls"| Services
    Services -->|"accesses"| Models
    Views -->|"read/write"| Postgres
    Views -->|"cache lookup"| Redis
    Services -->|"fetch data"| Yahoo
    Services -->|"scrape filings"| NSE
    Services -->|"fetch news"| NewsAPI

    Beat -->|"broker 6379"| Redis
    Redis -->|"triggers tasks"| Worker
    Worker -->|"update prices"| Postgres
    Worker -->|"send alerts"| SMTP
    Worker -->|"fetch data"| Yahoo
    Worker -->|"scrape filings"| NSE
    Worker -->|"fetch news"| NewsAPI

    %% Click Events
    click Templates "https://github.com/anshsrihan/ticker2/tree/main/templates/"
    click JS "https://github.com/anshsrihan/ticker2/blob/main/staticfiles/js/main.js"
    click CSS "https://github.com/anshsrihan/ticker2/blob/main/staticfiles/css/style.css"
    click ProjectURLs "https://github.com/anshsrihan/ticker2/blob/main/stock_ticker/urls.py"
    click AppURLs "https://github.com/anshsrihan/ticker2/blob/main/stocks/urls.py"
    click Views "https://github.com/anshsrihan/ticker2/blob/main/stocks/views.py"
    click Serializers "https://github.com/anshsrihan/ticker2/blob/main/stocks/serializers.py"
    click Services "https://github.com/anshsrihan/ticker2/blob/main/stocks/services.py"
    click Models "https://github.com/anshsrihan/ticker2/blob/main/stocks/models.py"
    click WSGI "https://github.com/anshsrihan/ticker2/blob/main/stock_ticker/wsgi.py"
    click Manage "https://github.com/anshsrihan/ticker2/blob/main/manage.py"
    click CeleryConfig "https://github.com/anshsrihan/ticker2/blob/main/celery_app.py"
    click Tasks "https://github.com/anshsrihan/ticker2/blob/main/stocks/tasks.py"
    click Migrations "https://github.com/anshsrihan/ticker2/blob/main/stocks/migrations/0001_initial.py"
    click Admin "https://github.com/anshsrihan/ticker2/blob/main/stocks/admin.py"
    click Populate "https://github.com/anshsrihan/ticker2/blob/main/stocks/management/commands/populate_stocks.py"
    click TestNews "https://github.com/anshsrihan/ticker2/blob/main/stocks/management/commands/test_news.py"

    %% Styles
    classDef dataStore fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef compute fill:#ccddff,stroke:#333,stroke-width:1px
    classDef external fill:#ffcc99,stroke:#333,stroke-width:1px
    classDef static fill:#eeeeee,stroke:#333,stroke-width:1px
```
