# ablamalki/devflow_nextjs architecture

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

- Interactive diagram: https://gitdiagram.com/ablamalki/devflow_nextjs
- Repository: https://github.com/ablamalki/devflow_nextjs

## Overview

##### Main Architecture Components

A. Frontend Layer:
- Divide into App Router sections:
- Auth Routes /(auth)
- Main Routes /(root)
- API Routes /api
- Component hierarchy:
- Shared Components
- UI Components
- Forms
- Cards

B. Middleware Layer:
- In the middle
- Authentication/authorization flow
- Theme provider context

C. Backend/Data Layer:
- At the bottom
- MongoDB models:
- User
- Question
- Answer
- Tag
- Interaction

##### Component Relationships

A. Client-Side Flow:
- User interaction flow through components
- State management via Context API
- Client-side routing paths

B. Server-Side Flow:
- API routes communication
- Database interactions
- Authentication flow

##### Specific Implementation Details

Technical aspects:

A. Next.js App Router Structure:
- (auth) - Authentication routes
- (root) - Main application routes
- api - API endpoints

B. Data Flow Patterns:
- Server Actions (lib/actions)
- API Routes
- Database Operations

##### External Services Integration

Connections to:
- ChatGPT API integration
- Authentication service
- MongoDB database
- Webhook handlers

##### Specific Elements

A. Components:
- Relationship between shared components
- Reusable UI components
- Demonstrate form handling flow

B. Data Models:
- Relationships between models
- Field-level connections
- Interaction patterns

