# injamul3798/swiftme_mini architecture

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

- Interactive diagram: https://gitdiagram.com/injamul3798/swiftme_mini
- Repository: https://github.com/injamul3798/swiftme_mini

## Overview

##### Project Type and Purpose
- Full-stack, AI-driven web application.
- Purpose: Accept a freelancer’s profile, analyze incoming job postings, retrieve relevant profile chunks via RAG, invoke GPT-4o through LangChain LCEL chains, stream a personalized proposal back to the client, and persist history in MySQL.

##### Main Components
a. Frontend
‑ Static assets served at “/”: index.html, app.js, styles.css.
‑ UI issues POST to /api/v1/profile/setup and /api/v1/proposal/generate (SSE).
b. FastAPI Application (app/main.py)
‑ HTTP server (Uvicorn) receives requests.
‑ Routers/controllers in app/api:
- profile.py → profile setup endpoint
- proposal.py → SSE streaming generator
- history.py → history retrieval
c. Service Layer (app/services)
‑ vector_store.py → wraps ChromaDB operations
‑ profile_matcher.py → RAG retrieval, chunk selection
‑ job_analyzer.py → LangChain chain to parse job description
‑ proposal_generator.py → LangChain LCEL chain for streaming GPT-4o output
d. Data Layer
‑ ChromaDB (persistent vector store) for profile embeddings.
‑ MySQL 8.0+ via async SQLAlchemy (app/database/base.py + alembic migrations) for history.
e. Models & Validation
‑ Pydantic schemas (app/models/schemas.py) for request/response.
‑ SQLAlchemy ORM models (app/models/db_models.py).
f. External Services
‑ OpenAI API (GPT-4o).
g. Infrastructure & Cross-cutting
‑ Configuration: Pydantic settings (app/config.py) reading .env.
‑ Logging: Loguru with structured JSON, correlation IDs (app/logging_config.py).
‑ Dependency Injection: app/dependencies.py.
‑ Migrations: Alembic (alembic/env.py, versions).
‑ Running scripts: run.py / uvicorn CLI.

##### Relationships & Data Flows
1. User → Frontend UI → POST /api/v1/profile/setup
- Frontend JS calls FastAPI → profile service → embed & store in ChromaDB → record chunk counts → response.
2. User → Frontend UI → POST /api/v1/proposal/generate (Accept: text/event-stream)
- FastAPI → profile_matcher (ChromaDB) for relevant chunks → job_analyzer (LangChain) → proposal_generator (LangChain + OpenAI GPT-4o) streams SSE.
- Intermediary: Streaming SSE events (“status”, “proposal_chunk”, “complete”).
- Persist generation metadata and summary to MySQL history.
3. User → GET /api/v1/proposal/history → FastAPI → query MySQL → return paginated history.

##### Architectural Patterns & Principles
- Layered architecture: Presentation (frontend, routers) → Business logic (services) → Data access (vector store, ORM) → External APIs.
- RAG pattern: retrieval from ChromaDB followed by generation.
- Async / non-blocking I/O end-to-end (FastAPI async, aiomysql, SSE).
- Single responsibility per service, clear separation of concerns.
- Dependency injection for testability.

