# shivams21/todify architecture

> Architecture diagram of the GitHub repository shivams21/todify, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shivams21/todify
- Repository: https://github.com/shivams21/todify

## Overview

##### Project Type and Purpose
- This is a full-stack Next.js application for task management with user authentication.
- Frontend: React/Next.js pages and components under `src/app`
- Backend: Next.js API routes under `src/app/api`
- Data persistence: MongoDB (through `src/lib/mongodb.ts`) and Redis (through `src/lib/redis.ts`)
- Authentication: NextAuth’s dynamic route implementation at `src/app/api/auth/[...nextauth]/route.ts`

##### File Structure Analysis
- Top level:
- `next.config.mjs`, `tailwind.config.ts`, `postcss.config.mjs`, `tsconfig.json` – build and styling configurations
- `public` – static assets
- `src/app` – Next.js “App Router” structure containing:
- `page.tsx`, `layout.tsx` – top-level pages and layout
- `api/` – RESTful route handlers for `auth`, `task`, `user`
- `components/` – reusable UI pieces (cards, modals, navbar, loading)
- `views/` – higher-level page groupings (inbox, today, upcoming, filters)
- `provider.tsx` – React context for global state (likely NextAuth session provider)
- `utility/` – helper functions (e.g., password generator, Google sign-in check)
- `src/lib` – service connectors and business logic wrappers (auth, MongoDB, Redis)
- `src/models` – Mongoose/TypeScript schemas (`Task.ts`, `User.ts`)
- `middleware.ts` – route middleware (e.g., auth guard)

##### Key Architectural Insights (in lieu of README)
- Follows an MVC-like pattern:
- Models → `src/models`
- Controllers/API routes → `src/app/api/*/route.ts`
- Views → React components/pages in `src/app`
- State and session management via NextAuth + Redis cache
- Data flow is primarily HTTP/JSON between frontend and backend APIs

##### Main Components and Their Relationships
- User’s Browser (React/Next.js SPA)
- Next.js Server (server-side rendering, API endpoints)
- Authentication Service (NextAuth, Google OAuth)
- MongoDB (persistent store for users, tasks)
- Redis (session/token store, caching)
- Optional External Services (e.g., Google sign-in)

##### Interactions and Data Flows
- On page load: Browser → Next.js Server → React page (SSR or CSR)
- User actions (e.g., create task): Browser → `/api/task` → Controller logic → MongoDB write → Response → UI update
- Authentication flows:
- Browser → `/api/auth` (NextAuth) → OAuth provider (Google)
- Tokens/sessions stored in Redis, extended to MongoDB for user records
- Middleware intercepts protected routes, validates session via Redis

