How pintoderian/next-directus-auth-ts works
Main Components
• Frontend UI: This consists of the React components for the dashboard, admin panel (under src/components/admin-panel), general UI components (located in src/components/ui), and theme or mode toggling components. These are responsible for rendering pages such as login, account management, posts, categories, tags, etc.
• Routing & Layout: Leveraging Next.js’ App Router structure. The “src/app” directory contains the route-based pages (root, dashboard, API endpoints, etc.) and layout files (layout.tsx) that define the overall structure.
• API & Authentication: Under src/app/api, most notably the NextAuth.js dynamic route ([...nextauth]) provides authentication endpoints. Also, the lib folder (src/lib/auth and associated files) supports session handling and validation logic.
• External Integrations:
• Directus: Found in src/services/directus.ts is responsible for connecting to and communicating with the Directus API for dynamic content.
• Third Party Libraries: NextAuth, Tailwind, shadcn UI components, and state management (using zustand via src/hooks/use-store.ts) make up the additional layers of functionality.
Relationships & Interactions
• The Browser/Client sends requests for pages (rendering components built with Next.js and Tailwind CSS).
• When authentication-related actions occur (like login), the client communicates with the API endpoints (src/app/api/auth/[...nextauth]) which interact with NextAuth.js flows using the library functions in src/lib/auth.
• Once authenticated, the UI components (dashboard and admin panel) retrieve user-specific or content data. They potentially call service functions (e.g., src/services/directus.ts) that interact with the Directus CMS.
• Global configuration elements like the Next.js configuration (next.config.js), tailwind, ESLint, and Prettier ensure consistency in building and styling the app.
Architectural Patterns & Design Principles
• File-Based Routing & Layout: The use of “src/app” and nested folders (like /dashboard and /api) indicates a clear separation between the user pages and API endpoints.
• Component Reusability: The modular structure with components stored under src/components (for both admin and common UI controls) reveals an emphasis on reusability and separation of concerns.
• Service and Utility Abstraction: Code in src/lib and src/services abstracts core functionalities (authentication, utility functions, and CMS integration) away from UI rendering, promoting a clean architecture.
Relevant Technologies and Frameworks
• Next.js is used for both the server-side rendering and API routes.
• Tailwind CSS provides the styling backbone.
• NextAuth.js is central for authentication.
• Directus is integrated as the CMS using the Directus SDK.
• Additional tooling includes Husky for Git hooks, ESLint/Prettier for code quality, and Zustand for lightweight state management.
Final Advice
• Authentication flow (login → NextAuth API → session management) and the integration with external content management (Directus).
• Modular separation (UI components, admin layouts, service layers) so every element’s role is unambiguous.