C. Authentication Flow:
- Sign-in/Sign-up processes
- Protected routes
- Authorization checks

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Frontend Layer"
        direction TB
        AuthRoutes["/(auth) Routes"]
        MainRoutes["/(root) Routes"]
        APIRoutes["/api Routes"]
        
        subgraph "Components"
            direction TB
            SharedComps["Shared Components"]:::component
            UIComps["UI Components"]:::component
            Forms["Forms"]:::component
            Cards["Cards"]:::component
            
            NavBar["Navbar"]:::component
            LeftSide["LeftSidebar"]:::component
            RightSide["RightSidebar"]:::component
            ThemeSwitch["Theme Switcher"]:::component
            GlobalSearch["Global Search"]:::component
            LocalSearch["Local Search"]:::component
        end
        
        subgraph "Auth Routes"
            SignIn["Sign In"]:::page
            SignUp["Sign Up"]:::page
        end
        
        subgraph "Main Routes"
            Home["Home"]:::page
            Questions["Questions"]:::page
            Profile["Profile"]:::page
            Community["Community"]:::page
        end
    end
    
    subgraph "Middleware Layer"
        AuthMiddleware["Auth Middleware"]:::middleware
        ThemeProvider["Theme Provider"]:::context
    end
    
    subgraph "Backend Layer"
        direction TB
        subgraph "Server Actions"
            QuestionActions["Question Actions"]:::action
            AnswerActions["Answer Actions"]:::action
            UserActions["User Actions"]:::action
            TagActions["Tag Actions"]:::action
            InteractionActions["Interaction Actions"]:::action
        end
        
        subgraph "API Routes"
            ChatGPTAPI["ChatGPT API"]:::api
            WebhookHandler["Webhook Handler"]:::api
        end
        
        subgraph "Database Models"
            UserModel["User Model"]:::model
            QuestionModel["Question Model"]:::model
            AnswerModel["Answer Model"]:::model
            TagModel["Tag Model"]:::model
            InteractionModel["Interaction Model"]:::model
        end
    end
    
    %% Connections
    AuthRoutes --> AuthMiddleware
    MainRoutes --> AuthMiddleware
    APIRoutes --> AuthMiddleware
    AuthMiddleware --> ServerActions
    
    ServerActions --> DatabaseModels
    APIRoutes --> ExternalServices
    
    %% External Services
    ExternalServices[("External Services")]:::external
    
    %% Styles
    classDef page fill:#2563eb,color:white
    classDef component fill:#4ade80,color:black
    classDef middleware fill:#a855f7,color:white
    classDef context fill:#84cc16,color:black
    classDef action fill:#06b6d4,color:white
    classDef api fill:#f97316,color:white
    classDef model fill:#eab308,color:black
    classDef external fill:#ef4444,color:white
    
    %% Click Events
    click SignIn "https://github.com/AblaMalki/devflow_nextjs/blob/main//app/(auth)/sign-in/[[...sign-in]]/page.tsx"
    click SignUp "https://github.com/AblaMalki/devflow_nextjs/blob/main//app/(auth)/sign-up/[[...sign-up]]/page.tsx"
    click Home "https://github.com/AblaMalki/devflow_nextjs/blob/main//app/(root)/(home)/page.tsx"
    click Questions "https://github.com/AblaMalki/devflow_nextjs/tree/main//app/(root)/question"
    click Profile "https://github.com/AblaMalki/devflow_nextjs/tree/main//app/(root)/profile"
    click Community "https://github.com/AblaMalki/devflow_nextjs/blob/main//app/(root)/community/page.tsx"
    click ChatGPTAPI "https://github.com/AblaMalki/devflow_nextjs/blob/main//app/api/chatgpt/route.ts"
    click WebhookHandler "https://github.com/AblaMalki/devflow_nextjs/blob/main//app/api/webhook/route.ts"
    click UserModel "https://github.com/AblaMalki/devflow_nextjs/blob/main//database/user.model.ts"
    click QuestionModel "https://github.com/AblaMalki/devflow_nextjs/blob/main//database/question.model.ts"
    click AnswerModel "https://github.com/AblaMalki/devflow_nextjs/blob/main//database/answer.model.ts"
    click TagModel "https://github.com/AblaMalki/devflow_nextjs/blob/main//database/tag.model.ts"
    click InteractionModel "https://github.com/AblaMalki/devflow_nextjs/blob/main//database/interaction.model.ts"
    click QuestionActions "https://github.com/AblaMalki/devflow_nextjs/blob/main//lib/actions/question.action.ts"
    click AnswerActions "https://github.com/AblaMalki/devflow_nextjs/blob/main//lib/actions/answer.actions.ts"
    click UserActions "https://github.com/AblaMalki/devflow_nextjs/blob/main//lib/actions/user.action.ts"
    click TagActions "https://github.com/AblaMalki/devflow_nextjs/blob/main//lib/actions/tag.actions.ts"
    click InteractionActions "https://github.com/AblaMalki/devflow_nextjs/blob/main//lib/actions/interaction.action.ts"
    click Cards "https://github.com/AblaMalki/devflow_nextjs/tree/main//components/cards"
    click Forms "https://github.com/AblaMalki/devflow_nextjs/tree/main//components/forms"
    click SharedComps "https://github.com/AblaMalki/devflow_nextjs/tree/main//components/shared"
    click UIComps "https://github.com/AblaMalki/devflow_nextjs/tree/main//components/ui"
    click ThemeProvider "https://github.com/AblaMalki/devflow_nextjs/blob/main//context/ThemeProvider.tsx"
    click ThemeSwitch "https://github.com/AblaMalki/devflow_nextjs/blob/main//components/shared/navbar/Theme.tsx"
    click GlobalSearch "https://github.com/AblaMalki/devflow_nextjs/blob/main//components/shared/search/GlobalSearch.tsx"
    click LocalSearch "https://github.com/AblaMalki/devflow_nextjs/blob/main//components/shared/search/LocalSearchbar.tsx"
    click AuthMiddleware "https://github.com/AblaMalki/devflow_nextjs/blob/main//middleware.ts"
    click NavBar "https://github.com/AblaMalki/devflow_nextjs/blob/main//components/shared/navbar/Navbar.tsx"
    click LeftSide "https://github.com/AblaMalki/devflow_nextjs/blob/main//components/shared/LeftSidebar.tsx"
    click RightSide "https://github.com/AblaMalki/devflow_nextjs/blob/main//components/shared/RightSidebar.tsx"
```