##### Essential Elements
- Clear labels: e.g., “Frontend UI”, “FastAPI Endpoints”, “ProfileMatcher Service”.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    client[/"Client Browser"/]:::client

    %% Frontend UI
    subgraph "Frontend UI"
        Index["index.html"]:::frontend
        Appjs["app.js"]:::frontend
        Styles["styles.css"]:::frontend
    end

    client --> Index
    client --> Appjs
    client --> Styles

    %% Backend - FastAPI
    subgraph "Backend - FastAPI"
        Main["app/main.py"]:::backendEntry
        Run["run.py"]:::backendEntry

        subgraph "API Routers"
            ProfileAPI["Profile Router\nPOST /api/v1/profile/setup"]:::controller
            ProposalAPI["Proposal Router\nPOST /api/v1/proposal/generate\n(SSE)"]:::controller
            HistoryAPI["History Router\nGET /api/v1/proposal/history"]:::controller
        end

        subgraph "Infrastructure & Config"
            Config["app/config.py\n.env"]:::infra
            Logging["app/logging_config.py"]:::infra
            Dependencies["app/dependencies.py"]:::infra
            Migrations["alembic/env.py"]:::infra
        end
    end

    Run --> Main
    Main --> ProfileAPI
    Main --> ProposalAPI
    Main --> HistoryAPI

    %% Service Layer
    subgraph "Service Layer"
        VectorStore["Vector Store"]:::service
        ProfileMatcher["Profile Matcher"]:::service
        JobAnalyzer["Job Analyzer"]:::service
        ProposalGenerator["Proposal Generator"]:::service
    end

    %% Models & Validation
    subgraph "Models & Validation"
        Schemas["app/models/schemas.py"]:::model
        DBModels["app/models/db_models.py"]:::model
    end

    %% Data Layer
    subgraph "Data Layer"
        ChromaDB[(ChromaDB)]:::database
        MySQL[(MySQL 8.0+)]:::database
    end

    %% External API
    OpenAI((OpenAI GPT-4o)):::external

    %% Frontend to Backend
    Appjs -->|HTTP POST /api/v1/profile/setup| ProfileAPI
    Appjs -->|HTTP POST /api/v1/proposal/generate| ProposalAPI
    Appjs -->|HTTP GET /api/v1/proposal/history| HistoryAPI

    %% Profile Setup Flow
    ProfileAPI -->|calls| VectorStore
    VectorStore -->|embed & store| ChromaDB
    VectorStore -->|return status| ProfileAPI
    ProfileAPI -->|response| Appjs

    %% Proposal Generation Flow
    ProposalAPI -->|retrieve chunks| ProfileMatcher
    ProfileMatcher -->|chunks| ProposalAPI
    ProposalAPI -->|analyze job| JobAnalyzer
    JobAnalyzer -->|parsed data| ProposalAPI
    ProposalAPI -->|generate stream| ProposalGenerator
    ProposalGenerator -->|call API| OpenAI
    OpenAI -->|stream response| ProposalGenerator
    ProposalGenerator -->|SSE stream| Appjs
    ProposalGenerator -->|persist metadata| MySQL

    %% History Retrieval Flow
    HistoryAPI -->|SQL query| MySQL
    HistoryAPI -->|response| Appjs

    %% Models usage
    ProfileAPI --> Schemas
    HistoryAPI --> DBModels
    ProposalAPI --> Schemas

    %% Click Events
    click Index "https://github.com/injamul3798/swiftme_mini/blob/main/frontend/index.html"
    click Appjs "https://github.com/injamul3798/swiftme_mini/blob/main/frontend/app.js"
    click Styles "https://github.com/injamul3798/swiftme_mini/blob/main/frontend/styles.css"
    click Main "https://github.com/injamul3798/swiftme_mini/blob/main/app/main.py"
    click Run "https://github.com/injamul3798/swiftme_mini/blob/main/run.py"
    click ProfileAPI "https://github.com/injamul3798/swiftme_mini/blob/main/app/api/profile.py"
    click ProposalAPI "https://github.com/injamul3798/swiftme_mini/blob/main/app/api/proposal.py"
    click HistoryAPI "https://github.com/injamul3798/swiftme_mini/blob/main/app/api/history.py"
    click VectorStore "https://github.com/injamul3798/swiftme_mini/blob/main/app/services/vector_store.py"
    click ProfileMatcher "https://github.com/injamul3798/swiftme_mini/blob/main/app/services/profile_matcher.py"
    click JobAnalyzer "https://github.com/injamul3798/swiftme_mini/blob/main/app/services/job_analyzer.py"
    click ProposalGenerator "https://github.com/injamul3798/swiftme_mini/blob/main/app/services/proposal_generator.py"
    click Schemas "https://github.com/injamul3798/swiftme_mini/blob/main/app/models/schemas.py"
    click DBModels "https://github.com/injamul3798/swiftme_mini/blob/main/app/models/db_models.py"
    click Config "https://github.com/injamul3798/swiftme_mini/blob/main/app/config.py"
    click Logging "https://github.com/injamul3798/swiftme_mini/blob/main/app/logging_config.py"
    click Dependencies "https://github.com/injamul3798/swiftme_mini/blob/main/app/dependencies.py"
    click Migrations "https://github.com/injamul3798/swiftme_mini/blob/main/alembic/env.py"

    %% Styles
    classDef client fill:#D0E7FF,stroke:#0066CC,color:#003366
    classDef frontend fill:#E8F4FF,stroke:#3399FF
    classDef backendEntry fill:#DFFFE0,stroke:#33CC33
    classDef controller fill:#CCFFE0,stroke:#33CC33
    classDef service fill:#E0FFE8,stroke:#33AA44
    classDef database fill:#FFF2CC,stroke:#CC9900
    classDef external fill:#EEEEEE,stroke:#888888
    classDef infra fill:#F0F0FF,stroke:#8888CC
    classDef model fill:#FFF7E0,stroke:#CCAA33
```
