# michniks2001/mark-ai architecture

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

- Interactive diagram: https://gitdiagram.com/michniks2001/mark-ai
- Repository: https://github.com/michniks2001/mark-ai

## Overview

##### Project type and purpose
- This is a full-stack web application called **MarkAI**, an AI-powered marketing assistant.
- The **frontend** is a React/Vite/Tailwind single-page app for user interactions (landing page, pitch deck generator).
- The **backend** is a Python service (likely FastAPI, given the `routers` folder and `main.py`) that exposes endpoints for market analysis and pitch-deck generation. It orchestrates AI/vector operations, external data fetches, caching, and business logic.

##### File structure
Top-level:
- `.windsurf/` – internal rule docs (irrelevant for runtime)
- `backend/` – Python API service
- `frontend/` – React SPA
- Scripts & guides (`start-dev.sh`, `SETUP.md`, guides)

backend/
- `main.py` – entrypoint, server setup
- `routers/` – API endpoints (`github.py` suggests a GitHub integration)
- `market_analysis/` – chunks: analyzer, cache, Google search wrapper
- `pitch_deck/` – generator module
- `services/` – high-level orchestrators (`pitch_deck_service.py`, `sector_analyzer.py`)
- `vectorstore/` – chunking, embeddings, indexing, retrieval, storage
- `tools/` – misc utility functions

frontend/
- `src/components/` – React components, UI library under `ui/`
- `src/lib/api.js` – client-side API calls
- `vite.config.js`, `tailwind.config.js` – build configuration

##### README for additional insights
- README simply states “Your personal AI-powered marketing assistant!” – confirms purpose but no architecture hints.
- The existence of `MARKET_ANALYSIS_GUIDE.md` and `PITCH_DECK_GUIDE.md` suggests the two core user flows.

a. Main components
1. **Client (Browser)** – React SPA
2. **API Gateway / Web Server** – Python `main.py` (FastAPI/Uvicorn)
3. **Routers** – HTTP endpoints
4. **Service Layer** – `sector_analyzer`, `pitch_deck_service`
5. **Market Analysis Module** – `analyzer.py`, `google_market_search.py`, `cache.py`
6. **Pitch Deck Generator** – `generator.py`
7. **Vector Store** – chunker, embeddings, indexer, retrieval, persistent store
8. **External Services** – Google Search API, OpenAI or embedding provider, GitHub integration
9. **Data Store / Cache** – in-memory or Redis (as implied by `cache.py`)

b. Relationships & interactions
- Browser > invokes REST calls via `api.js` to API Gateway
- Requests hit specific **Router** (e.g., `/api/market-analysis`)
- Router delegates to **Service Layer**, which calls either the Market Analysis Module or Pitch Deck Generator
- Market Analysis Module may fetch external data (Google Search), store results in Cache, process text, then index embeddings into Vector Store
- Pitch Deck Generator uses Vector Store retrieval + templates to build a deck, possibly invoking AI embeddings or completions
- Results are returned up the stack to the frontend, which renders them in UI components
- GitHub Router can push or fetch user repos if integrating with a user’s code

c. Architectural patterns & principles
- **Layered Architecture**: API layer → Service layer → Domain modules → Data / external integrations
- **Separation of Concerns**: Routers only handle HTTP; services orchestrate business logic; vectorstore is a self-contained sub-system
- **Modularity**: Each feature (market analysis, pitch deck) lives in its own package
- **Extensibility**: Tools and services folders can be extended with new AI tasks

