A modern, high-performance full-stack app built with Next.js, leveraging MDX for content, PWA capabilities, and a rich ecosystem of libraries including Supabase, Framer Motion, KaTeX, and more. This project is designed for scalability, maintainability, and an excellent developer experience.
- Overview
- Live Application
- Features
- Project Structure
- Prerequisites
- Getting Started
- Available Scripts
- Dependencies
- Dev Dependencies
- Backend (Supabase)
- Docker & Dev Container Configuration
- Contributing
- License
- Further Reading
This repository hosts a Next.js-based blog that uses MDX to write rich, interactive content. The app combines server-side rendering, static site generation, and client-side rendering to deliver fast and SEO-friendly pages. It also includes modern features such as PWA support, image optimization, and seamless animations using Framer Motion.
The blog covers a wide range of topics in computer science and software engineering, providing educational content, tutorials, and insights for developers of all levels. The content is written in MDX, allowing for a mix of Markdown and React components to create engaging posts. Additionally, this architecture also allows for easy addition or modification of content without compromising performance or modifying any code.
To add more content, we can simply create new MDX files in the content
directory, following the existing structure. The blog is designed to be scalable, maintainable, and extensible, making it a great platform for sharing knowledge and insights within the tech community.
Feel free to contribute your own articles, improve the existing content, or customize the blog to suit your needs. Let's build a vibrant community around computer science and software engineering! Refer to the Contributing section for guidelines on how to contribute to this project.
The blog is deployed on Vercel and can be accessed at https://devverse-swe.vercel.app/.
The backup deployment is available on Netlify at https://devverse-swe.netlify.app.
Feel free to explore the content and features of the blog! π
and many more pages...
- Next.js Framework: Built with Next.js for robust SSR, SSG, and CSR.
- MDX Integration: Write content in MDX, mixing Markdown with React components.
- Progressive Web App (PWA): Enhanced offline capabilities with next-pwa.
- Animation: Smooth animations with Framer Motion.
- Mathematics Rendering: Render mathematical equations using KaTeX, rehype-katex, and remark-math.
- Code Splitting & Performance: Automatic code splitting and image optimization for improved performance.
- Containerized Development: Docker and Docker Compose configurations for an isolated development environment.
- Dev Containers: VS Code Dev Container configuration for a seamless setup.
- User Authentication: User authentication with JWT tokens.
- User Registration/Sign-In: User registration and sign-in functionality.
- Favorites: Add articles to favorites for easy access (authenticated users only).
- Responsive Design: Mobile-friendly layout with responsive design.
- Dark Mode: Toggle between light and dark themes.
- SEO-Friendly: Optimized for search engines with meta tags and structured data, with SSR and SSG.
- Linting & Formatting: ESLint and Prettier configurations for consistent code quality.
devverse-cs-swe-blog/
βββ app/
β βββ globals.css # Global CSS styles
β βββ page.tsx # Main page component
β βββ layout.tsx # Layout component
β βββ not-found.tsx # 404 page component
β βββ favorites/
β β βββ page.tsx # Favorites page component
β βββ api/
β β βββ reset-password/
β β β βββ route.ts # Reset password API route
β β βββ favorites/
β β β βββ route.ts # Favorites API route
β βββ auth/
β β βββ login/
β β β βββ page.tsx # Login page component
β β βββ register/
β β β βββ page.tsx # Register page component
β β βββ reset/
β β β βββ page.tsx # Reset password page component
β βββ articles/[slug]
β βββ page.tsx # Dynamic topic pages
βββ components/ # Reusable React components
β βββ ArticleList.tsx # Component for displaying a list of articles
β βββ ArticleContent.tsx # Article content component
β βββ FavoritesList.tsx # Component for displaying a list of favorite articles
β βββ FavButton.tsx # Favorite button component
β βββ Footer.tsx # Footer component
β βββ HomePageContent.tsx # Home page content component
β βββ Navbar.tsx # Navbar component
β βββ InteractiveCard.tsx # Interactive card component
β βββ Loading.tsx # Loading spinner component
β βββ MdxLayout.tsx # Layout component for MDX content
β βββ (...) # Other components
β βββ RouteProgress.tsx # Route progress bar component
βββ utils/ # Utility functions and constants
β βββ getAllPosts.js # Function to fetch all MDX posts
βββ ui/ # UI components and styles
β βββ CodeBlock.tsx # Code block component
β βββ InlineCode.tsx # Inline code component
β βββ PreBlock.tsx # Preformatted block component
βββ supabase/ # Supabase client configuration and queries
β βββ supabaseClient.ts # Supabase client configuration
β βββ auth.ts # Authentication functions
β βββ avatar.ts # Avatar functions
β βββ favorites.ts # Favorites functions
β βββ profile.ts # Profile functions
β βββ (other sql files for database setup)
βββ public/ # Static files (images, fonts, etc.)
βββ content/ # MDX content for blog posts
βββ .devcontainer/ # VS Code Dev Container configuration
β βββ devcontainer.json
βββ images/ # Images for README
βββ Dockerfile # Docker image configuration for the app
βββ docker-compose.yml # Docker Compose file for containerized development
βββ package.json # Project manifest with scripts and dependencies
βββ tsconfig.json # TypeScript configuration
βββ next.config.js # Next.js configuration
βββ next-sitemap.config.js # Next.js sitemap configuration
βββ mdx-components.tsx # Custom MDX components
βββ tailwind.config.js # Tailwind CSS configuration
βββ README.md # This documentation file
βββ (... and more)
- Node.js (v14 or higher recommended)
- npm
- Docker & Docker Compose (for containerized development)
- Visual Studio Code (optional, for using Dev Containers)
-
Clone the Repository:
git clone https://github.com/hoangsonww/DevVerse-SWE-Blog.git cd DevVerse-CS-SWE-Blog
-
Install Dependencies:
npm install
-
Run the Development Server:
npm run dev
Open http://localhost:3000 in your browser to view the app.
A docker-compose.yml
file is provided to facilitate containerized development.
-
Build and Start the Container:
docker-compose up
-
Access the App:
The application will be available at http://localhost:3000.
If you use Visual Studio Code, you can open the project in a Dev Container:
- Install the Remote - Containers extension.
- Open the Command Palette (
Ctrl+Shift+P
orCmd+Shift+P
on macOS) and select "Remote-Containers: Reopen in Container". - VS Code will build and attach to the container using the configuration in
.devcontainer/devcontainer.json
.
-
npm run dev
Runs the Next.js development server. -
npm run build
Builds the application for production. -
npm run start
Starts the production server.
- Next.js: The core framework powering the application.
- Tailwind CSS: Utility-first CSS framework for styling.
- @supabase/supabase-js: Supabase client for user authentication.
- React & React-Dom: Essential libraries for building user interfaces.
- @mdx-js/loader & @mdx-js/react: Tools for integrating MDX content with React.
- next-pwa: Adds progressive web app capabilities.
- Framer Motion: Provides smooth animations.
- KaTeX, rehype-katex, remark-math: Enable mathematical rendering within MDX content.
- nprogress: A progress bar for route transitions.
- remark-gfm: Adds support for GitHub Flavored Markdown.
- and more...
- TypeScript & @types/node: Enable static typing for robust development.
- @types/nprogress: Provides type definitions for nprogress.
- @types/react & @types/react-dom: Type definitions for React.
- @types/tailwindcss: Type definitions for Tailwind CSS.
- and more...
The blog uses Supabase for user authentication, file storage, and database services. To set up the backend services, follow these steps:
-
Create a Supabase Account:
Sign up for a free account on Supabase.
-
Create a New Project:
Create a new project in the Supabase dashboard.
-
Set Up Authentication:
Enable authentication in the project settings.
-
Create a
.env
(or.env.local
) File:Create a
.env
(or.env.local
) file in the root directory of the project with the following environment variables:NEXT_PUBLIC_SUPABASE_URL=YOUR_SUPABASE_URL NEXT_PUBLIC_SUPABASE_ANON_KEY=YOUR_SUPABASE_ANON_KEY SUPABASE_SERVICE_ROLE_KEY=YOUR_SUPABASE_SERVICE_ROLE_KEY
Replace
YOUR_SUPABASE_URL
andYOUR_SUPABASE_ANON_KEY
with your Supabase project URL and anonymous key, respectively. Also, replaceYOUR_SUPABASE_SERVICE_ROLE_KEY
with your Supabase service role key, obtained from the project settings. -
Set Up Database:
Create 3 new tables in the Supabase dashboard with the following schema:
CREATE TABLE IF NOT EXISTS articles ( id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), title TEXT NOT NULL, slug TEXT NOT NULL, content TEXT NOT NULL, author TEXT NOT NULL, created_at TIMESTAMPTZ DEFAULT now() ); CREATE TABLE IF NOT EXISTS profiles ( id UUID PRIMARY KEY REFERENCES auth.users(id) ON DELETE CASCADE, avatar_url TEXT, updated_at TIMESTAMPTZ DEFAULT now() ); CREATE TABLE IF NOT EXISTS favorite_articles ( id SERIAL PRIMARY KEY, user_id UUID REFERENCES auth.users(id) ON DELETE CASCADE, article_slug TEXT NOT NULL, created_at TIMESTAMPTZ DEFAULT now(), UNIQUE (user_id, article_slug) );
You may copy the above SQL queries and run them in the SQL editor in the Supabase dashboard. This will create the necessary tables for the bare-bones blog. For a more complex and full-fledged blog, visit the
supabase/
directory for more SQL files & queries. -
Set Up Storage:
Enable storage in the project settings to store images and other files.
-
Set Up User Roles:
Create a new service role in the project settings with the following permissions:
articles: select, insert, update, delete
storage: create, read, update, delete
This role will be used to access the articles and storage services from the blog.
Or, for development purposes, you can use the
public
role with the same permissions, or just allow all permissions for simplicity (not recommended for production). -
Run the Application:
Start the development server using
npm run dev
and test the user authentication and article services.
Because, in order to reset password with Supabase, it requires sending a confirmation email to the user, which is not implemented in this project since it requires setting up a custom SMTP server.
However, for an application this size, I overrode the default Supabase reset password API route to allow users to reset their password without the need for a confirmation email. This is not recommended for production applications, but it is a quick and easy way to test the reset password functionality.
The Next.js API routes are as follows:
-
/api/reset-password
- Method: POST
- Body:
{ email: string, password: string }
- Description: Resets the user's password without sending a confirmation email.
-
/api/verify-email
- Method: POST
- Body:
{ email: string }
- Description: Verifies the user's email address.
The flow is: First, call the /api/verify-email
route to verify the user's email address. Then, call the /api/reset-password
route to reset the user's password associated with that email address.
All other routes are standard Supabase routes for user authentication and profile/favorites management.
FROM node:18-bullseye-slim
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "run", "dev"]
version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
volumes:
- .:/app:cached
command: npm run dev
environment:
- NODE_ENV=development
{
"name": "devverse-cs-swe-blog",
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"editor.formatOnSave": true
},
"extensions": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"ms-vscode.vscode-typescript-next",
"eamodio.gitlens"
],
"postCreateCommand": "npm install",
"remoteUser": "node",
"forwardPorts": [3000]
}
Contributions are welcome! Please follow these guidelines when contributing:
- Fork the repository and create your feature branch (
git checkout -b feature/your-feature
). - Commit your changes (
git commit -m 'Add some feature'
). - Push your branch (
git push origin feature/your-feature
). - Open a pull request with a detailed description of your changes.
Ensure that your code adheres to our coding standards and includes tests where applicable.
To add more MDX content, create a new .mdx
file in the content
directory. You can use the existing files as a template.
We welcome contributions that expand the content and cover a wide range of topics in computer science and software engineering! I hope this project can serve as a platform for sharing knowledge and insights within the tech community.
This project is licensed under the MIT License.
- Next.js Documentation: https://nextjs.org/docs
- MDX Documentation: https://mdxjs.com/
- Supabase Documentation: https://supabase.io/docs
- Next.js Blog: Explore real-world examples and case studies on the official Next.js blog.
- Docker Documentation: https://docs.docker.com/
- VS Code Dev Containers: https://code.visualstudio.com/docs/remote/containers
Reach out to me at @hoangsonww for any questions or feedback. I'd love to hear from you!
This project is powered by Next.js and serves as a testament to the framework's capabilities in building modern, scalable, and high-performance web applications. Happy coding! π