Skip to content
osamaayubPublic

About

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

DevFlow

DevFlow Logo Status

A modern, community-driven Q&A platform for developers β€” reimagined with the latest web technologies.

Next.js React TypeScript MongoDB Tailwind CSS License: MIT

Documentation β€’ Report Bug β€’ Request Feature

πŸš€ Project Status: Currently in active development. Core features are being implemented. Check back soon for the live demo!


✨ Features

πŸ’¬ Ask & Answer

Post questions, write detailed answers, and help others grow together.

πŸ” Powerful Search

Full-text search with intelligent tag and category filtering.

🏷️ Tagging System

Organize content with technology tags (React, JavaScript, TypeScript, etc.).

⭐ Saved Questions

Save or remove questions and browse saved questions in your collection.

πŸ‘ Voting

Upvote or downvote questions and answers with optimistic UI updates.

πŸ” Authentication

Sign in with Google, GitHub, or email via NextAuth.

πŸŒ“ Dark / Light Theme

Seamless theme switching for comfortable viewing.

πŸ“± Responsive Design

Optimized for desktop, tablet, and mobile devices.

πŸ‘₯ Community

Browse members, filter by reputation or popularity, and view each member's questions.

πŸ‘€ User Profiles

View responsive profiles with bio, location, portfolio, activity stats, and paginated questions and answers. Users can edit their profile details.

πŸ”₯ Hot Network & Popular Tags

Right sidebar highlights top-voted questions and the most-used tags.

✍️ Rich Editor

Markdown editor (MDXEditor, loaded client-side only) for questions and answers, with syntax-highlighted code blocks rendered via Bright.

🧭 Filters & Pagination

Shared filter components and pagination across home, tags, tag details, collection, community, and answers.

πŸ“Š Structured Logging

Request and error logging with Pino for debugging and monitoring.

πŸ€– AI-Powered Answers

Generate intelligent answers using OpenAI integration.


πŸ› οΈ Tech Stack

Layer Technology
Frontend Next.js 16 (App Router, Server Components, Server Actions) β€’ React 19
Language TypeScript
Database MongoDB via Mongoose 8
Auth NextAuth.js v5 (Google, GitHub, Credentials)
Styling Tailwind CSS 4 β€’ shadcn/ui β€’ Radix UI β€’ Lucide
Forms & Validation React Hook Form β€’ Zod
Editor MDX Editor β€’ next-mdx-remote β€’ Bright
AI OpenAI via Vercel AI SDK
Logging Pino

πŸš€ Quick Start

Prerequisites

βœ“ Node.js β‰₯ 22.13
βœ“ Yarn (via Corepack: `corepack enable`)
βœ“ MongoDB (local or Atlas)

Installation

# 1️⃣ Clone the repository
git clone https://github.com/osamaayub/DevFlow.git
cd DevFlow

# 2️⃣ Install dependencies (also applies patches/ via patch-package)
yarn install

# 3️⃣ Create a .env.local file in the project root
#    and add the variables listed below

# 4️⃣ At minimum set:
# MONGODB_URI, AUTH_SECRET (OAuth and OpenAI keys are optional)

# 5️⃣ Start development server
yarn dev

# 6️⃣ Open http://localhost:3000 in your browser πŸŽ‰

πŸ”§ Environment Variables

πŸ“ Note: Env files are loaded per environment and are git-ignored for security.

Required Variables

Variable Description Example
MONGODB_URI MongoDB connection string mongodb+srv://user:[email protected]/devflow
AUTH_SECRET NextAuth encryption key Generate with: npx auth secret
OPENAI_API_KEY OpenAI API key for AI answers Get from OpenAI Platform

OAuth Providers (Optional)

Variable Provider How to Get
AUTH_GITHUB_ID GitHub OAuth GitHub OAuth Settings
AUTH_GITHUB_SECRET GitHub OAuth GitHub OAuth Settings
AUTH_GOOGLE_ID Google OAuth Google Cloud Console
AUTH_GOOGLE_SECRET Google OAuth Google Cloud Console

