# raedinkhaled/casbahconnect-next architecture

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

- Interactive diagram: https://gitdiagram.com/raedinkhaled/casbahconnect-next
- Repository: https://github.com/raedinkhaled/casbahconnect-next

## Overview

Casbah Connect is a Stack Overflow–style developer Q&A platform. Visitors browse and search questions, open a question, then sign in to ask or answer, vote, save, and build a profile; passwordless email and a read-only demo identity are alternate entry modes. Server actions enforce identity and write permissions before accessing MongoDB. The README documents broader search, tag, profile, reputation, and theme capabilities; several routes and action implementations were not sampled, so those links are documented rather than inferred from imports.

Main entry points: [`lib/actions/question.action.ts`](https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/actions/question.action.ts) (Question actions), [`lib/actions/user.action.ts`](https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/actions/user.action.ts) (User actions), [`lib/auth.ts`](https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/auth.ts) (Authentication), [`lib/auth-user.ts`](https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/auth-user.ts) (Session and user guard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_discovery["Browse and discovery"]
  node_home["Question feed<br/>[page.tsx]"]
  node_questiondetail["Question detail<br/>[page.tsx]"]
  node_tagbrowse["Tag browsing<br/>[page.tsx]"]
  node_community["Community<br/>[page.tsx]"]
  node_searchui["Global search<br/>[GlobalSearch.tsx]"]
  node_searchapi["Search endpoint<br/>[route.ts]"]
end

subgraph group_participation["Q&amp;A participation"]
  node_questionform["Question form<br/>[QuestionForm.tsx]"]
  node_answerform["Answer form<br/>[AnswerForm.tsx]"]
  node_votes["Voting controls<br/>[Votes.tsx]"]
end

subgraph group_identity["Identity and profiles"]
  node_auth["Authentication<br/>[auth.ts]"]
  node_signin["Sign-in form<br/>[SignInForm.tsx]"]
  node_sessionuser["Session and user guard<br/>[auth-user.ts]"]
  node_profile["Profile pages<br/>[page.tsx]"]
  node_profileform["Profile editing<br/>[ProfileForm.tsx]"]
  node_demo["Demo identity<br/>[demo.ts]"]
end

subgraph group_services["Application services"]
  node_questionactions["Question actions<br/>[question.action.ts]"]
  node_answeractions["Answer actions<br/>[answer.action.ts]"]
  node_interactionactions["Interaction actions"]
  node_useractions["User actions<br/>[user.action.ts]"]
  node_tagactions["Tag actions<br/>[tag.actions.ts]"]
  node_generalactions["Search actions<br/>[general.action.ts]"]
end

subgraph group_persistence["Persistence"]
  node_questions[("Question records<br/>[question.model.ts]")]
  node_answers[("Answer records<br/>[answer.model.ts]")]
  node_users[("User records<br/>[user.model.ts]")]
  node_tags[("Tag records<br/>[tag.model.ts]")]
  node_interactions[("Interaction records")]
end

node_visitor(("Visitor"))
node_mongodb[("MongoDB")]
node_email["Email delivery"]

node_visitor -->|"browses"| node_home
node_home -->|"loads feed"| node_questionactions
node_questionactions -->|"queries"| node_questions
node_visitor -->|"opens question"| node_questiondetail
node_questiondetail -->|"loads question"| node_questionactions
node_visitor -->|"browses tags"| node_tagbrowse
node_tagbrowse -->|"loads tags"| node_tagactions
node_visitor -->|"browses members"| node_community
node_community -->|"loads users"| node_useractions
node_visitor -->|"searches"| node_searchui
node_searchui -->|"requests results"| node_searchapi
node_searchapi -->|"dispatches search"| node_generalactions
node_visitor -->|"starts sign-in"| node_signin
node_signin -->|"authenticates"| node_auth
node_auth -->|"sends magic link"| node_email
node_auth -->|"adapter account"| node_users
node_auth -->|"issues demo identity"| node_demo
node_auth -->|"uses adapter"| node_mongodb
node_questiondetail -->|"renders form"| node_answerform
node_questionform -->|"creates question"| node_questionactions
node_questiondetail -->|"renders controls"| node_votes
node_votes -->|"votes question"| node_questionactions
node_votes -->|"votes answer"| node_answeractions
node_votes -->|"records interaction"| node_interactionactions
node_answerform -.->|"submits answer"| node_answeractions
node_questionactions -->|"checks writer"| node_sessionuser
node_useractions -->|"checks writer"| node_sessionuser
node_questionactions -->|"creates and reads"| node_questions
node_questionactions -->|"uses answers"| node_answers
node_questionactions -->|"reads interactions"| node_interactions
node_questionactions -->|"updates reputation"| node_users
node_questionactions -->|"populates tags"| node_tags
node_useractions -->|"queries profiles"| node_users
node_useractions -->|"queries activity"| node_questions
node_useractions -->|"queries activity"| node_answers
node_profile -->|"loads profile"| node_useractions
node_profileform -.->|"updates profile"| node_useractions
node_useractions -->|"resolves identity"| node_sessionuser
node_sessionuser -->|"reads session"| node_auth
node_sessionuser -->|"resolves account"| node_users
node_sessionuser -->|"connects for lookup"| node_mongodb
node_visitor -->|"asks question"| node_questionform
node_visitor -->|"posts answer"| node_answerform
node_visitor -->|"votes content"| node_votes
node_visitor -->|"views profiles"| node_profile

click node_home "https://github.com/raedinkhaled/casbahconnect-next/blob/main/app/(root)/(home)/page.tsx"
click node_questiondetail "https://github.com/raedinkhaled/casbahconnect-next/blob/main/app/(root)/question/%5Bid%5D/page.tsx"
click node_tagbrowse "https://github.com/raedinkhaled/casbahconnect-next/blob/main/app/(root)/tags/page.tsx"
click node_community "https://github.com/raedinkhaled/casbahconnect-next/blob/main/app/(root)/community/page.tsx"
click node_searchui "https://github.com/raedinkhaled/casbahconnect-next/blob/main/components/shared/search/GlobalSearch.tsx"
click node_searchapi "https://github.com/raedinkhaled/casbahconnect-next/blob/main/app/api/search/route.ts"
click node_questionform "https://github.com/raedinkhaled/casbahconnect-next/blob/main/components/forms/QuestionForm.tsx"
click node_answerform "https://github.com/raedinkhaled/casbahconnect-next/blob/main/components/forms/AnswerForm.tsx"
click node_votes "https://github.com/raedinkhaled/casbahconnect-next/blob/main/components/shared/Votes.tsx"
click node_questionactions "https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/actions/question.action.ts"
click node_answeractions "https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/actions/answer.action.ts"
click node_interactionactions "https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/actions/interaction.action.ts"
click node_useractions "https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/actions/user.action.ts"
click node_tagactions "https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/actions/tag.actions.ts"
click node_generalactions "https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/actions/general.action.ts"
click node_auth "https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/auth.ts"
click node_signin "https://github.com/raedinkhaled/casbahconnect-next/blob/main/components/auth/SignInForm.tsx"
click node_sessionuser "https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/auth-user.ts"
click node_profile "https://github.com/raedinkhaled/casbahconnect-next/blob/main/app/(root)/profile/%5Bid%5D/page.tsx"
click node_profileform "https://github.com/raedinkhaled/casbahconnect-next/blob/main/components/forms/ProfileForm.tsx"
click node_questions "https://github.com/raedinkhaled/casbahconnect-next/blob/main/database/question.model.ts"
click node_answers "https://github.com/raedinkhaled/casbahconnect-next/blob/main/database/answer.model.ts"
click node_users "https://github.com/raedinkhaled/casbahconnect-next/blob/main/database/user.model.ts"
click node_tags "https://github.com/raedinkhaled/casbahconnect-next/blob/main/database/tag.model.ts"
click node_interactions "https://github.com/raedinkhaled/casbahconnect-next/blob/main/database/interaction.model.ts"
click node_demo "https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/demo.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_questiondetail,node_tagbrowse,node_community,node_searchui,node_searchapi toneBlue
class node_questionform,node_answerform,node_votes,node_mongodb toneAmber
class node_auth,node_signin,node_sessionuser,node_profile,node_profileform,node_demo toneMint
class node_questionactions,node_answeractions,node_interactionactions,node_useractions,node_tagactions,node_generalactions toneRose
class node_questions,node_answers,node_users,node_tags,node_interactions,node_visitor,node_email toneIndigo
```

## Components

### Browse and discovery

- [Question feed](https://github.com/raedinkhaled/casbahconnect-next/blob/main/app/(root)/(home)/page.tsx): `app/(root)/(home)/page.tsx`
- [Question detail](https://github.com/raedinkhaled/casbahconnect-next/blob/main/app/(root)/question/%5Bid%5D/page.tsx): `app/(root)/question/[id]/page.tsx`
- [Tag browsing](https://github.com/raedinkhaled/casbahconnect-next/blob/main/app/(root)/tags/page.tsx): `app/(root)/tags/page.tsx`
- [Community](https://github.com/raedinkhaled/casbahconnect-next/blob/main/app/(root)/community/page.tsx): `app/(root)/community/page.tsx`
- [Global search](https://github.com/raedinkhaled/casbahconnect-next/blob/main/components/shared/search/GlobalSearch.tsx): `components/shared/search/GlobalSearch.tsx`
- [Search endpoint](https://github.com/raedinkhaled/casbahconnect-next/blob/main/app/api/search/route.ts): `app/api/search/route.ts`

### Q&A participation

- [Question form](https://github.com/raedinkhaled/casbahconnect-next/blob/main/components/forms/QuestionForm.tsx): `components/forms/QuestionForm.tsx`
- [Answer form](https://github.com/raedinkhaled/casbahconnect-next/blob/main/components/forms/AnswerForm.tsx): `components/forms/AnswerForm.tsx`
- [Voting controls](https://github.com/raedinkhaled/casbahconnect-next/blob/main/components/shared/Votes.tsx): `components/shared/Votes.tsx`

### Identity and profiles

- [Authentication](https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/auth.ts): `lib/auth.ts`
- [Sign-in form](https://github.com/raedinkhaled/casbahconnect-next/blob/main/components/auth/SignInForm.tsx): `components/auth/SignInForm.tsx`
- [Session and user guard](https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/auth-user.ts): `lib/auth-user.ts`
- [Profile pages](https://github.com/raedinkhaled/casbahconnect-next/blob/main/app/(root)/profile/%5Bid%5D/page.tsx): `app/(root)/profile/[id]/page.tsx`
- [Profile editing](https://github.com/raedinkhaled/casbahconnect-next/blob/main/components/forms/ProfileForm.tsx): `components/forms/ProfileForm.tsx`
- [Demo identity](https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/demo.ts): `lib/demo.ts`

### Application services

- [Question actions](https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/actions/question.action.ts): `lib/actions/question.action.ts`
- [Answer actions](https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/actions/answer.action.ts): `lib/actions/answer.action.ts`
- [Interaction actions](https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/actions/interaction.action.ts): `lib/actions/interaction.action.ts`
- [User actions](https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/actions/user.action.ts): `lib/actions/user.action.ts`
- [Tag actions](https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/actions/tag.actions.ts): `lib/actions/tag.actions.ts`
- [Search actions](https://github.com/raedinkhaled/casbahconnect-next/blob/main/lib/actions/general.action.ts): `lib/actions/general.action.ts`

### Persistence

- [Question records](https://github.com/raedinkhaled/casbahconnect-next/blob/main/database/question.model.ts): `database/question.model.ts`
- [Answer records](https://github.com/raedinkhaled/casbahconnect-next/blob/main/database/answer.model.ts): `database/answer.model.ts`
- [User records](https://github.com/raedinkhaled/casbahconnect-next/blob/main/database/user.model.ts): `database/user.model.ts`
- [Tag records](https://github.com/raedinkhaled/casbahconnect-next/blob/main/database/tag.model.ts): `database/tag.model.ts`
- [Interaction records](https://github.com/raedinkhaled/casbahconnect-next/blob/main/database/interaction.model.ts): `database/interaction.model.ts`

### Other components

- **Visitor**
- **MongoDB**
- **Email delivery**

## Connections

- Visitor → Question feed: browses (evidence: `README.md`)
- Question feed → Question actions: loads feed (evidence: `app/(root)/(home)/page.tsx`)
- Question actions → Question records: queries (evidence: `lib/actions/question.action.ts`)
- Visitor → Question detail: opens question (evidence: `README.md`)
- Question detail → Question actions: loads question (evidence: `app/(root)/question/[id]/page.tsx`)
- Visitor → Tag browsing: browses tags (evidence: `README.md`)
- Tag browsing → Tag actions: loads tags (evidence: `app/(root)/tags/page.tsx`)
- Visitor → Community: browses members (evidence: `README.md`)
- Community → User actions: loads users (evidence: `app/(root)/community/page.tsx`)
- Visitor → Global search: searches (evidence: `README.md`)
- Global search → Search endpoint: requests results (evidence: `app/api/search/route.ts`)
- Search endpoint → Search actions: dispatches search (evidence: `app/api/search/route.ts`)
- Visitor → Sign-in form: starts sign-in (evidence: `README.md`)
- Sign-in form → Authentication: authenticates (evidence: `lib/auth.ts`)
- Authentication → Email delivery: sends magic link (evidence: `README.md`)
- Authentication → User records: adapter account (evidence: `lib/auth.ts`)
- Authentication → Demo identity: issues demo identity (evidence: `lib/auth.ts`)
- Authentication → MongoDB: uses adapter (evidence: `lib/auth.ts`)
- Question detail → Answer form: renders form (evidence: `app/(root)/question/[id]/page.tsx`)
- Question form → Question actions: creates question (evidence: `components/forms/QuestionForm.tsx`)
- Question detail → Voting controls: renders controls (evidence: `app/(root)/question/[id]/page.tsx`)
- Voting controls → Question actions: votes question (evidence: `components/shared/Votes.tsx`)
- Voting controls → Answer actions: votes answer (evidence: `components/shared/Votes.tsx`)
- Voting controls → Interaction actions: records interaction (evidence: `components/shared/Votes.tsx`)
- Answer form → Answer actions: submits answer
- Question actions → Session and user guard: checks writer (evidence: `lib/actions/question.action.ts`)
- User actions → Session and user guard: checks writer (evidence: `lib/actions/user.action.ts`)
- Question actions → Question records: creates and reads (evidence: `lib/actions/question.action.ts`)
- Question actions → Answer records: uses answers (evidence: `lib/actions/question.action.ts`)
- Question actions → Interaction records: reads interactions (evidence: `lib/actions/question.action.ts`)
- Question actions → User records: updates reputation (evidence: `lib/actions/question.action.ts`)
- Question actions → Tag records: populates tags (evidence: `lib/actions/question.action.ts`)
- User actions → User records: queries profiles (evidence: `lib/actions/user.action.ts`)
- User actions → Question records: queries activity (evidence: `lib/actions/user.action.ts`)
- User actions → Answer records: queries activity (evidence: `lib/actions/user.action.ts`)
- Profile pages → User actions: loads profile (evidence: `app/(root)/profile/[id]/page.tsx`)
- Profile editing → User actions: updates profile
- User actions → Session and user guard: resolves identity (evidence: `lib/actions/user.action.ts`)
- Session and user guard → Authentication: reads session (evidence: `lib/auth-user.ts`)
- Session and user guard → User records: resolves account (evidence: `lib/auth-user.ts`)
- Session and user guard → MongoDB: connects for lookup (evidence: `lib/auth-user.ts`)
- Visitor → Question form: asks question (evidence: `README.md`)
- Visitor → Answer form: posts answer (evidence: `README.md`)
- Visitor → Voting controls: votes content (evidence: `README.md`)
- Visitor → Profile pages: views profiles (evidence: `README.md`)
