# phodal/autodev-worker architecture

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

- Interactive diagram: https://gitdiagram.com/phodal/autodev-worker
- Repository: https://github.com/phodal/autodev-worker

## Overview

##### Project Type and Purpose
- This is a full-stack, monorepo platform with two primary packages:
- **context-worker**: a Node.js CLI/library that analyzes codebases, builds ASTs, extracts context, runs code searches, and presents codemodels.
- **web**: a Next.js (React + serverless API routes) frontend + backend that provides UI, REST/HTTP APIs, and persistence via Prisma.
- Purpose: power AI-driven development workflows (contextual code assistance, knowledge management, analytics, marketplace).

##### File Structure
- **Root**: pnpm-workspace; CI/CD pipeline (.github/workflows/ci-cd.yml); shared types in `packages/work-core`.
- **context-worker**: Organized into layered modules:
– **analyzer** (collects files, runs language analyzers)
– **ast** (Tree-sitter wrapper, AST builders)
– **code-context** (language profiles + context providers)
– **code-search** (scope graph builder + search indexes)
– **codemodel** (UML/PlantUML presenters)
– **document** (Markdown/ReST analyzers)
– **utils**, CLI entrypoint `main.ts`
- **web**: Next.js app under `src/app`, with:
– **pages** & **layouts**
– **API routes** (`src/app/api/...`) using utilities for LLM, embeddings, concept extraction, DB.
– **Prisma** schemas & migrations for relational store.
– **Components**, **hooks**, **lib** (shared UI, client-side logic).

##### Dig into the README
- Confirms the full-stack AI platform: “AI-Powered Development,” “Knowledge Management,” “Metrics & Analytics.”

1. **Client / Browser** (rectangle)
2. **Web Frontend** (Next.js UI)
3. **Web API Layer** (serverless functions / Next.js API routes)
5. **Context-Worker Service** (separate Node.js process or microservice)
9. **Shared Types / Modules** (`work-core`)

- Browser → Web Frontend (HTTP/HTTPS)
- Frontend → Web API (REST calls)
- API → Database (SQL queries via Prisma)
- API → Context-Worker (RPC/CLI invocation or message queue)
- Context-Worker → File System or Git Repos (scans code)
- Context-Worker → LLM Providers (API calls for embeddings, analysis)
- API → LLM Providers (when user triggers AI-powered features)
- CI/CD → Deploy Frontend & Context-Worker

c. Architectural Patterns & Principles:
– **Monorepo with Workspaces**: share code/types via `work-core`.
– **Layered Modules** in `context-worker`: separation of scanning, analysis, AST, context, search, presentation.
– **Serverless API** in Web: decoupled functions for chat, context generation, concept extraction, validation.
– **Plugin-style Language Profiles**: context providers registered for each language.
– **Infrastructure as Code**: Prisma migrations, Next.js config.