Optional Variables

Variable Default Values
LOG_LEVEL debug (dev) / info (prod) debug, info, warn, error
NEXTAUTH_URL Auto-detected (trustHost) Your site URL, e.g. http://localhost:3000
NEXT_PUBLIC_API_BASE_URL https://$VERCEL_URL on Vercel, otherwise localhost Base URL used by the API client in lib/api.ts

πŸ“‹ Available Scripts

# Development
yarn dev          # Start dev server (webpack)

# Production
yarn build        # Create optimized production build
yarn start        # Run production server

# Code Quality
yarn lint         # Run ESLint checks

πŸ—οΈ Development Status

βœ… Completed

  • Project setup with Next.js 16 & TypeScript
  • MongoDB & Mongoose integration with multiple models
  • NextAuth.js authentication (Google, GitHub, Email/Password)
  • Complete database models (Questions, Answers, Users, Tags, Accounts, Collections, Interactive, Votes, QuestionView, TagQuestion)
  • Server actions for CRUD operations (questions, answers, tags, auth)
  • Tailwind CSS & component styling with shadcn/ui
  • Dark/Light theme support with context provider
  • Rich text editor with MDX support
  • Tag management system with tag-question relationships
  • Search functionality with filtering
  • Pagination system
  • Error handling with custom error handler
  • Validation schemas with Zod
  • AI Answer API endpoint with OpenAI integration
  • API client functions and centralized route constants
  • Core UI pages (home, sign-in, sign-up, ask-question, question details, tags, collections)
  • React components (forms, cards, navigation, editor, search, filters, shared utilities)
  • User authentication flow (sign up, sign in, OAuth)
  • Question creation and editing
  • Save and remove questions with a stateful saved-star indicator
  • Collection page listing the signed-in user's saved questions
  • Answer creation
  • Question view tracking
  • Responsive design across implemented pages
  • Local search bar with filtering
  • Navigation sidebar and mobile navigation
  • Theme toggle component
  • User avatar components
  • Relative time display
  • Toast notifications with Sonner
  • Form validation with React Hook Form
  • Database connection management
  • Structured logging with Pino
  • API route handlers for users, accounts, auth, and AI
  • OAuth callback handling and user account creation
  • Password hashing with bcrypt
  • Username generation for OAuth users
  • Session management and JWT callbacks
  • MongoDB transaction support for complex operations
  • Tag processing and helper functions
  • Question filtering (newest, unanswered, popular)
  • URL utilities and helpers
  • AI Answer UI integration (API implemented, UI Implemented)
  • Vote system (upvotes/downvotes) for questions and answers with optimistic updates
  • Home filters (newest, recommended, frequent, unanswered)
  • Shared filter component for tags, collection, community, and answers
  • Pagination for questions, tags, tag details, answers, collection, and community
  • Tag details page
  • Community page with search, filters, and member details page
  • User profiles with editable profile details, activity tabs, statistics, and pagination
  • Right sidebar with hot questions and popular tags
  • Back button across pages
  • MDX editor loaded client-side only (fixes "This page couldn't load" on ask-question and question details)
  • CI workflow (lint, type-check, build) and Docker image publishing to GHCR

🚧 In Progress

  • Jobs page implementation (placeholder exists)
  • Question deletion UI (deleteQuestion action exists)

πŸ“‹ Planned

  • Interaction tracking - Schema exists, implementation pending
  • Answer editing and deletion
  • User management actions
  • Live demo deployment
  • Admin dashboard
  • Real-time notifications
  • Advanced analytics and reporting
  • Community features (comments, discussions)
  • Badge system and gamification
  • API rate limiting
  • Additional OAuth providers
  • Enhanced search algorithms
  • Performance optimizations
  • Additional unit and integration tests

πŸ“ Project Structure

