# khai-pi/co-oder architecture

> Architecture diagram of the GitHub repository khai-pi/co-oder, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/khai-pi/co-oder
- Repository: https://github.com/khai-pi/co-oder

## Overview

##### Main System Components

A. Frontend Layer
- Sub-components for:
- Pages (src/app/*)
- Components (src/components/)
- Context (auth-context)
- UI Components (src/components/ui/)

B. API Layer
- Distinct sections for:
- Auth APIs (/api/auth/*)
- User APIs (/api/users)
- Project APIs (/api/projects)

C. Service Layer
- Services for:
- Auth Services
- User Services
- Project Services

D. Database Layer
- Main entities:
- Users
- Projects
- Auth Tables

##### Component Relationships

- Client → API Routes (HTTP requests)
- API Routes → Service Layer (Internal calls)
- Service Layer → Database (Prisma queries)
- Auth Context → Auth APIs (Session management)

##### Key Architectural Elements

Important architectural patterns:
- Next.js App Router architecture
- API Route handlers
- Service-based architecture
- Prisma ORM integration

**┌─ Client Layer ─────────────────┐**
- Pages                        │
- Components                   │
- Auth Context                 │
- UI Components               │
- ┬───────────────┘
- ↓
**┌─ API Layer ────────────────────┐**
- Auth Routes                  │
- User Routes                  │
- Project Routes              │
- ┬───────────────┘
- ↓
**┌─ Service Layer ────────────────┐**
- Auth Services               │
- User Services              │
- Project Services           │
- ┬───────────────┘
- ↓
**┌─ Database Layer ───────────────┐**
- Users                        │
- Projects                     │
- Auth Tables                  │
- ┘

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef service fill:#f1c40f,stroke:#f39c12,color:black
    classDef database fill:#9b59b6,stroke:#8e44ad,color:white
    classDef middleware fill:#e74c3c,stroke:#c0392b,color:white
    classDef utils fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Legend
    subgraph Legend
        F[Frontend]:::frontend
        A[API]:::api
        S[Service]:::service
        D[Database]:::database
        M[Middleware]:::middleware
        U[Utils]:::utils
    end

    %% Frontend Layer
    subgraph "Client Side"
        Pages["Pages"]:::frontend
        UIComps["UI Components"]:::frontend
        SharedComps["Shared Components"]:::frontend
        ProjectComps["Project Components"]:::frontend
        HomeComps["Home Components"]:::frontend
        AuthContext["Auth Context"]:::frontend
    end

    %% Middleware Layer
    MW["Middleware"]:::middleware

    %% API Layer
    subgraph "API Routes"
        AuthAPI["Auth APIs"]:::api
        UserAPI["User APIs"]:::api
        ProjectAPI["Project APIs"]:::api
    end

    %% Service Layer
    subgraph "Services"
        AuthService["Auth Services"]:::service
        UserService["User Services"]:::service
        ProjectService["Project Services"]:::service
    end

    %% Database Layer
    subgraph "Database"
        DBSchema["Database Schema"]:::database
        DBClient["Database Client"]:::database
    end

    %% Utils
    subgraph "Utilities"
        Types["Type Definitions"]:::utils
        Utils["Utility Functions"]:::utils
    end

    %% Relationships
    Pages --> MW
    UIComps --> MW
    SharedComps --> MW
    ProjectComps --> MW
    HomeComps --> MW
    AuthContext --> AuthAPI
    MW --> AuthAPI
    MW --> UserAPI
    MW --> ProjectAPI
    AuthAPI --> AuthService
    UserAPI --> UserService
    ProjectAPI --> ProjectService
    AuthService --> DBClient
    UserService --> DBClient
    ProjectService --> DBClient
    DBClient --> DBSchema

    %% Click events
    click Pages "https://github.com/khai-pi/co-oder/tree/main/src/app/*"
    click UIComps "https://github.com/khai-pi/co-oder/tree/main/src/components/ui/"
    click SharedComps "https://github.com/khai-pi/co-oder/tree/main/src/components/shared/"
    click ProjectComps "https://github.com/khai-pi/co-oder/tree/main/src/components/projects/"
    click HomeComps "https://github.com/khai-pi/co-oder/tree/main/src/components/home/"
    click AuthContext "https://github.com/khai-pi/co-oder/blob/main/src/context/auth-context.tsx"
    click AuthAPI "https://github.com/khai-pi/co-oder/tree/main/src/app/api/auth/"
    click UserAPI "https://github.com/khai-pi/co-oder/tree/main/src/app/api/users/"
    click ProjectAPI "https://github.com/khai-pi/co-oder/tree/main/src/app/api/projects/"
    click AuthService "https://github.com/khai-pi/co-oder/tree/main/src/lib/services/auth/"
    click UserService "https://github.com/khai-pi/co-oder/tree/main/src/lib/services/users/"
    click ProjectService "https://github.com/khai-pi/co-oder/blob/main/src/lib/services/projects.ts"
    click DBSchema "https://github.com/khai-pi/co-oder/blob/main/prisma/schema.prisma"
    click DBClient "https://github.com/khai-pi/co-oder/blob/main/src/lib/prisma.ts"
    click Types "https://github.com/khai-pi/co-oder/tree/main/src/types/"
    click MW "https://github.com/khai-pi/co-oder/blob/main/src/middleware.ts"
    click Utils "https://github.com/khai-pi/co-oder/tree/main/src/lib/utils/"
```