d. Key Technologies / Frameworks:
– Node.js + TypeScript (both packages)
– Tree-sitter (AST)
– Prisma + PostgreSQL (or other SQL)
– Next.js (React, server-side rendering, API routes)
– pnpm workspaces
– GitHub Actions (CI/CD)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients and External Systems
    Client["Client / Browser"]:::external
    ExternalLLM["External LLM Providers"]:::external
    CodeRepos["Code Repositories / Source Files"]:::external

    %% CI/CD
    CI["CI/CD Pipeline"]:::ci

    %% Shared Types
    WC["Shared Types (work-core)"]:::utility

    %% Web Layer
    subgraph "Web Layer"
        UI["Next.js UI"]:::frontend
        API["Web API (Next.js routes)"]:::backend
    end

    %% Web Utilities and Config
    subgraph "Web Utilities"
        Components["UI Components Library"]:::frontend
        Hooks["Client-side Hooks & Lib"]:::frontend
        NextConfig["Next.js Configuration"]:::backend
    end

    %% Web API Utilities
    subgraph "Web API Utils"
        LLM_Util["LLM Provider Integration Utility"]:::backend
        DB_Util["Database Utility (Prisma Client)"]:::backend
    end

    %% Database
    subgraph "Prisma"
        Schema["Prisma Schema & Migrations"]:::database
    end
    DB["Prisma-backed Database"]:::database

    %% Context-Worker Service
    subgraph "Context-Worker Service"
        CW_Main["CLI Entrypoint"]:::worker
        CW_Analyzer["Analyzer Module"]:::worker
        CW_AST["AST Module"]:::worker
        CW_CodeContext["Code-Context Module"]:::worker
        CW_CodeSearch["Code-Search Module"]:::worker
        CW_CodeModel["CodeModel Presenters"]:::worker
        CW_Document["Document Analyzers"]:::worker
        CW_Utils["Utilities"]:::worker
    end

    %% Data Flows
    Client -->|"HTTP/HTTPS"| UI
    UI -->|"REST Calls"| API
    API -->|"SQL via Prisma"| DB
    API -->|"Invoke RPC/CLI"| CW_Main
    API -->|"API Calls"| ExternalLLM

    CW_Main -->|"File I/O"| CodeRepos
    CW_Main -->|"Module Calls"| CW_Analyzer
    CW_Analyzer --> CW_AST
    CW_AST --> CW_CodeContext
    CW_CodeContext --> CW_CodeSearch
    CW_CodeSearch --> CW_CodeModel
    CW_CodeModel --> CW_Document
    CW_Analyzer --> CW_Utils
    CW_Main -->|"API Calls"| ExternalLLM

    API --> LLM_Util
    API --> DB_Util
    DB_Util --> Schema
    Schema --> DB

    WC --- CW_Main

    CI --> UI
    CI --> API
    CI --> CW_Main

    UI --- Components
    UI --- Hooks
    API --- LLM_Util
    API --- DB_Util
    API --- NextConfig

    %% Click Events
    click CW_Main "https://github.com/phodal/autodev-worker/blob/master/packages/context-worker/src/main.ts"
    click CW_Analyzer "https://github.com/phodal/autodev-worker/tree/master/packages/context-worker/src/analyzer"
    click CW_AST "https://github.com/phodal/autodev-worker/tree/master/packages/context-worker/src/ast"
    click CW_CodeContext "https://github.com/phodal/autodev-worker/tree/master/packages/context-worker/src/code-context"
    click CW_CodeSearch "https://github.com/phodal/autodev-worker/tree/master/packages/context-worker/src/code-search"
    click CW_CodeModel "https://github.com/phodal/autodev-worker/tree/master/packages/context-worker/src/codemodel"
    click CW_Document "https://github.com/phodal/autodev-worker/tree/master/packages/context-worker/src/document"
    click CW_Utils "https://github.com/phodal/autodev-worker/blob/master/packages/context-worker/src/utils.ts"
    click WC "https://github.com/phodal/autodev-worker/tree/master/packages/work-core"
    click UI "https://github.com/phodal/autodev-worker/tree/master/packages/web/src/app"
    click API "https://github.com/phodal/autodev-worker/tree/master/packages/web/src/app/api"
    click LLM_Util "https://github.com/phodal/autodev-worker/blob/master/packages/web/src/app/api/_utils/llm-provider.ts"
    click DB_Util "https://github.com/phodal/autodev-worker/blob/master/packages/web/src/app/api/_utils/db.ts"
    click Components "https://github.com/phodal/autodev-worker/tree/master/packages/web/src/components"
    click Hooks "https://github.com/phodal/autodev-worker/tree/master/packages/web/src/hooks"
    click NextConfig "https://github.com/phodal/autodev-worker/blob/master/packages/web/next.config.ts"
    click Schema "https://github.com/phodal/autodev-worker/blob/master/packages/web/prisma/schema.prisma"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#2196F3,color:#0D47A1;
    classDef backend fill:#E8F5E9,stroke:#43A047,color:#1B5E20;
    classDef worker fill:#FFF3E0,stroke:#FB8C00,color:#E65100;
    classDef database fill:#F3E5F5,stroke:#8E24AA,color:#4A148C,shape:cylinder;
    classDef external fill:#ECEFF1,stroke:#607D8B,color:#37474F,shape:cloud;
    classDef ci fill:#FFFDE7,stroke:#FDD835,color:#F57F17,shape:gear;
    classDef utility fill:#F1F8E9,stroke:#8BC34A,color:#33691E;
```
