# swathi-88/competesmart architecture

> Architecture diagram of the GitHub repository swathi-88/competesmart, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/swathi-88/competesmart
- Repository: https://github.com/swathi-88/competesmart

## Overview

#### Purpose and Entry Points
CompeteSmart is a market-intelligence and strategy-simulation system: it collects competitive-market data, derives semantic and temporal signals, projects experiment outcomes, and exposes an AI copilot. The primary backend entry point is the FastAPI app in `backend/api.py`; `backend/main.py` and `backend/prototype_pipeline.py` appear to support pipeline execution/prototyping. The Next.js App Router frontend starts from `frontend/src/app/page.tsx`, with operational views at `frontend/src/app/dashboard/page.tsx` and `frontend/src/app/experiment-builder/page.tsx`.

#### Client Application
The frontend provides the user-facing dashboard, experiment workspace, authenticated access, and copilot interaction. `frontend/src/utils/api.ts` is the API boundary to the FastAPI service, configured through `NEXT_PUBLIC_API_URL`. Simulation UI composition is centered on `frontend/src/components/simulation/SimulationOrchestrator.tsx`, with KPI and history views in `frontend/src/components/simulation/LiveKpiPanel.tsx` and `frontend/src/components/simulation/ExperimentHistory.tsx`.

#### API and Application Boundary
FastAPI routes in `backend/api.py` coordinate requests from the frontend into authentication, intelligence retrieval, simulations, and copilot behavior. Authentication is separated in `backend/src/auth.py`; persistence and database session/access concerns are centralized in `backend/src/database.py`. Domain models are defined in `backend/src/models.py`, forming the contract between API, persistence, and analytical stages.

#### Market Data Acquisition and Persistence
The scraper subsystem is an independently structured ingestion boundary under `backend/web-scraper/`. `backend/web-scraper/scraper.py` obtains external market content, `backend/web-scraper/parser.py` converts it into usable records, and `backend/web-scraper/db.py` persists ingestion results. `backend/web-scraper/scheduler.py` suggests recurring collection rather than frontend-triggered scraping. PostgreSQL with pgvector is the stated system of record for structured market data and vector similarity data.

#### Intelligence Pipeline
The intelligence layer transforms ingested market content into searchable, decision-ready representations. `backend/src/embedding_pipeline.py` and `backend/src/intelligence/embeddings.py` generate embeddings; `backend/src/semantic_search.py` retrieves semantically relevant market context from pgvector-backed storage. Signal extraction, clustering, and time-oriented analysis are separated into `backend/src/intelligence/signal_extraction.py`, `backend/src/intelligence/clustering.py`, and `backend/src/intelligence/temporal.py`. Their output is likely normalized through schemas in `backend/src/intelligence/schemas.py`.

#### Decision, Trust, and Simulation
Strategic reasoning is layered above intelligence results. `backend/decision_layer.py` represents the decision/simulation layer that turns market signals and hypothetical pivots into projected outcomes. `backend/src/trust_layer.py` is an explicit validation/governance boundary around AI-generated or inferred recommendations. `backend/src/intelligence/advanced.py` likely provides higher-order analysis feeding these stages. Persisted or inspectable decision output is represented by `backend/decision_layer_output.json`.

#### AI Copilot and External Services
`backend/src/execution_copilot.py` supplies context-aware strategic guidance, using retrieved market intelligence and decision outputs rather than operating as a standalone chat service. The backend requires OpenAI and Google Gemini credentials, so model-provider calls are an external-service boundary; PostgreSQL/pgvector is the data-service boundary. The runtime is Python 3.10+ with FastAPI (`backend/requirements.txt`, `backend/runtime.txt`); the client is Next.js 15+ (`frontend/package.json`) and communicates over HTTP.

