# wallyway/wikiud architecture

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

- Interactive diagram: https://gitdiagram.com/wallyway/wikiud
- Repository: https://github.com/wallyway/wikiud

## Overview

##### Project Type and Purpose
- This is a full-stack TypeScript Next.js application (Next.js 13 “app” directory structure) named “WikiUD.”
- It provides marketing pages (hero, pricing), an authentication flow (login), a user dashboard, and a set of JSON API routes (auth, seed, teachers) backed by a database.

##### File Structure Analysis
- Top-level “app” directory
- Divided into route groups: (marketing), (auth), (dashboard)
- Each group has its own layout.tsx and page.tsx components
- API routes under app/api:
– /auth/[...nextauth]/route.ts (NextAuth)
– /seed/route.ts (database seeding)
– /teachers/route.ts (teacher data CRUD)
- “components” directory
- Reusable UI components, design system primitives, theme provider
- “hooks” directory
- Custom React hooks for toasts, mounting, scroll lock
- “lib” directory
- Core utilities: auth.ts, db.ts (DB client), session.ts, string-utils, etc.
- services subfolder (lib/services):
– auth.service.ts
– teacher.service.ts
- validations and validators (user, username)
- Configuration and tooling
- next.config.js, tsconfig.json, tailwind.config.ts, PostCSS, ESLint, DevContainer, GitHub workflows

##### Key Architectural Patterns
- UI layer (React, Next.js app directory) separated from service layer (API routes + lib/services)
- Service layer abstracts data access and business logic in lib/services
- Authentication using NextAuth (app/api/auth) integrated with session management
- Database access via db.ts client, used by services and seed route
- CSS-in-JS via Tailwind + globals.css

##### Main Components
a. Browser / Client
- Marketing pages
- Auth pages
- Dashboard pages
- React components & hooks (components/, hooks/)
b. Next.js Server / Edge Functions (app directory)
- Routing & rendering engine
- API Routes (auth, seed, teachers)
c. Service Layer (lib/services)
- auth.service.ts
- teacher.service.ts
d. Database (db client in lib/db.ts, e.g., PostgreSQL or Mongo)
e. External Services
- OAuth providers via NextAuth (Google, GitHub, etc.)
f. Static Asset Store (public/)

##### Relationships and Data Flows
- Client → Next.js Server: HTTP GET/POST for pages (SSR/SSG) and API calls
- Next.js API Route → Service Layer (lib/services) → Database
- NextAuth API → External OAuth Providers & DB session store → Client session cookie
- Dashboard components call the /teachers API for CRUD operations via teacher.service → db
- Seed route populates initial data via lib/services

##### Essential Elements to Capture
- Clear labels for every major directory (“app”, “components”, “lib/services”)
- Explicit inclusion of lib/services per instructions

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "UI Layer" 
        direction TB
        subgraph "Marketing Pages" 
            direction TB
            MP_Layout["app/(marketing)/layout.tsx"]:::ui
            MP_Page["app/(marketing)/page.tsx"]:::ui
            MP_Hero["app/(marketing)/hero/page.tsx"]:::ui
            MP_Pricing["app/(marketing)/pricing/page.tsx"]:::ui
        end
        subgraph "Auth Pages"
            direction TB
            Auth_Layout["app/(auth)/layout.tsx"]:::ui
            Auth_Login["app/(auth)/login/page.tsx"]:::ui
        end
        subgraph "Dashboard Pages"
            direction TB
            Dash_Layout["app/(dashboard)/layout.tsx"]:::ui
            Dash_Page["app/(dashboard)/dashboard/page.tsx"]:::ui
        end
        Components["components/*"]:::ui
        Hooks["hooks/*"]:::ui
    end

    %% Next.js Server
    subgraph "Next.js Server" 
        direction TB
        Rendering["Routing & Rendering Engine"]:::ui
        subgraph "API Routes"
            direction TB
            Auth_API["app/api/auth/[...nextauth]/route.ts"]:::api
            Seed_API["app/api/seed/route.ts"]:::api
            Teacher_API["app/api/teachers/route.ts"]:::api
        end
    end

    %% Service Layer
    subgraph "Service Layer (lib/services)"
        direction TB
        Auth_Service["lib/services/auth.service.ts"]:::service
        Teacher_Service["lib/services/teacher.service.ts"]:::service
    end

    %% Database
    DB["Database (lib/db.ts)"]:::db

    %% External OAuth
    OAuth["OAuth Providers"]:::external

    %% Static Assets
    Assets["Static Assets (public/)"]:::storage

    %% Flows
    Components -->|uses| Rendering
    Hooks -->|uses| Rendering
    MP_Layout -->|renders| Rendering
    MP_Page -->|renders| Rendering
    MP_Hero -->|renders| Rendering
    MP_Pricing -->|renders| Rendering
    Auth_Layout -->|renders| Rendering
    Auth_Login -->|renders| Rendering
    Dash_Layout -->|renders| Rendering
    Dash_Page -->|renders| Rendering

    Rendering -->|SSR/SSG GET/POST| Auth_API
    Rendering -->|SSR/SSG GET/POST| Seed_API
    Rendering -->|SSR/SSG GET/POST| Teacher_API

    Auth_API -->|calls| Auth_Service
    Seed_API -->|calls| Teacher_Service
    Teacher_API -->|calls| Teacher_Service

    Auth_Service -->|queries| DB
    Teacher_Service -->|queries| DB

    Auth_API -->|↔| OAuth
    Auth_API -->|session store| DB

    Assets -->|delivers static| Rendering

    %% Click events
    click MP_Layout "https://github.com/wallyway/wikiud/blob/main/app/(marketing)/layout.tsx"
    click MP_Page "https://github.com/wallyway/wikiud/blob/main/app/(marketing)/page.tsx"
    click MP_Hero "https://github.com/wallyway/wikiud/blob/main/app/(marketing)/hero/page.tsx"
    click MP_Pricing "https://github.com/wallyway/wikiud/blob/main/app/(marketing)/pricing/page.tsx"
    click Auth_Layout "https://github.com/wallyway/wikiud/blob/main/app/(auth)/layout.tsx"
    click Auth_Login "https://github.com/wallyway/wikiud/blob/main/app/(auth)/login/page.tsx"
    click Dash_Layout "https://github.com/wallyway/wikiud/blob/main/app/(dashboard)/layout.tsx"
    click Dash_Page "https://github.com/wallyway/wikiud/blob/main/app/(dashboard)/dashboard/page.tsx"
    click Components "https://github.com/wallyway/wikiud/tree/main/components"
    click Hooks "https://github.com/wallyway/wikiud/tree/main/hooks"
    click Auth_API "https://github.com/wallyway/wikiud/blob/main/app/api/auth/[...nextauth]/route.ts"
    click Seed_API "https://github.com/wallyway/wikiud/blob/main/app/api/seed/route.ts"
    click Teacher_API "https://github.com/wallyway/wikiud/blob/main/app/api/teachers/route.ts"
    click Auth_Service "https://github.com/wallyway/wikiud/blob/main/lib/services/auth.service.ts"
    click Teacher_Service "https://github.com/wallyway/wikiud/blob/main/lib/services/teacher.service.ts"
    click DB "https://github.com/wallyway/wikiud/blob/main/lib/db.ts"
    click OAuth "https://github.com/wallyway/wikiud/tree/main/public"
    click Assets "https://github.com/wallyway/wikiud/tree/main/public"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef api fill:#D4F8E8,stroke:#059669,color:#059669;
    classDef service fill:#FFE4B5,stroke:#D97706,color:#D97706;
    classDef db fill:#FCE7F3,stroke:#DB2777,color:#DB2777,stroke-width:2px;
    classDef external fill:#E0E7FF,stroke:#4338CA,color:#4338CA,stroke-dasharray: 5 5;
    classDef storage fill:#F0FDF4,stroke:#10B981,color:#10B981,stroke-dasharray: 5 5;
```