DevFlow/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/                         # Routes only: thin pages, layouts, API handlers
β”‚   β”‚   β”œβ”€β”€ (auth)/                  # sign-in, sign-up
β”‚   β”‚   β”œβ”€β”€ (root)/                  # home, ask-question, questions/[id], tags, community, ...
β”‚   β”‚   β”œβ”€β”€ api/                     # REST endpoints (accounts, users, ai/answers, auth)
β”‚   β”‚   β”œβ”€β”€ layout.tsx
β”‚   β”‚   └── Providers.tsx
β”‚   β”œβ”€β”€ features/                    # Vertical slices: one folder per domain
β”‚   β”‚   β”œβ”€β”€ answers/                 # actions.ts + components/ (AnswerForm, AnswerCard, AllAnswers)
β”‚   β”‚   β”œβ”€β”€ auth/                    # actions.ts, sign-out.action.ts + components/ (AuthForm, SocialAuthForm)
β”‚   β”‚   β”œβ”€β”€ collections/             # actions.ts (saved questions)
β”‚   β”‚   β”œβ”€β”€ community/               # actions.ts + components/ (UserCard, CommunityMemberProfile)
β”‚   β”‚   β”œβ”€β”€ questions/               # actions.ts + components/ (QuestionForm, QuestionCard, SaveQuestion)
β”‚   β”‚   β”œβ”€β”€ tags/                    # actions.ts, tag-helpers.ts + components/ (TagCards)
β”‚   β”‚   β”œβ”€β”€ users/                    # actions.ts + components/ (profile, activity, and profile editing)
β”‚   β”‚   └── votes/                    # actions.ts, vote-state.ts, components/, hooks/useVote.ts
β”‚   β”œβ”€β”€ server/                      # Server-only infrastructure (never imported by client code)
β”‚   β”‚   β”œβ”€β”€ auth.ts                  # NextAuth configuration
β”‚   β”‚   β”œβ”€β”€ action.ts                # Validate + authorize + connect wrapper for server actions
β”‚   β”‚   β”œβ”€β”€ errors/                  # HTTP error classes, error handler
β”‚   β”‚   └── db/                      # connect.ts, models/, schemas/ (guarded by "server-only")
β”‚   β”œβ”€β”€ shared/                      # Client-safe building blocks used across features
β”‚   β”‚   β”œβ”€β”€ api/                     # Typed fetch client for the REST endpoints
β”‚   β”‚   β”œβ”€β”€ components/              # ui/ (shadcn), common/, editor/, filters/, navigation/, search/
β”‚   β”‚   β”œβ”€β”€ constants/
β”‚   β”‚   β”œβ”€β”€ context/                 # Theme context
β”‚   β”‚   β”œβ”€β”€ lib/                     # utils, url, validation (zod), logger
β”‚   β”‚   └── types/
β”‚   └── proxy.ts                     # Request proxy: forwards the question filter header
β”œβ”€β”€ patches/                         # patch-package patches (next-themes)
β”œβ”€β”€ public/                          # Static assets
β”œβ”€β”€ .github/workflows/               # CI and deploy workflows
└── Dockerfile                       # Multi-stage standalone build

