Skip to content

imran-baitham/vibe-coded-todo-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

FastTodo - Offline-First Task Manager

A production-ready, offline-first todo application with authentication, multi-list organization, and rich task metadata. Built with Next.js 15, TypeScript, and MongoDB.

Next.js TypeScript MongoDB License

โœจ Features

๐Ÿ” Authentication & Security

  • Secure Authentication: Email/Password signup and login with JWT
  • HTTP-only Cookies: Session management with secure, HTTP-only cookies
  • Route Protection: Automatic redirect to login for protected routes
  • Data Isolation: Complete user data privacy and separation
  • Robust Logout: Clean session termination with client-side cleanup

๐Ÿ“‹ Multi-List Organization

  • Unlimited Lists: Create and manage multiple todo lists
  • List Management: Rename and delete lists with ease
  • Cascading Delete: Deleting a list removes all associated todos
  • Smart Defaults: Auto-select first list on load
  • List Switching: Quick dropdown navigation between lists

โœ… Rich Todo Metadata

Each todo includes:

  • Title and Description
  • Status: Pending | Todo | In Progress | Completed
  • Category: Bug | Feature | Docs | Improvement | Refactor
  • Priority: Minor | Normal | Important | Critical
  • Visual Badges: Color-coded badges for quick identification

๐Ÿš€ Offline-First Architecture

  • Instant Updates: Optimistic UI for immediate feedback
  • LocalStorage Caching: Persistent offline data storage
  • Smart Sync: Automatic synchronization when online
  • No Loading Flash: Skeleton loaders during hydration
  • Conflict Resolution: Intelligent merge strategy for sync conflicts

๐ŸŽจ Premium User Experience

  • Dark Mode: System, light, and dark theme support
  • Smooth Transitions: No jarring UI changes
  • Modern Design: Clean interface with shadcn/ui components
  • Responsive Layout: Works on all screen sizes
  • Accessible: ARIA labels and keyboard navigation

๐Ÿ› ๏ธ Tech Stack

  • Frontend: Next.js 15 (App Router), React 19, TypeScript
  • State Management: Zustand with localStorage persistence
  • Styling: Tailwind CSS, shadcn/ui components
  • Backend: Next.js API Routes
  • Database: MongoDB with Mongoose ODM
  • Authentication: JWT with jose, HTTP-only cookies
  • Theme: next-themes for dark mode support

๐Ÿ“‹ Prerequisites

  • Node.js 18+ and npm
  • MongoDB instance (local or cloud like MongoDB Atlas)
  • Git

๐Ÿš€ Installation

1. Clone the repository

git clone https://github.com/yourusername/fasttodo.git
cd fasttodo

2. Install dependencies

npm install

3. Environment Setup

Create a .env.local file in the root directory:

# MongoDB Connection String
MONGODB_URI=mongodb://localhost:27017/fasttodo
# OR for MongoDB Atlas:
# MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/fasttodo

# JWT Secret (use a strong random string)
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production

Generate a secure JWT secret:

node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

4. Run the development server

npm run dev

Open http://localhost:3000 in your browser.

๐Ÿ“– Usage

First Time Setup

  1. Navigate to http://localhost:3000
  2. You'll be redirected to /login
  3. Click "Sign Up" and create an account
  4. After signup, you'll be automatically logged in

Creating Your First List

  1. Click the "Create List" button
  2. Enter a list name (e.g., "Work Tasks")
  3. Click "Done"

Adding Todos

  1. Make sure a list is selected (shown in the dropdown)
  2. Click "Create Todo"
  3. Fill in the details:
    • Title (required)
    • Description (optional)
    • Status (default: Todo)
    • Category (default: Feature)
    • Priority (default: Normal)
  4. Click "Save changes"

Managing Lists

  • Switch Lists: Click the list dropdown, select a different list
  • Rename List: Click the โ‹ฎ menu next to the list dropdown โ†’ "Rename list"
  • Delete List: Click the โ‹ฎ menu โ†’ "Delete list" (deletes all todos in the list)

Offline Usage

The app works perfectly offline:

  1. Go Offline: Disconnect from the internet
  2. Create/Edit: Make changes to todos and lists
  3. Local Storage: Changes are saved immediately to localStorage
  4. Reload: Page reloads show cached data with no flash
  5. Reconnect: Automatic sync to server when back online

Theme Switching

Click the Sun/Moon icon in the header to toggle between:

  • Light mode
  • Dark mode
  • System preference

๐Ÿ—๏ธ Architecture

Data Flow

User Action
    โ†“
Zustand Store (Optimistic Update)
    โ†“
LocalStorage (Offline Persistence)
    โ†“
API Route (if online)
    โ†“
MongoDB (Server Persistence)
    โ†“
Sync & Merge (on reconnect)

Project Structure

fasttodo/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ app/
โ”‚   โ”‚   โ”œโ”€โ”€ api/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ auth/[...path]/    # Auth endpoints
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ lists/             # List CRUD
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ todos/             # Todo CRUD
โ”‚   โ”‚   โ”œโ”€โ”€ login/                 # Login page
โ”‚   โ”‚   โ”œโ”€โ”€ signup/                # Signup page
โ”‚   โ”‚   โ”œโ”€โ”€ layout.tsx             # Root layout with ThemeProvider
โ”‚   โ”‚   โ””โ”€โ”€ page.tsx               # Main dashboard
โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”œโ”€โ”€ ui/                    # shadcn/ui components
โ”‚   โ”‚   โ”œโ”€โ”€ header.tsx             # App header with theme toggle
โ”‚   โ”‚   โ”œโ”€โ”€ todo-list.tsx          # Main todo list view
โ”‚   โ”‚   โ”œโ”€โ”€ todo-card.tsx          # Individual todo card
โ”‚   โ”‚   โ”œโ”€โ”€ todo-dialog.tsx        # Create/edit dialog
โ”‚   โ”‚   โ”œโ”€โ”€ create-list-dialog.tsx # List creation
โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ”œโ”€โ”€ lib/
โ”‚   โ”‚   โ”œโ”€โ”€ db.ts                  # MongoDB connection
โ”‚   โ”‚   โ””โ”€โ”€ auth.ts                # JWT utilities
โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”‚   โ”œโ”€โ”€ Todo.ts                # Todo Mongoose schema
โ”‚   โ”‚   โ”œโ”€โ”€ List.ts                # List Mongoose schema
โ”‚   โ”‚   โ””โ”€โ”€ User.ts                # User Mongoose schema
โ”‚   โ”œโ”€โ”€ store/
โ”‚   โ”‚   โ””โ”€โ”€ use-todo-store.ts      # Zustand store with sync logic
โ”‚   โ””โ”€โ”€ proxy.ts                   # Route protection middleware
โ””โ”€โ”€ package.json

Key Features Implementation

Offline-First Sync

The app uses a sophisticated sync engine in use-todo-store.ts:

  1. Push Deletions: Sync deleted items to server
  2. Push Updates: Sync created/modified items
  3. Pull & Merge: Fetch server data and merge with local changes
  4. Conflict Resolution: Unsynced local changes always take precedence

Authentication Flow

  • Login โ†’ JWT signed โ†’ HTTP-only cookie set
  • Every API request โ†’ Cookie validated โ†’ User identified
  • Protected routes โ†’ proxy.ts checks auth โ†’ Redirect if needed

๐Ÿงช Testing

Manual Testing Checklist

  • Signup and login
  • Create multiple lists
  • Switch between lists
  • Create todos with different statuses/categories/priorities
  • Edit todos
  • Delete todos
  • Rename list
  • Delete list (verify cascading delete)
  • Go offline, create todo, reconnect (verify sync)
  • Reload page offline (verify no data loss)
  • Toggle theme (light/dark/system)
  • Logout and login again

๐Ÿ› Troubleshooting

MongoDB Connection Issues

If you get connection errors:

  1. Ensure MongoDB is running: mongod --version
  2. Check your MONGODB_URI in .env.local
  3. For MongoDB Atlas, ensure IP whitelist includes your IP

JWT Errors

If you see JWT-related errors:

  1. Verify JWT_SECRET is set in .env.local
  2. Clear cookies and try logging in again
  3. Regenerate JWT_SECRET with a strong random string

Hydration Errors

If you see hydration warnings:

  1. Check that suppressHydrationWarning is on <html> tag
  2. Ensure ThemeProvider is wrapping the app
  3. Clear browser cache and reload

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

๐Ÿ“ License

This project is licensed under the MIT License.

๐Ÿ™ Acknowledgments


Built with โค๏ธ using Next.js and TypeScript

About

Offline First Todo Application

Topics

Resources

Stars

Watchers

Forks

Contributors