# abhi7b/dcp_capstone architecture

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

- Interactive diagram: https://gitdiagram.com/abhi7b/dcp_capstone
- Repository: https://github.com/abhi7b/dcp_capstone

## Overview

##### Project Type & Purpose
- This is a full-stack application where the backend provides a FastAPI service that supports a Streamlit frontend (note: there’s no Next.js). Its purpose is to collect, process, and expose investment-related data (especially focusing on Duke-affiliated companies/founders) enriched through SERP, Nitter, NLP, and LLM processing.

##### Main Components to Represent (all within one rectangle)
- Frontend Component:
- Backend API Service:
○ Data Collection Service: Showing integrations with SERP APIs and Nitter scraping.
○ Data Processing Pipeline: Highlight OpenAI-powered entity extraction, Duke affiliation verification, scoring, and enrichment.
○ Background Task Manager: Note the Celery integration for running scheduled tasks.
- Database and Caching:
- “PostgreSQL Database” as a component for structured storage.
- “Redis Cache” as the caching layer (used for rate limiting and fast data retrieval).

##### Relationships & Interactions
○ From the Streamlit Frontend to the FastAPI Backend (REST API calls).
○ From Processing pipeline to both Database (for processed data) and to background tasks (representing scheduled data updates).

##### Architectural Patterns & Design Principles
- Separation of Concerns: Clearly separate the frontend (Streamlit UI) from the backend service (REST API, processing, and data collection).
- Modular Services: Break down the backend into discrete modules (routes, services, tasks, utilities) – you may list these as annotations inside the “FastAPI Backend” block.
- Data Pipeline: Emphasize the two-stage pipeline—data collection followed by processing—that uses external data sources (SERP, Nitter) with enrichment via NLP.
- Use of External Technologies: Be sure to mark the usage of FastAPI, PostgreSQL, Redis, Celery (for tasks), and Streamlit.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Duke Capital Partners AI Insight Engine"
        A["Streamlit Frontend"]:::frontend

        subgraph "FastAPI Backend"
            B0["FastAPI Backend"]:::backend
            B0 -->|"API_Call"| B["API Endpoints"]:::service

            subgraph "Data Collection Service"
                C1["SERP Scraper"]:::service
                C2["Nitter Scraper"]:::service
            end

            B0 --> F["Raw Data Storage"]:::storage

            subgraph "Data Processing Pipeline"
                D1["NLP Processor"]:::service
                D2["Person Processor"]:::service
            end

            subgraph "Background Task Manager"
                E1["Celery App"]:::service
                E2["Tasks Scheduler"]:::service
            end
        end

        G["PostgreSQL Database"]:::database
        H["Redis Cache"]:::cache
    end

    %% Interactions
    A -->|"API_Call"| B0

    %% API Endpoints interactions with storage layers
    B -->|"DB_Query"| G
    B -->|"Cache_Lookup"| H

    %% Data Collection to Raw Data Storage
    C1 -->|"Store_Raw"| F
    C2 -->|"Store_Raw"| F

    %% Raw data flows into Data Processing Pipeline
    F -->|"Process_Data"| D1
    F -->|"Process_Data"| D2

    %% Processed data updates database and schedules background tasks
    D1 -->|"Pipeline_Update"| G
    D2 -->|"Pipeline_Update"| G
    D1 -->|"Schedule_Task"| E1
    D2 -->|"Schedule_Task"| E2

    %% Click Events
    click A "https://github.com/abhi7b/dcp_capstone/blob/main/frontend/app.py"
    click B0 "https://github.com/abhi7b/dcp_capstone/blob/main/backend/app/main.py"
    click B "https://github.com/abhi7b/dcp_capstone/tree/main/backend/app/routes/"
    click C1 "https://github.com/abhi7b/dcp_capstone/blob/main/backend/app/services/scraper.py"
    click C2 "https://github.com/abhi7b/dcp_capstone/blob/main/backend/app/services/nitter.py"
    click D1 "https://github.com/abhi7b/dcp_capstone/blob/main/backend/app/services/nlp_processor.py"
    click D2 "https://github.com/abhi7b/dcp_capstone/blob/main/backend/app/services/person_processor.py"
    click E1 "https://github.com/abhi7b/dcp_capstone/blob/main/backend/app/tasks/celery_app.py"
    click E2 "https://github.com/abhi7b/dcp_capstone/blob/main/backend/app/tasks/tasks.py"
    click G "https://github.com/abhi7b/dcp_capstone/tree/main/backend/app/db/"
    click H "https://github.com/abhi7b/dcp_capstone/blob/main/backend/app/services/redis.py"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef service fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef database fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef cache fill:#F0E68C,stroke:#000,stroke-width:1px;
    classDef storage fill:#D3D3D3,stroke:#000,stroke-width:1px;
```