##### Architectural Patterns and Principles
- Separation of concerns: UI vs. API vs. data layers
- API-first design: all CRUD for tasks and users exposed as REST routes
- Reuse of React components for consistent UX (cards, modals)
- Context/provider pattern for global state (AuthProvider)
- Caching layer (Redis) to offload session reads from MongoDB

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Client["Browser / React App<br/>(React, TailwindCSS)"]:::frontend
        Pages["Pages & Layout<br/>(Next.js App Router)"]:::frontend
        click Pages "https://github.com/shivams21/todify/blob/main/src/app/page.tsx"
        click Pages "https://github.com/shivams21/todify/blob/main/src/app/layout.tsx"
        UIComponents["UI Components<br/>(cards, modals, navbar)"]:::frontend
        click UIComponents "https://github.com/shivams21/todify/tree/main/src/app/components"
        AuthProvider["Global Auth Provider"]:::frontend
        click AuthProvider "https://github.com/shivams21/todify/blob/main/src/app/provider.tsx"
        Utilities["Utilities<br/>(passwordGenerator, GoogleSignIn)"]:::frontend
        click Utilities "https://github.com/shivams21/todify/blob/main/src/app/utility/passwordGenerator.ts"
        click Utilities "https://github.com/shivams21/todify/blob/main/src/app/utility/checkGoogleSignInNewUser.ts"
        Views["Views (Inbox, Today, Upcoming, Filters)"]:::frontend
        click Views "https://github.com/shivams21/todify/blob/main/src/app/views/inbox/page.tsx"
        click Views "https://github.com/shivams21/todify/blob/main/src/app/views/today/page.tsx"
        click Views "https://github.com/shivams21/todify/blob/main/src/app/views/upcoming/page.tsx"
        click Views "https://github.com/shivams21/todify/blob/main/src/app/views/filters-labels/page.tsx"
    end

    %% Next.js Server Layer
    subgraph "Next.js Server" 
        direction TB
        SSR["SSR/SSG<br/>(React Rendering)"]:::backend
        subgraph "Next.js API" 
            direction TB
            AuthAPI["Auth API<br/>(NextAuth)"]:::backend
            click AuthAPI "https://github.com/shivams21/todify/blob/main/src/app/api/auth/[...nextauth]/route.ts"
            TaskAPI["Task API<br/>(REST CRUD)"]:::backend
            click TaskAPI "https://github.com/shivams21/todify/blob/main/src/app/api/task/route.ts"
            UserAPI["User API<br/>(REST CRUD)"]:::backend
            click UserAPI "https://github.com/shivams21/todify/blob/main/src/app/api/user/route.ts"
        end
        Middleware["Middleware (Auth Guard)"]:::backend
        click Middleware "https://github.com/shivams21/todify/blob/main/src/middleware.ts"
    end

    %% Libraries Layer
    subgraph "Service Connectors"
        direction TB
        MongoLib["MongoDB Connector"]:::backend
        click MongoLib "https://github.com/shivams21/todify/blob/main/src/lib/mongodb.ts"
        RedisLib["Redis Connector"]:::backend
        click RedisLib "https://github.com/shivams21/todify/blob/main/src/lib/redis.ts"
    end

    %% Data Stores
    subgraph "Data Stores"
        direction TB
        MongoDB[(MongoDB)]:::datastore
        Redis[(Redis Cache)]:::datastore
        subgraph "Models"
            direction TB
            TaskModel["Task Model"]:::datastore
            click TaskModel "https://github.com/shivams21/todify/blob/main/src/models/Task.ts"
            UserModel["User Model"]:::datastore
            click UserModel "https://github.com/shivams21/todify/blob/main/src/models/User.ts"
        end
    end

    %% External Services
    OAuthProvider["External OAuth Provider<br/>(Google)"]:::external

    %% Connections
    Client -->|"renders"| Pages
    Client -->|"uses"| UIComponents
    Client -->|"wraps in"| AuthProvider
    Client -->|"calls"| SSR
    Client -->|"API requests"| AuthAPI
    Client -->|"API requests"| TaskAPI
    Client -->|"API requests"| UserAPI

    SSR -->|"renders pages"| Client

    AuthAPI -->|"session check"| RedisLib
    TaskAPI -->|"cache read/write"| RedisLib
    UserAPI -->|"cache read/write"| RedisLib
    AuthAPI -->|"db operations"| MongoLib
    TaskAPI -->|"db operations"| MongoLib
    UserAPI -->|"db operations"| MongoLib

    MongoLib -->|"connects to"| MongoDB
    RedisLib -->|"connects to"| Redis

    AuthAPI -->|"OAuth flow"| OAuthProvider

    AuthAPI -->|"/api/auth requests"| Middleware
    TaskAPI -->|"/api/task requests"| Middleware
    UserAPI -->|"/api/user requests"| Middleware
    Middleware -->|"validates session"| RedisLib

    %% Styles
    classDef frontend fill:#CCE5FF,stroke:#000,stroke-width:1px
    classDef backend fill:#CCFFCC,stroke:#000,stroke-width:1px
    classDef datastore fill:#FFD699,stroke:#000,stroke-width:1px
    classDef external fill:#E5CCFF,stroke:#000,stroke-width:1px
```
