# mukil571/portfolio-builder architecture

> Architecture diagram of the GitHub repository mukil571/portfolio-builder, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mukil571/portfolio-builder
- Repository: https://github.com/mukil571/portfolio-builder

## Overview

This is a Next.js website-builder with portfolio/product sites, an owner dashboard, and an AI chat widget grounded in each published site’s content and approved knowledge. The main workflow runs from an owner editing a site or managing knowledge and visitor questions, through API and server-side logic to persistent records; visitors then chat with the published site. The source excerpts show chat orchestration and selected persistence calls; several dashboard pages and routes are unsampled, so their detailed connections are omitted.

Main entry points: [`src/app/api/chat/route.ts`](https://github.com/mukil571/portfolio-builder/blob/main/src/app/api/chat/route.ts) (Chat endpoint), [`src/app/dashboard`](https://github.com/mukil571/portfolio-builder/tree/main/src/app/dashboard) (Owner dashboard), [`src/server/ai/knowledge.ts`](https://github.com/mukil571/portfolio-builder/blob/main/src/server/ai/knowledge.ts) (Knowledge service), [`src/server/db/index.ts`](https://github.com/mukil571/portfolio-builder/blob/main/src/server/db/index.ts) (Database client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Site Experiences"]
  node_public_site["Published site<br/>[page.tsx]"]
  node_site_renderer["Site renderer<br/>[site-renderer.tsx]"]
  node_chat_widget["AI chat widget<br/>[chat-widget.tsx]"]
end

subgraph group_management["Owner Management"]
  node_dashboard["Owner dashboard"]
  node_content_editor["Content editor<br/>[content-editor.tsx]"]
  node_website_manager["Website manager"]
  node_knowledge_manager["Knowledge manager"]
  node_questions_manager["Questions manager"]
end

subgraph group_server["Server Services"]
  node_chat_api["Chat endpoint<br/>[route.ts]"]
  node_site_api["Site and section APIs"]
  node_knowledge_api["Knowledge APIs"]
  node_questions_api["Question APIs"]
  node_knowledge_service["Knowledge service<br/>[knowledge.ts]"]
  node_question_service["Question service<br/>[questions.ts]"]
  node_prompt["Prompt builder<br/>[prompt.ts]"]
  node_ai_provider["AI provider<br/>[provider.ts]"]
  node_validation["Input validation<br/>[validation.ts]"]
  node_rate_limit["Rate limiting<br/>[rate-limit.ts]"]
  node_auth["Authentication<br/>[auth.ts]"]
end

subgraph group_persistence["Persistence"]
  node_db[("Postgres data<br/>[schema.ts]")]
  node_db_client["Database client<br/>[index.ts]"]
end

node_owner(("Site owner"))
node_visitor(("Site visitor"))

node_visitor -.->|"visits"| node_public_site
node_public_site -.->|"renders"| node_site_renderer
node_visitor -.->|"asks"| node_chat_widget
node_chat_widget -.->|"sends chat"| node_chat_api
node_owner -.->|"manages site"| node_dashboard
node_dashboard -.->|"offers editing"| node_content_editor
node_dashboard -.->|"offers setup"| node_website_manager
node_dashboard -.->|"offers curation"| node_knowledge_manager
node_dashboard -.->|"offers review"| node_questions_manager
node_knowledge_manager -->|"uses knowledge"| node_knowledge_service
node_questions_manager -->|"uses questions"| node_question_service
node_chat_api -->|"validates payload"| node_validation
node_chat_api -->|"checks limit"| node_rate_limit
node_chat_api -->|"loads context"| node_knowledge_service
node_chat_api -->|"records question"| node_question_service
node_chat_api -->|"gets model"| node_ai_provider
node_knowledge_service -->|"builds prompt"| node_prompt
node_knowledge_api -->|"checks session"| node_auth
node_knowledge_api -->|"calls service"| node_knowledge_service
node_questions_api -->|"checks session"| node_auth
node_questions_api -->|"calls service"| node_question_service
node_site_api -->|"checks session"| node_auth
node_site_api -->|"validates fields"| node_validation
node_site_api -->|"writes site records"| node_db_client
node_knowledge_service -->|"reads and writes"| node_db_client
node_question_service -->|"reads and writes"| node_db_client
node_db_client -->|"uses schema"| node_db
node_auth -->|"uses database"| node_db_client

click node_public_site "https://github.com/mukil571/portfolio-builder/blob/main/src/app/site/%5Bslug%5D/page.tsx"
click node_site_renderer "https://github.com/mukil571/portfolio-builder/blob/main/src/components/public/site-renderer.tsx"
click node_chat_widget "https://github.com/mukil571/portfolio-builder/blob/main/src/components/public/chat-widget.tsx"
click node_chat_api "https://github.com/mukil571/portfolio-builder/blob/main/src/app/api/chat/route.ts"
click node_dashboard "https://github.com/mukil571/portfolio-builder/tree/main/src/app/dashboard"
click node_content_editor "https://github.com/mukil571/portfolio-builder/blob/main/src/components/dashboard/content-editor.tsx"
click node_website_manager "https://github.com/mukil571/portfolio-builder/blob/main/src/components/dashboard/website-manager.tsx"
click node_knowledge_manager "https://github.com/mukil571/portfolio-builder/blob/main/src/components/dashboard/knowledge-manager.tsx"
click node_questions_manager "https://github.com/mukil571/portfolio-builder/blob/main/src/components/dashboard/questions-manager.tsx"
click node_site_api "https://github.com/mukil571/portfolio-builder/tree/main/src/app/api"
click node_knowledge_api "https://github.com/mukil571/portfolio-builder/tree/main/src/app/api/knowledge"
click node_questions_api "https://github.com/mukil571/portfolio-builder/tree/main/src/app/api/questions"
click node_knowledge_service "https://github.com/mukil571/portfolio-builder/blob/main/src/server/ai/knowledge.ts"
click node_question_service "https://github.com/mukil571/portfolio-builder/blob/main/src/server/ai/questions.ts"
click node_prompt "https://github.com/mukil571/portfolio-builder/blob/main/src/server/ai/prompt.ts"
click node_ai_provider "https://github.com/mukil571/portfolio-builder/blob/main/src/server/ai/provider.ts"
click node_validation "https://github.com/mukil571/portfolio-builder/blob/main/src/server/security/validation.ts"
click node_rate_limit "https://github.com/mukil571/portfolio-builder/blob/main/src/server/security/rate-limit.ts"
click node_auth "https://github.com/mukil571/portfolio-builder/blob/main/src/lib/auth.ts"
click node_db "https://github.com/mukil571/portfolio-builder/blob/main/src/server/db/schema.ts"
click node_db_client "https://github.com/mukil571/portfolio-builder/blob/main/src/server/db/index.ts"

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_public_site,node_site_renderer,node_chat_widget toneBlue
class node_dashboard,node_content_editor,node_website_manager,node_knowledge_manager,node_questions_manager toneAmber
class node_chat_api,node_site_api,node_knowledge_api,node_questions_api,node_knowledge_service,node_question_service,node_prompt,node_ai_provider,node_validation,node_rate_limit,node_auth toneMint
class node_db,node_db_client toneRose
class node_owner,node_visitor toneIndigo
```

## Components

### Site Experiences

- [Published site](https://github.com/mukil571/portfolio-builder/blob/main/src/app/site/%5Bslug%5D/page.tsx): `src/app/site/[slug]/page.tsx`
- [Site renderer](https://github.com/mukil571/portfolio-builder/blob/main/src/components/public/site-renderer.tsx): `src/components/public/site-renderer.tsx`
- [AI chat widget](https://github.com/mukil571/portfolio-builder/blob/main/src/components/public/chat-widget.tsx): `src/components/public/chat-widget.tsx`

### Owner Management

- [Owner dashboard](https://github.com/mukil571/portfolio-builder/tree/main/src/app/dashboard): `src/app/dashboard`
- [Content editor](https://github.com/mukil571/portfolio-builder/blob/main/src/components/dashboard/content-editor.tsx): `src/components/dashboard/content-editor.tsx`
- [Website manager](https://github.com/mukil571/portfolio-builder/blob/main/src/components/dashboard/website-manager.tsx): `src/components/dashboard/website-manager.tsx`
- [Knowledge manager](https://github.com/mukil571/portfolio-builder/blob/main/src/components/dashboard/knowledge-manager.tsx): `src/components/dashboard/knowledge-manager.tsx`
- [Questions manager](https://github.com/mukil571/portfolio-builder/blob/main/src/components/dashboard/questions-manager.tsx): `src/components/dashboard/questions-manager.tsx`

### Server Services

- [Chat endpoint](https://github.com/mukil571/portfolio-builder/blob/main/src/app/api/chat/route.ts): `src/app/api/chat/route.ts`
- [Site and section APIs](https://github.com/mukil571/portfolio-builder/tree/main/src/app/api): `src/app/api`
- [Knowledge APIs](https://github.com/mukil571/portfolio-builder/tree/main/src/app/api/knowledge): `src/app/api/knowledge`
- [Question APIs](https://github.com/mukil571/portfolio-builder/tree/main/src/app/api/questions): `src/app/api/questions`
- [Knowledge service](https://github.com/mukil571/portfolio-builder/blob/main/src/server/ai/knowledge.ts): `src/server/ai/knowledge.ts`
- [Question service](https://github.com/mukil571/portfolio-builder/blob/main/src/server/ai/questions.ts): `src/server/ai/questions.ts`
- [Prompt builder](https://github.com/mukil571/portfolio-builder/blob/main/src/server/ai/prompt.ts): `src/server/ai/prompt.ts`
- [AI provider](https://github.com/mukil571/portfolio-builder/blob/main/src/server/ai/provider.ts): `src/server/ai/provider.ts`
- [Input validation](https://github.com/mukil571/portfolio-builder/blob/main/src/server/security/validation.ts): `src/server/security/validation.ts`
- [Rate limiting](https://github.com/mukil571/portfolio-builder/blob/main/src/server/security/rate-limit.ts): `src/server/security/rate-limit.ts`
- [Authentication](https://github.com/mukil571/portfolio-builder/blob/main/src/lib/auth.ts): `src/lib/auth.ts`

### Persistence

- [Postgres data](https://github.com/mukil571/portfolio-builder/blob/main/src/server/db/schema.ts): `src/server/db/schema.ts`
- [Database client](https://github.com/mukil571/portfolio-builder/blob/main/src/server/db/index.ts): `src/server/db/index.ts`

### Other components

- **Site owner**
- **Site visitor**

## Connections

- Site visitor → Published site: visits
- Published site → Site renderer: renders
- Site visitor → AI chat widget: asks
- AI chat widget → Chat endpoint: sends chat
- Site owner → Owner dashboard: manages site
- Owner dashboard → Content editor: offers editing
- Owner dashboard → Website manager: offers setup
- Owner dashboard → Knowledge manager: offers curation
- Owner dashboard → Questions manager: offers review
- Knowledge manager → Knowledge service: uses knowledge (evidence: `src/components/dashboard/knowledge-manager.tsx`)
- Questions manager → Question service: uses questions (evidence: `src/components/dashboard/questions-manager.tsx`)
- Chat endpoint → Input validation: validates payload (evidence: `src/app/api/chat/route.ts`)
- Chat endpoint → Rate limiting: checks limit (evidence: `src/app/api/chat/route.ts`)
- Chat endpoint → Knowledge service: loads context (evidence: `src/app/api/chat/route.ts`)
- Chat endpoint → Question service: records question (evidence: `src/app/api/chat/route.ts`)
- Chat endpoint → AI provider: gets model (evidence: `src/app/api/chat/route.ts`)
- Knowledge service → Prompt builder: builds prompt (evidence: `src/server/ai/knowledge.ts`)
- Knowledge APIs → Authentication: checks session (evidence: `src/app/api/knowledge/route.ts`)
- Knowledge APIs → Knowledge service: calls service (evidence: `src/app/api/knowledge/route.ts`)
- Question APIs → Authentication: checks session (evidence: `src/app/api/questions/route.ts`)
- Question APIs → Question service: calls service (evidence: `src/app/api/questions/route.ts`)
- Site and section APIs → Authentication: checks session (evidence: `src/app/api/websites/route.ts`)
- Site and section APIs → Input validation: validates fields (evidence: `src/app/api/websites/route.ts`)
- Site and section APIs → Database client: writes site records (evidence: `src/app/api/websites/route.ts`)
- Knowledge service → Database client: reads and writes (evidence: `src/server/ai/knowledge.ts`)
- Question service → Database client: reads and writes (evidence: `src/server/ai/questions.ts`)
- Database client → Postgres data: uses schema (evidence: `src/server/db/index.ts`)
- Authentication → Database client: uses database (evidence: `src/lib/auth.ts`)