d. Key technologies/frameworks
- Backend: Python 3.x, FastAPI (inferred), Uvicorn/Gunicorn, vector database (custom or Pinecone?), Google Search API, OpenAI embeddings
- Frontend: React, Vite, TailwindCSS, custom UI components
- Dev & Deploy: Docker (implied), CI/CD scripts, environment configuration via `.env`, `pyproject.toml`, `package.json`

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend"
        direction TB
        Client["React SPA"]:::frontend
        APIClient["API Client Library\n(frontend/src/lib/api.js)"]:::frontend
        Utils["Utility Functions\n(frontend/src/lib/utils.js)"]:::frontend
        subgraph "UI Components"
            direction TB
            Landing["Landing Page"]:::frontend
            PitchUI["Pitch Deck Generator UI"]:::frontend
            Button["button.jsx"]:::frontend
            Card["card.jsx"]:::frontend
            Input["input.jsx"]:::frontend
            Label["label.jsx"]:::frontend
            Separator["separator.jsx"]:::frontend
            Textarea["textarea.jsx"]:::frontend
        end
    end

    %% Backend Layer
    subgraph "Backend"
        direction TB
        APIGateway["API Gateway / FastAPI\n(backend/main.py)"]:::api
        subgraph "Routers"
            direction TB
            GitHubRouter["Router: /github"]:::api
            MarketRouter["Router: /market-analysis"]:::api
            PitchRouter["Router: /pitch-deck"]:::api
        end
        subgraph "Service Layer"
            direction TB
            SectorService["Sector Analyzer Service"]:::service
            PitchService["Pitch Deck Service"]:::service
        end
        subgraph "Domain Modules"
            direction TB
            Analyzer["Analyzer"]:::domain
            CacheLayer["Cache"]:::domain
            SearchWrapper["Google Search Wrapper"]:::domain
            Generator["Pitch Deck Generator"]:::domain
        end
        subgraph "Vector Store"
            direction TB
            Chunker["Chunker"]:::storage
            Embeddings["Embeddings"]:::storage
            Indexer["Indexer"]:::storage
            Retrieval["Retrieval"]:::storage
            Store["Persistent Store"]:::storage
        end
    end

    %% External Services
    subgraph "External Services"
        direction TB
        GoogleAPI["Google Search API"]:::external
        OpenAI["AI Embedding/Completion API"]:::external
        GitHubAPI["GitHub API"]:::external
    end

    %% Connections: Frontend to Backend
    Client -->|"REST calls"| APIGateway
    APIClient --> Client
    Utils --> Client
    Landing --> Client
    PitchUI --> Client

    %% API Gateway to Routers
    APIGateway --> GitHubRouter
    APIGateway --> MarketRouter
    APIGateway --> PitchRouter

    %% Routers to Services
    GitHubRouter -->|"invoke GitHub Service"| SectorService
    MarketRouter -->|"invoke Market Analysis"| SectorService
    PitchRouter -->|"invoke Pitch Service"| PitchService

    %% Services to Domain Modules
    SectorService --> Analyzer
    Analyzer --> CacheLayer
    Analyzer --> SearchWrapper
    PitchService --> Generator
    PitchService --> Retrieval

    %% Domain Modules to Vector Store and External
    SearchWrapper --> GoogleAPI
    CacheLayer --> Store
    Analyzer --> Chunker
    Chunker --> Embeddings
    Embeddings --> Indexer
    Indexer --> Store
    Retrieval --> Store
    Retrieval --> Embeddings
    Generator --> OpenAI

    %% External Router
    GitHubRouter --> GitHubAPI

    %% Click Events
    click Client "https://github.com/michniks2001/mark-ai/tree/main/frontend/src"
    click APIClient "https://github.com/michniks2001/mark-ai/blob/main/frontend/src/lib/api.js"
    click Utils "https://github.com/michniks2001/mark-ai/blob/main/frontend/src/lib/utils.js"
    click Landing "https://github.com/michniks2001/mark-ai/blob/main/frontend/src/components/LandingPage.jsx"
    click PitchUI "https://github.com/michniks2001/mark-ai/blob/main/frontend/src/components/PitchDeckGenerator.jsx"
    click Button "https://github.com/michniks2001/mark-ai/blob/main/frontend/src/components/ui/button.jsx"
    click Card "https://github.com/michniks2001/mark-ai/blob/main/frontend/src/components/ui/card.jsx"
    click Input "https://github.com/michniks2001/mark-ai/blob/main/frontend/src/components/ui/input.jsx"
    click Label "https://github.com/michniks2001/mark-ai/blob/main/frontend/src/components/ui/label.jsx"
    click Separator "https://github.com/michniks2001/mark-ai/blob/main/frontend/src/components/ui/separator.jsx"
    click Textarea "https://github.com/michniks2001/mark-ai/blob/main/frontend/src/components/ui/textarea.jsx"
    click APIGateway "https://github.com/michniks2001/mark-ai/blob/main/backend/main.py"
    click GitHubRouter "https://github.com/michniks2001/mark-ai/blob/main/backend/routers/github.py"
    click SectorService "https://github.com/michniks2001/mark-ai/blob/main/backend/services/sector_analyzer.py"
    click PitchService "https://github.com/michniks2001/mark-ai/blob/main/backend/services/pitch_deck_service.py"
    click Analyzer "https://github.com/michniks2001/mark-ai/blob/main/backend/market_analysis/analyzer.py"
    click CacheLayer "https://github.com/michniks2001/mark-ai/blob/main/backend/market_analysis/cache.py"
    click SearchWrapper "https://github.com/michniks2001/mark-ai/blob/main/backend/market_analysis/google_market_search.py"
    click Generator "https://github.com/michniks2001/mark-ai/blob/main/backend/pitch_deck/generator.py"
    click Chunker "https://github.com/michniks2001/mark-ai/blob/main/backend/vectorstore/chunker.py"
    click Embeddings "https://github.com/michniks2001/mark-ai/blob/main/backend/vectorstore/embeddings.py"
    click Indexer "https://github.com/michniks2001/mark-ai/blob/main/backend/vectorstore/indexer.py"
    click Retrieval "https://github.com/michniks2001/mark-ai/blob/main/backend/vectorstore/retrieval.py"
    click Store "https://github.com/michniks2001/mark-ai/blob/main/backend/vectorstore/store.py"

    %% Styles
    classDef frontend fill:#E3F2FF,stroke:#2196F3,color:#0D47A1,stroke-width:1px
    classDef api fill:#E8F5E9,stroke:#4CAF50,color:#1B5E20,stroke-width:1px
    classDef service fill:#FFF3E0,stroke:#FB8C00,color:#E65100,stroke-width:1px
    classDef domain fill:#FFE0B2,stroke:#FF9800,color:#E65100,stroke-width:1px
    classDef storage fill:#FFFDE7,stroke:#FDD835,color:#F57F17,stroke-width:1px
    classDef external fill:#ECEFF1,stroke:#90A4AE,color:#37474F,stroke-width:1px
```
