# amerdoahmed/threads architecture

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

- Interactive diagram: https://gitdiagram.com/amerdoahmed/threads
- Repository: https://github.com/amerdoahmed/threads

## Overview

This is a Next.js social-thread application: authenticated users complete onboarding, browse a paginated thread feed, create threads and replies, and explore profiles, creators, activity, and communities. Server actions own the data operations and persist users, threads, and communities through Mongoose. Profile editing also supports image upload. The sampled source shows the feed and action-to-model relationships; some route and integration details are represented only by the source index, so unsampled links are omitted where their caller is unclear.

Main entry points: [`lib/actions/user.actions.ts`](https://github.com/amerdoahmed/threads/blob/main/lib/actions/user.actions.ts) (User operations), [`lib/actions/thread.actions.ts`](https://github.com/amerdoahmed/threads/blob/main/lib/actions/thread.actions.ts) (Thread operations), [`lib/actions/community.actions.ts`](https://github.com/amerdoahmed/threads/blob/main/lib/actions/community.actions.ts) (Community operations), [`app/(root)/thread/[id]/page.tsx`](https://github.com/amerdoahmed/threads/blob/main/app/(root)/thread/%5Bid%5D/page.tsx) (Thread detail)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_home["Thread feed<br/>[page.tsx]"]
  node_activity["Activity<br/>[page.tsx]"]
  node_communities["Communities<br/>[page.tsx]"]
  node_search["Creator search<br/>[page.tsx]"]
  node_profile["User profile<br/>[page.tsx]"]
  node_thread_detail["Thread detail<br/>[page.tsx]"]
  node_thread_card["Thread card<br/>[ThreadCard.tsx]"]
  node_searchbar["Search input<br/>[Searchbar.tsx]"]
  node_pagination["Pagination<br/>[Pagination.tsx]"]
  node_profile_header["Profile header<br/>[ProfileHeader.tsx]"]
  node_threads_tab["Profile threads<br/>[ThreadsTab.tsx]"]
end

subgraph group_authoring["Profiles and authoring"]
  node_onboarding["Onboarding<br/>[page.tsx]"]
  node_account_form["Profile editor<br/>[AccountProfile.tsx]"]
  node_create_thread_page["Thread composer page<br/>[page.tsx]"]
  node_post_form["Thread composer<br/>[PostThread.tsx]"]
  node_comment_form["Reply form<br/>[Comment.tsx]"]
end

subgraph group_domain["Domain operations"]
  node_user_actions["User operations<br/>[user.actions.ts]"]
  node_thread_actions["Thread operations<br/>[thread.actions.ts]"]
  node_community_actions["Community operations"]
end

subgraph group_infrastructure["Persistence and integrations"]
  node_user_model[("User model<br/>[user.model.ts]")]
  node_thread_model[("Thread model<br/>[thread.model.ts]")]
  node_community_model[("Community model<br/>[community.model.ts]")]
  node_mongoose["MongoDB connection<br/>[mongoose.ts]"]
  node_upload_form_helper["Upload helper<br/>[uploadthings.ts]"]
  node_upload_endpoint["Upload endpoint<br/>[core.ts]"]
  node_clerk_webhook["Clerk webhook<br/>[route.ts]"]
end

node_visitor(("User"))

node_visitor -->|"opens feed"| node_home
node_home -->|"fetches user"| node_user_actions
node_home -->|"fetches threads"| node_thread_actions
node_home -->|"renders"| node_thread_card
node_visitor -->|"sets up profile"| node_onboarding
node_onboarding -->|"renders"| node_account_form
node_account_form -->|"updates profile"| node_user_actions
node_account_form -->|"uploads image"| node_upload_form_helper
node_upload_form_helper -->|"uses upload service"| node_upload_endpoint
node_visitor -->|"starts thread"| node_create_thread_page
node_create_thread_page -->|"renders"| node_post_form
node_post_form -->|"creates thread"| node_thread_actions
node_thread_detail -->|"loads thread"| node_thread_actions
node_thread_detail -->|"loads user"| node_user_actions
node_thread_detail -->|"renders thread"| node_thread_card
node_thread_detail -->|"renders reply form"| node_comment_form
node_comment_form -->|"adds reply"| node_thread_actions
node_activity -->|"fetches activity"| node_user_actions
node_search -->|"searches users"| node_user_actions
node_search -->|"renders"| node_searchbar
node_search -->|"renders"| node_pagination
node_profile -->|"loads profile"| node_user_actions
node_profile -->|"renders"| node_profile_header
node_profile -->|"renders"| node_threads_tab
node_threads_tab -->|"loads user threads"| node_user_actions
node_threads_tab -->|"renders"| node_thread_card
node_user_actions -->|"connects to"| node_mongoose
node_user_actions -->|"queries"| node_user_model
node_user_actions -->|"populates"| node_community_model
node_user_actions -->|"queries"| node_thread_model
node_thread_actions -->|"connects to"| node_mongoose
node_thread_actions -->|"queries"| node_thread_model
node_thread_actions -->|"updates and populates"| node_user_model
node_thread_actions -->|"queries and updates"| node_community_model
node_community_actions -->|"connects to"| node_mongoose
node_community_actions -->|"queries and updates"| node_community_model
node_community_actions -->|"queries and deletes"| node_thread_model
node_community_actions -->|"queries and updates"| node_user_model
node_clerk_webhook -->|"invokes"| node_community_actions
node_communities -.->|"uses community data"| node_community_actions

click node_home "https://github.com/amerdoahmed/threads/blob/main/app/(root)/page.tsx"
click node_activity "https://github.com/amerdoahmed/threads/blob/main/app/(root)/activity/page.tsx"
click node_communities "https://github.com/amerdoahmed/threads/blob/main/app/(root)/communities/page.tsx"
click node_search "https://github.com/amerdoahmed/threads/blob/main/app/(root)/search/page.tsx"
click node_profile "https://github.com/amerdoahmed/threads/blob/main/app/(root)/profile/%5Bid%5D/page.tsx"
click node_thread_detail "https://github.com/amerdoahmed/threads/blob/main/app/(root)/thread/%5Bid%5D/page.tsx"
click node_thread_card "https://github.com/amerdoahmed/threads/blob/main/components/cards/ThreadCard.tsx"
click node_searchbar "https://github.com/amerdoahmed/threads/blob/main/components/shared/Searchbar.tsx"
click node_pagination "https://github.com/amerdoahmed/threads/blob/main/components/shared/Pagination.tsx"
click node_profile_header "https://github.com/amerdoahmed/threads/blob/main/components/shared/ProfileHeader.tsx"
click node_threads_tab "https://github.com/amerdoahmed/threads/blob/main/components/shared/ThreadsTab.tsx"
click node_onboarding "https://github.com/amerdoahmed/threads/blob/main/app/(auth)/onboarding/page.tsx"
click node_account_form "https://github.com/amerdoahmed/threads/blob/main/components/forms/AccountProfile.tsx"
click node_create_thread_page "https://github.com/amerdoahmed/threads/blob/main/app/(root)/create-thread/page.tsx"
click node_post_form "https://github.com/amerdoahmed/threads/blob/main/components/forms/PostThread.tsx"
click node_comment_form "https://github.com/amerdoahmed/threads/blob/main/components/forms/Comment.tsx"
click node_user_actions "https://github.com/amerdoahmed/threads/blob/main/lib/actions/user.actions.ts"
click node_thread_actions "https://github.com/amerdoahmed/threads/blob/main/lib/actions/thread.actions.ts"
click node_community_actions "https://github.com/amerdoahmed/threads/blob/main/lib/actions/community.actions.ts"
click node_user_model "https://github.com/amerdoahmed/threads/blob/main/lib/models/user.model.ts"
click node_thread_model "https://github.com/amerdoahmed/threads/blob/main/lib/models/thread.model.ts"
click node_community_model "https://github.com/amerdoahmed/threads/blob/main/lib/models/community.model.ts"
click node_mongoose "https://github.com/amerdoahmed/threads/blob/main/lib/mongoose.ts"
click node_upload_form_helper "https://github.com/amerdoahmed/threads/blob/main/lib/uploadthings.ts"
click node_upload_endpoint "https://github.com/amerdoahmed/threads/blob/main/app/api/uploadthing/core.ts"
click node_clerk_webhook "https://github.com/amerdoahmed/threads/blob/main/app/api/webhook/clerk/route.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_home,node_activity,node_communities,node_search,node_profile,node_thread_detail,node_thread_card,node_searchbar,node_pagination,node_profile_header,node_threads_tab,node_visitor toneBlue
class node_onboarding,node_account_form,node_create_thread_page,node_post_form,node_comment_form toneAmber
class node_user_actions,node_thread_actions,node_community_actions toneMint
class node_user_model,node_thread_model,node_community_model,node_mongoose,node_upload_form_helper,node_upload_endpoint,node_clerk_webhook toneRose
```

## Components

### User experience

- [Thread feed](https://github.com/amerdoahmed/threads/blob/main/app/(root)/page.tsx): `app/(root)/page.tsx`
- [Activity](https://github.com/amerdoahmed/threads/blob/main/app/(root)/activity/page.tsx): `app/(root)/activity/page.tsx`
- [Communities](https://github.com/amerdoahmed/threads/blob/main/app/(root)/communities/page.tsx): `app/(root)/communities/page.tsx`
- [Creator search](https://github.com/amerdoahmed/threads/blob/main/app/(root)/search/page.tsx): `app/(root)/search/page.tsx`
- [User profile](https://github.com/amerdoahmed/threads/blob/main/app/(root)/profile/%5Bid%5D/page.tsx): `app/(root)/profile/[id]/page.tsx`
- [Thread detail](https://github.com/amerdoahmed/threads/blob/main/app/(root)/thread/%5Bid%5D/page.tsx): `app/(root)/thread/[id]/page.tsx`
- [Thread card](https://github.com/amerdoahmed/threads/blob/main/components/cards/ThreadCard.tsx): `components/cards/ThreadCard.tsx`
- [Search input](https://github.com/amerdoahmed/threads/blob/main/components/shared/Searchbar.tsx): `components/shared/Searchbar.tsx`
- [Pagination](https://github.com/amerdoahmed/threads/blob/main/components/shared/Pagination.tsx): `components/shared/Pagination.tsx`
- [Profile header](https://github.com/amerdoahmed/threads/blob/main/components/shared/ProfileHeader.tsx): `components/shared/ProfileHeader.tsx`
- [Profile threads](https://github.com/amerdoahmed/threads/blob/main/components/shared/ThreadsTab.tsx): `components/shared/ThreadsTab.tsx`

### Profiles and authoring

- [Onboarding](https://github.com/amerdoahmed/threads/blob/main/app/(auth)/onboarding/page.tsx): `app/(auth)/onboarding/page.tsx`
- [Profile editor](https://github.com/amerdoahmed/threads/blob/main/components/forms/AccountProfile.tsx): `components/forms/AccountProfile.tsx`
- [Thread composer page](https://github.com/amerdoahmed/threads/blob/main/app/(root)/create-thread/page.tsx): `app/(root)/create-thread/page.tsx`
- [Thread composer](https://github.com/amerdoahmed/threads/blob/main/components/forms/PostThread.tsx): `components/forms/PostThread.tsx`
- [Reply form](https://github.com/amerdoahmed/threads/blob/main/components/forms/Comment.tsx): `components/forms/Comment.tsx`

### Domain operations

- [User operations](https://github.com/amerdoahmed/threads/blob/main/lib/actions/user.actions.ts): `lib/actions/user.actions.ts`
- [Thread operations](https://github.com/amerdoahmed/threads/blob/main/lib/actions/thread.actions.ts): `lib/actions/thread.actions.ts`
- [Community operations](https://github.com/amerdoahmed/threads/blob/main/lib/actions/community.actions.ts): `lib/actions/community.actions.ts`

### Persistence and integrations

- [User model](https://github.com/amerdoahmed/threads/blob/main/lib/models/user.model.ts): `lib/models/user.model.ts`
- [Thread model](https://github.com/amerdoahmed/threads/blob/main/lib/models/thread.model.ts): `lib/models/thread.model.ts`
- [Community model](https://github.com/amerdoahmed/threads/blob/main/lib/models/community.model.ts): `lib/models/community.model.ts`
- [MongoDB connection](https://github.com/amerdoahmed/threads/blob/main/lib/mongoose.ts): `lib/mongoose.ts`
- [Upload helper](https://github.com/amerdoahmed/threads/blob/main/lib/uploadthings.ts): `lib/uploadthings.ts`
- [Upload endpoint](https://github.com/amerdoahmed/threads/blob/main/app/api/uploadthing/core.ts): `app/api/uploadthing/core.ts`
- [Clerk webhook](https://github.com/amerdoahmed/threads/blob/main/app/api/webhook/clerk/route.ts): `app/api/webhook/clerk/route.ts`

### Other components

- **User**

## Connections

- User → Thread feed: opens feed (evidence: `app/(root)/page.tsx`)
- Thread feed → User operations: fetches user (evidence: `app/(root)/page.tsx`)
- Thread feed → Thread operations: fetches threads (evidence: `app/(root)/page.tsx`)
- Thread feed → Thread card: renders (evidence: `app/(root)/page.tsx`)
- User → Onboarding: sets up profile (evidence: `app/(auth)/onboarding/page.tsx`)
- Onboarding → Profile editor: renders (evidence: `app/(auth)/onboarding/page.tsx`)
- Profile editor → User operations: updates profile (evidence: `components/forms/AccountProfile.tsx`)
- Profile editor → Upload helper: uploads image (evidence: `components/forms/AccountProfile.tsx`)
- Upload helper → Upload endpoint: uses upload service (evidence: `lib/uploadthings.ts`)
- User → Thread composer page: starts thread (evidence: `app/(root)/create-thread/page.tsx`)
- Thread composer page → Thread composer: renders (evidence: `app/(root)/create-thread/page.tsx`)
- Thread composer → Thread operations: creates thread (evidence: `components/forms/PostThread.tsx`)
- Thread detail → Thread operations: loads thread (evidence: `app/(root)/thread/[id]/page.tsx`)
- Thread detail → User operations: loads user (evidence: `app/(root)/thread/[id]/page.tsx`)
- Thread detail → Thread card: renders thread (evidence: `app/(root)/thread/[id]/page.tsx`)
- Thread detail → Reply form: renders reply form (evidence: `app/(root)/thread/[id]/page.tsx`)
- Reply form → Thread operations: adds reply (evidence: `components/forms/Comment.tsx`)
- Activity → User operations: fetches activity (evidence: `app/(root)/activity/page.tsx`)
- Creator search → User operations: searches users (evidence: `app/(root)/search/page.tsx`)
- Creator search → Search input: renders (evidence: `app/(root)/search/page.tsx`)
- Creator search → Pagination: renders (evidence: `app/(root)/search/page.tsx`)
- User profile → User operations: loads profile (evidence: `app/(root)/profile/[id]/page.tsx`)
- User profile → Profile header: renders (evidence: `app/(root)/profile/[id]/page.tsx`)
- User profile → Profile threads: renders (evidence: `app/(root)/profile/[id]/page.tsx`)
- Profile threads → User operations: loads user threads (evidence: `components/shared/ThreadsTab.tsx`)
- Profile threads → Thread card: renders (evidence: `components/shared/ThreadsTab.tsx`)
- User operations → MongoDB connection: connects to (evidence: `lib/actions/user.actions.ts`)
- User operations → User model: queries (evidence: `lib/actions/user.actions.ts`)
- User operations → Community model: populates (evidence: `lib/actions/user.actions.ts`)
- User operations → Thread model: queries (evidence: `lib/actions/user.actions.ts`)
- Thread operations → MongoDB connection: connects to (evidence: `lib/actions/thread.actions.ts`)
- Thread operations → Thread model: queries (evidence: `lib/actions/thread.actions.ts`)
- Thread operations → User model: updates and populates (evidence: `lib/actions/thread.actions.ts`)
- Thread operations → Community model: queries and updates (evidence: `lib/actions/thread.actions.ts`)
- Community operations → MongoDB connection: connects to (evidence: `lib/actions/community.actions.ts`)
- Community operations → Community model: queries and updates (evidence: `lib/actions/community.actions.ts`)
- Community operations → Thread model: queries and deletes (evidence: `lib/actions/community.actions.ts`)
- Community operations → User model: queries and updates (evidence: `lib/actions/community.actions.ts`)
- Clerk webhook → Community operations: invokes (evidence: `app/api/webhook/clerk/route.ts`)
- Communities → Community operations: uses community data
