CodeCraft Auth API Docs - v0.0.0
    Preparing search index...

    CodeCraft Auth API Docs - v0.0.0

    CodeCraft Auth

    A modern, production-ready authentication web application built with Vite + React + TypeScript + Supabase, following global industry conventions for folder structure, tooling, testing, and scalability.

    Documentation

    • Build Tool: Vite 7
    • Framework: React 19 + TypeScript 5.9
    • Routing: React Router v7 (createBrowserRouter)
    • Auth & Backend: Supabase (Email/Password + Google OAuth)
    • Forms: React Hook Form
    • Validation: Zod v4
    • UI: shadcn/ui + Radix UI (20+ components)
    • Styling: Tailwind CSS v4 with @tailwindcss/vite
    • Icons: Lucide React + Phosphor Icons
    • Theme: next-themes (dark mode support)
    • Notifications: Sonner
    • Animations: Motion
    • Testing: Vitest + Testing Library + jsdom
    • Linting: ESLint v9 with TypeScript
    • Package Manager: pnpm
    src/
    β”œβ”€β”€ modules/
    β”‚ β”œβ”€β”€ authentication/ # Authentication module
    β”‚ β”‚ β”œβ”€β”€ components/ # Auth-specific components (forms, inputs, social login)
    β”‚ β”‚ β”œβ”€β”€ configs/ # Content maps and error maps
    β”‚ β”‚ β”œβ”€β”€ contexts/ # Auth context provider
    β”‚ β”‚ β”œβ”€β”€ hooks/ # Auth custom hooks (useAuthSubmit)
    β”‚ β”‚ β”œβ”€β”€ layouts/ # Auth layout wrapper
    β”‚ β”‚ β”œβ”€β”€ pages/ # Auth pages
    β”‚ β”‚ β”‚ β”œβ”€β”€ auth-sign-in.page.tsx
    β”‚ β”‚ β”‚ β”œβ”€β”€ auth-sign-up.page.tsx
    β”‚ β”‚ β”‚ β”œβ”€β”€ auth-forgot-password.page.tsx
    β”‚ β”‚ β”‚ └── auth-update-password.page.tsx
    β”‚ β”‚ β”œβ”€β”€ schemas/ # Zod validation schemas
    β”‚ β”‚ └── services/ # Auth service (sign in/up, OAuth, reset)
    β”‚ β”‚
    β”‚ └── application/ # Application module
    β”‚ β”œβ”€β”€ components/ # App components (header, sidebar, breadcrumb)
    β”‚ β”œβ”€β”€ layouts/ # App layout wrapper
    β”‚ β”œβ”€β”€ pages/ # App pages (dashboard)
    β”‚ └── types/ # App-specific types
    β”‚
    β”œβ”€β”€ routes/
    β”‚ β”œβ”€β”€ configs/ # Route paths and route definitions
    β”‚ β”œβ”€β”€ core/ # Route builder, guards, wrappers, error boundary
    β”‚ β”œβ”€β”€ hooks/ # Route-specific hooks
    β”‚ β”œβ”€β”€ types/ # Route types
    β”‚ └── index.tsx # Router configuration
    β”‚
    β”œβ”€β”€ components/
    β”‚ └── ui/ # shadcn/ui components (20+ components)
    β”‚ β”œβ”€β”€ button.tsx, input.tsx, card.tsx, etc.
    β”‚ β”œβ”€β”€ sidebar.tsx, breadcrumb.tsx, avatar.tsx
    β”‚ └── loader.tsx, spinner.tsx, skeleton.tsx
    β”‚
    β”œβ”€β”€ contexts/ # Global contexts (theme)
    β”œβ”€β”€ hooks/ # Global custom hooks (media query, mobile)
    β”œβ”€β”€ lib/
    β”‚ β”œβ”€β”€ supabase.ts # Supabase client configuration
    β”‚ └── utils.ts # Utility functions (cn, etc.)
    β”‚
    β”œβ”€β”€ assets/ # Static assets (fonts)
    β”œβ”€β”€ tests/ # Test setup and utilities
    β”œβ”€β”€ App.tsx # Root app component
    └── main.tsx # Application entry point
    • Node.js 18+
    • pnpm 8+
    • A Supabase account
    1. Clone the repository:
    cd codecraft-auth
    
    1. Install dependencies:
    pnpm install
    
    1. Configure environment variables:
      • Open the .env file in the project root
      • Update with your Supabase credentials:
    VITE_SUPABASE_URL=your_supabase_url
    VITE_SUPABASE_ANON_KEY=your_supabase_anon_key
    1. Create a new project at supabase.com
    2. Go to Project Settings > API
    3. Copy the Project URL and anon public key
    4. Paste them into your .env file
    5. (Optional) Enable Google OAuth:
      • Go to Authentication > Providers
      • Enable Google
      • Set up OAuth credentials from Google Cloud Console
      • Add redirect URI: https://YOUR-PROJECT-ID.supabase.co/auth/v1/callback

    The authentication is handled automatically by Supabase Auth. No additional table setup is required for basic email/password authentication.

    Start the development server:

    pnpm dev
    

    The app will be available at http://localhost:5173

    Build for production:

    pnpm build
    

    Preview the production build:

    pnpm preview
    

    Run tests:

    pnpm test
    

    Run tests with UI:

    pnpm test:ui
    
    • βœ… Email/Password Sign Up with full name
    • βœ… Email/Password Sign In
    • βœ… Google OAuth Sign In
    • βœ… Password Reset Flow
    • βœ… Password Update
    • βœ… Email Verification
    • βœ… Protected Routes with Guards
    • βœ… Session Management & Persistence
    • βœ… Auto-redirect based on auth state
    • βœ… Auth context with hooks
    • βœ… Dark mode support with next-themes
    • βœ… Modern sidebar layout with collapsible navigation
    • βœ… Breadcrumb navigation
    • βœ… User profile dropdown in sidebar
    • βœ… Accessible forms with proper labels and ARIA attributes
    • βœ… Form validation with Zod v4
    • βœ… Loading states and spinners
    • βœ… Toast notifications with Sonner
    • βœ… Error handling and boundaries
    • βœ… Responsive design for all screen sizes
    • βœ… Smooth animations with Motion
    • βœ… 20+ shadcn/ui components
    • βœ… TypeScript strict mode
    • βœ… Path aliases (@/)
    • βœ… Module-based folder structure (domain-driven)
    • βœ… Colocated validation schemas
    • βœ… Centralized route configuration
    • βœ… Testing setup with Vitest + jsdom
    • βœ… ESLint v9 with TypeScript and React hooks
    • βœ… Hot Module Replacement
    • βœ… Code splitting with lazy loading
    • βœ… Custom hooks for common patterns
    • /auth/sign-in - Sign in page (email/password + Google)
    • /auth/sign-up - Sign up page with confirmation
    • /auth/forgot-password - Password reset request page
    • /auth/update-password - Password update page (after reset)
    • / - Redirects to dashboard
    • /app/dashboard - User dashboard with sidebar (requires authentication)
    • * - 404 Not Found page
    1. Sign Up: User creates account with email, password, and optional full name
    2. Email Verification: Supabase sends confirmation email (can be disabled for dev)
    3. Sign In: User signs in with verified credentials
    4. Session Management: Auth state is persisted and synced across tabs
    5. Protected Access: Dashboard and app routes require authentication
    1. OAuth Initiation: User clicks 'Sign in with Google'
    2. Google Authentication: User authenticates with Google
    3. Redirect: User is redirected back to app with session
    4. Auto Sign-In: User is automatically signed in and redirected to dashboard
    1. Request Reset: User enters email on forgot password page
    2. Reset Email: Supabase sends password reset link
    3. Update Password: User clicks link and enters new password
    4. Confirmation: Password is updated and user can sign in
    • Strict TypeScript: All code is type-safe with strict mode enabled
    • Module-based Organization: Code organized by domain/feature (authentication, application)
    • Naming Convention: Pages use .page.tsx suffix, layouts use .layout.tsx
    • Schemas: Validation schemas are colocated with features
    • No Prop Drilling: Context and custom hooks for state management
    • Service Layer: API calls abstracted into service modules
    • Route Configuration: Centralized in routes/configs/
    • Component Variants: Using class-variance-authority for component variants
    • Accessibility First: All components follow WCAG guidelines with proper ARIA labels
    1. Create a new directory in src/modules/
    2. Structure it with: components/, pages/, services/, schemas/, hooks/, types/
    3. Add route configurations in src/routes/configs/route-definitions.ts
    4. Register routes and guards as needed
    1. Update modules/authentication/services/auth.service.ts with the new provider method
    2. Add UI button in modules/authentication/components/auth-social-login.tsx
    3. Configure the provider in Supabase dashboard
    4. Test the authentication flow
    1. Create the page in appropriate module (e.g., modules/application/pages/)
    2. Add route definition in routes/configs/route-definitions.ts
    3. Set requiresAuth: true in the route config
    4. Add navigation link in sidebar or breadcrumb

    Use shadcn/ui CLI to add more components:

    pnpm dlx shadcn@latest add button
    pnpm dlx shadcn@latest add input
    pnpm dlx shadcn@latest add form
    pnpm dlx shadcn@latest add dialog
    pnpm dlx shadcn@latest add table

    MIT