Dependency rules

  • app β†’ features β†’ shared; server is used by app and feature actions.ts, never by client components.
  • A feature is imported only through its public surface: @/features/<name>/components or @/features/<name>/actions. Features don't reach into each other's internals.
  • Relative imports stay inside one area; anything crossing areas uses the @/ alias (@/* β†’ src/*).

🌐 API Reference

All responses follow the standard envelope format:

{ "success": true, "data": {...}, "statusCode": 200 }

Note: Questions, Answers, and Tags use Server Actions instead of REST API endpoints for better performance and type safety.

πŸ‘₯ Users

Method Endpoint Description
GET /api/users List all users
POST /api/users Create new user (201)
GET /api/users/:id Get user by ID
PATCH /api/users/:id Update user
DELETE /api/users/:id Delete user
POST /api/users/email Get user by email

πŸ” Accounts

Method Endpoint Description
GET /api/accounts List all accounts
POST /api/accounts Create new account
GET /api/accounts/:id Get account by ID
PATCH /api/accounts/:id Update account
DELETE /api/accounts/:id Delete account
POST /api/accounts/provider Get account by provider

πŸ” Authentication

Method Endpoint Description
GET/POST /api/auth/[...nextauth] NextAuth.js handler (Google, GitHub, Credentials)

πŸ€– AI

Method Endpoint Description
POST /api/ai/answers Generate AI-powered answers with OpenAI

⚑ Server Actions

Questions, Answers, Tags, Votes, Collections, and Community are handled via Server Actions instead of REST API:

Feature Action Description
Questions createQuestion Create new question with tags
editQuestion Edit existing question
getQuestion Get single question by ID
getQuestions Get paginated questions with search and filters
getHotQuestions Get top questions for the right sidebar
incrementQuestionViews Track question views
deleteQuestion Delete a question (no UI yet)
Answers createAnswer Create answer for question
getAnswers Get paginated answers with filters
Tags getTags Get paginated tags with filters
getTagQuestions Get questions for specific tag
getTopTags Get popular tags for the right sidebar
Votes CreateVote / UpdateVote Cast, switch, or remove an upvote/downvote
hasVoted Check the current user's vote on a question or answer
getUserVotesForTargets Batch-check votes for multiple targets
Collection toggleSaveQuestion Save or unsave a question
hasSavedQuestion Check whether a question is saved
getSaveQuestions Get the user's saved questions (paginated, filtered)
Community getUsers Get paginated users with search and filters
getCommunityMember Get a member and their questions
Auth signUpWithCredentials User registration
signInWithCredentials User login
logout User sign out

🐳 Docker

Build and run DevFlow in a containerized environment:

# Build the image
docker build -t devflow .

# Run the container
docker run -p 3000:3000 \
  -e MONGODB_URI="mongodb+srv://..." \
  -e AUTH_SECRET="your-secret-key" \
  -e AUTH_GITHUB_ID="your-github-id" \
  -e AUTH_GITHUB_SECRET="your-github-secret" \
  devflow

The image runs as a non-root user on port 3000 for security.


πŸ”„ CI/CD Pipeline

GitHub Actions automate testing and deployment:

Workflows

Workflow Trigger Action
CI PR or push to main/dev Lint β†’ Type-check β†’ Build
Deploy (Dev) Push to dev Build β†’ Push ghcr.io/.../devflow:dev
Deploy (Prod) Push to main Build β†’ Push ghcr.io/.../devflow:latest

Setup

  1. Configure Settings β†’ Environments in your GitHub repo
  2. Add secrets for development and production environments:
    • MONGODB_URI
    • AUTH_SECRET
    • OAuth credentials
    • Docker registry credentials (if using GHCR)

πŸ“Š Performance

  • 🎯 Next.js App Router with Server Components and Server Actions
  • 🧩 Client-only MDX editor loaded with next/dynamic to keep it out of server rendering
  • πŸ—œοΈ Optimized Bundle with tree-shaking
  • πŸ“¦ MongoDB Indexing for fast queries
  • πŸš€ Docker Multi-stage Build for minimal image size

🀝 Contributing

We welcome contributions! Here's how to get started:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request against the dev branch

Guidelines

  • Follow the existing code style
  • Add tests for new features
  • Update documentation as needed
  • Reference related issues in your PR

πŸ› Troubleshooting

MongoDB Connection Issues

# Check your MONGODB_URI format
# Expected: mongodb+srv://username:[email protected]/dbname
# Make sure your IP is whitelisted in MongoDB Atlas

NextAuth Errors

# Regenerate AUTH_SECRET
npx auth secret

# Verify OAuth credentials in your provider settings

Build Fails

# Clear cache and reinstall
rm -rf .next node_modules
yarn install
yarn build

πŸ“ License

This project is licensed under the MIT License β€” feel free to use it in your projects!


πŸ™‹ Support & Contribution

Have questions or want to contribute?


Made with ❀️ by Osama Ayub

⬆ Back to Top

About

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages