Project Structure
Overview of the MkSaaS boilerplate file and folder organization
MkSaaS follows a modular architecture based on Next.js App Router with a focus on scalability and maintainability. This guide explains the key directories and files in the boilerplate to help you navigate the codebase more effectively.
Root Directory Structure
Key Files
src/middleware.ts
: Contains route protection logic and redirectssrc/routes.ts
: Defines application routes for consistent navigationcontent-collections.ts
: Configures MDX content collections for blog and docsdrizzle.config.ts
: Drizzle ORM configuration for the databasenext.config.ts
: Next.js configuration including redirects and rewrites.env.example
: Template for environment variables
Key directories
/src/app
Directory
The app directory follows Next.js App Router convention:
/src/actions
Directory
Server actions organized by feature, powered by next-safe-action for type-safe server actions:
/src/lib
Directory
Core application logic and utilities:
/src/components
Directory
Components are organized by feature and purpose for better maintainability:
Code Organization Best Practices
When working with MkSaaS, follow these best practices for code organization:
Group by feature, not by type
Keep related files together, regardless of their type.
Keep components focused and small
Each component should have a single responsibility.
Use barrel exports
Create index.ts
files to re-export components from a directory, making imports cleaner.
Clearly separate client and server components
Use the 'use client'
directive at the top of client components, and keep server components as the default.
Next Steps
Now that you understand the project structure, explore these related topics: