This project is a Todo Application built using modern web development technologies. It allows users to manage their personal task list efficiently with user authentication and optional image upload support.
Todo application uses a layered architecture as its primary architectural pattern, but it's enhanced with modern Next.js patterns and React paradigms. Here's the break down the architectural approach:
The application follows a layered architecture with these distinct layers:
-
Presentation Layer
- React components in
/componentsdirectory - Next.js pages in
/appdirectory - Handles UI rendering and user interactions
- React components in
-
Application/Business Logic Layer
- Server Actions in
/lib/actions.ts - Authentication logic in
/auth.ts - Handles business rules, data validation, and orchestration
- Server Actions in
-
Data Access Layer
- Database connection in
/lib/db/index.ts - Schema definitions in
/lib/db/schema.ts - S3 integration in
/lib/s3.ts - Handles data persistence and retrieval
- Database connection in
-
Infrastructure Layer
- Middleware in
/middleware.ts - Environment configuration
- Cross-cutting concerns like authentication and routing
- Middleware in
-
User Authentication
- Login and signup pages implemented under
/app/loginand/app/register. - Uses
next-authfor session management.
- Login and signup pages implemented under
-
Todo List Display
- All todos are fetched from a relational database using Drizzle ORM.
- Display logic handled inside the
components/ui/todo-list.tsx.
-
Add Todo Item
- Users can add new tasks via a form. If an image is uploaded, it is stored in an AWS S3 bucket.
- The form is processed server-side using
addTodo()function inlib/actions.ts.
-
Update Todo Status
- Each todo can be updated (e.g., mark as "Done" or "In Progress").
- Update logic interacts directly with the database using Drizzle.
-
Delete Todo Item
- Users can delete todos. If the todo contains an image, it also deletes the image from S3 using
deleteFromS3()inlib/s3.ts.
- Users can delete todos. If the todo contains an image, it also deletes the image from S3 using
-
(Optional) Image Upload
- Users can upload an image associated with a todo.
- Image files are uploaded to an S3 bucket using the
uploadToS3()function inlib/s3.ts.
- Frontend & Backend Framework: Next.js (App Router)
- CSS Styling: Tailwind CSS
- Authentication: NextAuth.js
- Database: Neon (PostgreSQL)
- Database ORM: Drizzle ORM
- Cloud Storage: AWS S3 for optional image upload
The application uses Neon PostgreSQL, a scalable serverless PostgreSQL solution that integrates well with Next.js applications.
id(primary key)nameemail(unique)password(hashed)image(optional)
id(primary key)contentcompleted(boolean)imageUrl(optional, for photo attachments)createdAt(timestamp)userId(foreign key →users.id)status(string)
For interacting with the database, the application uses Drizzle ORM, which offers:
- Type-safe database operations
- Clean and readable API for CRUD actions
- Excellent integration with TypeScript and modern frameworks like Next.js
Follow these steps to set up and run the Todo Application on your local machine.
git clone https://github.com/GGWPXXXX/TodoListNa
cd TodoListNapnpm installBefore continuing, make sure to:
-
Create a Neon Postgres database at https://neon.tech and copy your database connection string.
-
Create an AWS S3 bucket, and get your Access Key ID, Secret Access Key, and set your region (e.g., ap-southeast-2).
Create a .env file in the root directory and add the variables listed below. You can use the .env.example file as a reference.
DATABASE_URL=
NEXTAUTH_URL=
NEXTAUTH_SECRET=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION=
AWS_S3_BUCKET_NAME=
AWS_ENDPOINT=npx drizzle-kit pushpnpm dev- This app is deployed on Vercel.
- To deploy:
- Push your code to GitHub.
- Link the repo to Vercel.
- Add environment variables for:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_REGIONAWS_S3_BUCKET_NAMEAWS_ENDPOINTNEXTAUTH_SECRETNEXTAUTH_URLDATABASE_URL
-
app/login/– Login pageregister/– Signup pagelayout.tsx– Global layout component
-
components/ui/login-form.tsx– Login form componentregister-form.tsx– Registration form componenttodo-list.tsx– Core display and control logic for todostheme-provider.tsx– (Optional) Theme setup
-
lib/actions.ts– Handles DB logic and image upload/deletedb/– Drizzle schema & DB setups3.ts– AWS S3 integration
-
hooks/use-mobile.tsx– Custom mobile detection hookuse-toast.ts– Toast/notification hook
-
public/– Static assets (e.g., icons, images) -
.env– Environment variables -
.gitignore– Git ignore rules -
auth.ts– Authentication setup (e.g., NextAuth) -
drizzle.config.ts– Drizzle ORM configuration
- The image upload is optional and only triggered if a file is selected.
uploadToS3()uses@aws-sdk/lib-storageto stream uploads directly.deleteFromS3()ensures image is removed if a todo is deleted.- Each user’s image is stored in a folder matching their user ID for isolation.
- Image modal uses
fixedandflexto center preview. Large vertical images are now scrollable for better UX.