Main entry points: [`backend/api.py`](https://github.com/swathi-88/competesmart/blob/master/backend/api.py) (FastAPI routes), [`backend/src/semantic_search.py`](https://github.com/swathi-88/competesmart/blob/master/backend/src/semantic_search.py) (Semantic retrieval), [`backend/src/execution_copilot.py`](https://github.com/swathi-88/competesmart/blob/master/backend/src/execution_copilot.py) (Execution copilot), [`backend/decision_layer.py`](https://github.com/swathi-88/competesmart/blob/master/backend/decision_layer.py) (Strategy simulation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Next.js Client"]
  node_frontend_pages["Dashboard &amp; experiment views<br/>Next.js pages<br/>[page.tsx]"]
  node_simulation_ui["Simulation workspace<br/>React components"]
  node_frontend_api["API client<br/>HTTP boundary<br/>[api.ts]"]
end

subgraph group_api["FastAPI Application"]
  node_fastapi{{"FastAPI routes<br/>Python API<br/>[api.py]"}}
  node_auth["Authentication<br/>auth service<br/>[auth.py]"]
  node_models["Domain models<br/>data contracts<br/>[models.py]"]
end

subgraph group_ingestion["Market Ingestion"]
  node_scheduler["Collection scheduler<br/>recurring job<br/>[scheduler.py]"]
  node_scraper["Market scraper<br/>external ingestion<br/>[scraper.py]"]
  node_parser["Content parser<br/>record transformation<br/>[parser.py]"]
  node_scraper_db["Ingestion persistence<br/>database adapter<br/>[db.py]"]
end

subgraph group_intelligence["Intelligence &amp; Decisions"]
  node_embeddings["Embedding generation<br/>intelligence stage"]
  node_semantic_search["Semantic retrieval<br/>intelligence query<br/>[semantic_search.py]"]
  node_signal_analysis["Signals, clusters &amp; temporal analysis<br/>intelligence analysis"]
  node_decision_layer{{"Strategy simulation<br/>decision engine<br/>[decision_layer.py]"}}
  node_trust_layer["Recommendation governance<br/>trust validation<br/>[trust_layer.py]"]
  node_copilot["Execution copilot<br/>AI guidance"]
end

node_database[("PostgreSQL + pgvector<br/>system of record")]
node_model_providers(("OpenAI &amp; Gemini<br/>model providers"))

node_frontend_pages -->|"renders"| node_simulation_ui
node_simulation_ui -->|"uses"| node_frontend_api
node_frontend_api -->|"HTTP"| node_fastapi
node_fastapi -->|"authenticates"| node_auth
node_fastapi -->|"uses contracts"| node_models
node_fastapi -->|"retrieves context"| node_semantic_search
node_fastapi -->|"runs simulations"| node_decision_layer
node_fastapi -->|"requests guidance"| node_copilot
node_scheduler -->|"triggers"| node_scraper
node_scraper -->|"market content"| node_parser
node_parser -->|"records"| node_scraper_db
node_scraper_db -->|"persists"| node_database
node_database -->|"market content"| node_embeddings
node_embeddings -->|"vector records"| node_database
node_semantic_search -->|"pgvector query"| node_database
node_semantic_search -->|"relevant context"| node_signal_analysis
node_signal_analysis -->|"market signals"| node_decision_layer
node_decision_layer -->|"recommendations"| node_trust_layer
node_trust_layer -->|"validated outputs"| node_copilot
node_semantic_search -->|"retrieved intelligence"| node_copilot
node_copilot -->|"model calls"| node_model_providers

click node_frontend_pages "https://github.com/swathi-88/competesmart/blob/master/frontend/src/app/dashboard/page.tsx"
click node_simulation_ui "https://github.com/swathi-88/competesmart/blob/master/frontend/src/components/simulation/SimulationOrchestrator.tsx"
click node_frontend_api "https://github.com/swathi-88/competesmart/blob/master/frontend/src/utils/api.ts"
click node_fastapi "https://github.com/swathi-88/competesmart/blob/master/backend/api.py"
click node_auth "https://github.com/swathi-88/competesmart/blob/master/backend/src/auth.py"
click node_models "https://github.com/swathi-88/competesmart/blob/master/backend/src/models.py"
click node_scheduler "https://github.com/swathi-88/competesmart/blob/master/backend/web-scraper/scheduler.py"
click node_scraper "https://github.com/swathi-88/competesmart/blob/master/backend/web-scraper/scraper.py"
click node_parser "https://github.com/swathi-88/competesmart/blob/master/backend/web-scraper/parser.py"
click node_scraper_db "https://github.com/swathi-88/competesmart/blob/master/backend/web-scraper/db.py"
click node_embeddings "https://github.com/swathi-88/competesmart/blob/master/backend/src/embedding_pipeline.py"
click node_semantic_search "https://github.com/swathi-88/competesmart/blob/master/backend/src/semantic_search.py"
click node_signal_analysis "https://github.com/swathi-88/competesmart/blob/master/backend/src/intelligence/signal_extraction.py"
click node_decision_layer "https://github.com/swathi-88/competesmart/blob/master/backend/decision_layer.py"
click node_trust_layer "https://github.com/swathi-88/competesmart/blob/master/backend/src/trust_layer.py"
click node_copilot "https://github.com/swathi-88/competesmart/blob/master/backend/src/execution_copilot.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend_pages,node_simulation_ui,node_frontend_api toneBlue
class node_fastapi,node_auth,node_models toneAmber
class node_scheduler,node_scraper,node_parser,node_scraper_db toneMint
class node_embeddings,node_semantic_search,node_signal_analysis,node_decision_layer,node_trust_layer,node_copilot toneRose
class node_database,node_model_providers toneNeutral
```

## Components

### Next.js Client

- [Dashboard & experiment views](https://github.com/swathi-88/competesmart/blob/master/frontend/src/app/dashboard/page.tsx): Next.js pages · `frontend/src/app/dashboard/page.tsx`
- [Simulation workspace](https://github.com/swathi-88/competesmart/blob/master/frontend/src/components/simulation/SimulationOrchestrator.tsx): React components · `frontend/src/components/simulation/SimulationOrchestrator.tsx`
- [API client](https://github.com/swathi-88/competesmart/blob/master/frontend/src/utils/api.ts): HTTP boundary · `frontend/src/utils/api.ts`

### FastAPI Application

- [FastAPI routes](https://github.com/swathi-88/competesmart/blob/master/backend/api.py): Python API · Coordinates authentication, intelligence, simulations, and copilot requests. · `backend/api.py`
- [Authentication](https://github.com/swathi-88/competesmart/blob/master/backend/src/auth.py): auth service · `backend/src/auth.py`
- [Domain models](https://github.com/swathi-88/competesmart/blob/master/backend/src/models.py): data contracts · `backend/src/models.py`

### Market Ingestion

- [Collection scheduler](https://github.com/swathi-88/competesmart/blob/master/backend/web-scraper/scheduler.py): recurring job · `backend/web-scraper/scheduler.py`
- [Market scraper](https://github.com/swathi-88/competesmart/blob/master/backend/web-scraper/scraper.py): external ingestion · `backend/web-scraper/scraper.py`
- [Content parser](https://github.com/swathi-88/competesmart/blob/master/backend/web-scraper/parser.py): record transformation · `backend/web-scraper/parser.py`
- [Ingestion persistence](https://github.com/swathi-88/competesmart/blob/master/backend/web-scraper/db.py): database adapter · `backend/web-scraper/db.py`

### Intelligence & Decisions

- [Embedding generation](https://github.com/swathi-88/competesmart/blob/master/backend/src/embedding_pipeline.py): intelligence stage · `backend/src/embedding_pipeline.py`
- [Semantic retrieval](https://github.com/swathi-88/competesmart/blob/master/backend/src/semantic_search.py): intelligence query · `backend/src/semantic_search.py`
- [Signals, clusters & temporal analysis](https://github.com/swathi-88/competesmart/blob/master/backend/src/intelligence/signal_extraction.py): intelligence analysis · `backend/src/intelligence/signal_extraction.py`
- [Strategy simulation](https://github.com/swathi-88/competesmart/blob/master/backend/decision_layer.py): decision engine · Projects outcomes from market signals and hypothetical pivots. · `backend/decision_layer.py`
- [Recommendation governance](https://github.com/swathi-88/competesmart/blob/master/backend/src/trust_layer.py): trust validation · `backend/src/trust_layer.py`
- [Execution copilot](https://github.com/swathi-88/competesmart/blob/master/backend/src/execution_copilot.py): AI guidance · Produces context-aware strategic guidance. · `backend/src/execution_copilot.py`

### Other components

- **PostgreSQL + pgvector**: system of record · Stores structured market data and vector similarity data.
- **OpenAI & Gemini**: model providers

## Connections

- Dashboard & experiment views → Simulation workspace: renders
- Simulation workspace → API client: uses
- API client → FastAPI routes: HTTP
- FastAPI routes → Authentication: authenticates
- FastAPI routes → Domain models: uses contracts
- FastAPI routes → Semantic retrieval: retrieves context
- FastAPI routes → Strategy simulation: runs simulations
- FastAPI routes → Execution copilot: requests guidance
- Collection scheduler → Market scraper: triggers
- Market scraper → Content parser: market content
- Content parser → Ingestion persistence: records
- Ingestion persistence → PostgreSQL + pgvector: persists
- PostgreSQL + pgvector → Embedding generation: market content
- Embedding generation → PostgreSQL + pgvector: vector records
- Semantic retrieval → PostgreSQL + pgvector: pgvector query
- Semantic retrieval → Signals, clusters & temporal analysis: relevant context
- Signals, clusters & temporal analysis → Strategy simulation: market signals
- Strategy simulation → Recommendation governance: recommendations
- Recommendation governance → Execution copilot: validated outputs
- Semantic retrieval → Execution copilot: retrieved intelligence
- Execution copilot → OpenAI & Gemini: model calls
