# sullyo/webapp-starter architecture

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

- Interactive diagram: https://gitdiagram.com/sullyo/webapp-starter
- Repository: https://github.com/sullyo/webapp-starter

## Overview

##### Project Overview
- The project is a modern full-stack SaaS template using Turborepo:
– Backend: Bun API built with Hono, Drizzle ORM, and integrates with Supabase (or any Postgres DB).
– Frontend: Next.js with Tailwind CSS and Shadcn/ui for the UI, utilizing Clerk for authentication.
– Shared packages: Include the DB package (with Drizzle configurations and schema), an ID generation package, logs, and a common TypeScript configuration package.

##### And List Main Components (from top to bottom)
- At the Top:
– External Services & Deployment Platforms:
- Supabase (or any PostgreSQL solution)
- Clerk authentication (plus Clerk Webhooks for user sync)
- Deployment targets: Vercel (for the Next.js frontend) and Render (for the Bun API)
- Other integrations: Ngrok for tunneling (during development)

- Next Tier:
– API Backend ("apps/api"):
- Modules (like posts, webhooks) that handle business logic, routes, and middleware (JWT, Clerk auth, error handling).
- Core Service Layers: Expressed via source files in apps/api/src/modules.
- Utility functions and custom middleware under apps/api/src/pkg.

- Following Tier:
– Frontend Web ("apps/web"):
- Next.js application structure with routes (marketing, auth, posts) and shared components (UI elements, hooks, and providers like Query and Theme Providers).
- API interactions: Client-side API utilities that connect to the backend.

- Lower Tier (Shared Packages):
– Packages that hold shared logic and configuration:
- packages/db: Contains database configuration (Drizzle ORM client, schema, types, utilities).
- packages/id: Provides unique ID generation.
- packages/logs: Contains logging utilities.
- packages/typescript-config: Centralized TypeScript config templates for various app aspects.

##### Displaying Relationships and Data Flow Vertically
1. External Service (Clerk, Supabase) at the top feeding credentials and database connectivity downwards into the API.
2. The API backend communicates with the shared DB package (for database interactions) and exposes endpoints consumed by the Web frontend.

##### Design Principles and Architectural Patterns
- Clearly separate concerns by isolating API modules, frontend pages/components, and shared libraries.
- A microservices-like modular structure in the API (individual modules for posts, webhooks, etc.).
- Middleware usage that centralizes authentication and error handling procedures.

##### Essential Architectural Elements
- Clear boundaries for each component (API vs. Web vs. Shared Packages) and show how these interact.

- Use a vertical flow layout: Top (External Services & Deployment) → Middle (API Backend, Frontend Web) → Bottom (Shared Packages and Utilities).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External & Deployment Layer
    subgraph "External & Deployment"
        E1["Clerk authentication"]:::clerkStyle
        E2["Supabase DB"]:::supabaseStyle
        E3["Ngrok (Dev)"]:::external
        E4["Vercel (Frontend Deployment)"]:::deploymentStyle
        E5["Render (API Deployment)"]:::deploymentStyle
    end

    %% API Backend Layer
    subgraph "API Backend"
        A1["API Backend (apps/api)"]:::apiStyle
        A2["API Modules: Posts (apps/api/src/modules/posts)"]:::apiStyle
        A3["API Modules: Webhooks (apps/api/src/modules/webhooks)"]:::apiStyle
        A4["API Middleware (apps/api/src/pkg/middleware)"]:::apiStyle
        A5["API Utility Functions (apps/api/src/pkg/util)"]:::apiStyle
    end

    %% Frontend Web Layer
    subgraph "Frontend Web"
        F1["Frontend Web Application (apps/web)"]:::frontendStyle
        F2["Client-side API Utilities (apps/web/src/api)"]:::frontendStyle
        F3["Frontend Components & UI (apps/web/src/components)"]:::frontendStyle
    end

    %% Shared Packages Layer
    subgraph "Shared Packages & Utilities"
        S1["Shared Database Package (packages/db)"]:::sharedStyle
        S2["Shared ID Generation Package (packages/id)"]:::sharedStyle
        S3["Shared Logging Utilities Package (packages/logs)"]:::sharedStyle
        S4["Shared TypeScript Configuration (packages/typescript-config)"]:::sharedStyle
    end

    %% External & Deployment to Internal Components
    E5 --> A1
    E4 --> F1
    E1 --> A4
    E2 --> A1
    E3 --> A1

    %% Internal API Flow
    A1 --> A2
    A2 --> A3
    A3 --> A4
    A4 --> A5

    %% Frontend Internal Flow
    F1 --> F2
    F2 --> F3

    %% Communication Between Frontend and API
    F1 -- "CallsAPI" --> A1

    %% API Backend and Shared Packages Interaction
    A1 -- "DBConn" --> S1
    A1 -- "IDGen" --> S2
    A1 -- "Logging" --> S3
    A1 -- "TSConfig" --> S4

    %% Frontend and Shared Packages Interaction
    F1 -- "TSConfig" --> S4

    %% Click Events for API Backend
    click A1 "https://github.com/sullyo/webapp-starter/tree/main/apps/api"
    click A2 "https://github.com/sullyo/webapp-starter/tree/main/apps/api/src/modules/posts"
    click A3 "https://github.com/sullyo/webapp-starter/tree/main/apps/api/src/modules/webhooks"
    click A4 "https://github.com/sullyo/webapp-starter/tree/main/apps/api/src/pkg/middleware"
    click A5 "https://github.com/sullyo/webapp-starter/tree/main/apps/api/src/pkg/util"

    %% Click Events for Frontend
    click F1 "https://github.com/sullyo/webapp-starter/tree/main/apps/web"
    click F2 "https://github.com/sullyo/webapp-starter/tree/main/apps/web/src/api"
    click F3 "https://github.com/sullyo/webapp-starter/tree/main/apps/web/src/components"

    %% Click Events for Shared Packages
    click S1 "https://github.com/sullyo/webapp-starter/tree/main/packages/db"
    click S2 "https://github.com/sullyo/webapp-starter/tree/main/packages/id"
    click S3 "https://github.com/sullyo/webapp-starter/tree/main/packages/logs"
    click S4 "https://github.com/sullyo/webapp-starter/tree/main/packages/typescript-config"

    %% Styles
    classDef clerkStyle fill:#0000FF,stroke:#000,stroke-width:1px,color:#fff;
    classDef supabaseStyle fill:#008000,stroke:#000,stroke-width:1px,color:#fff;
    classDef external fill:#ADD8E6,stroke:#000,stroke-width:1px,color:#000;
    classDef deploymentStyle fill:#FFFF00,stroke:#000,stroke-width:1px,color:#000;
    classDef apiStyle fill:#FFA500,stroke:#000,stroke-width:1px,color:#000;
    classDef frontendStyle fill:#800080,stroke:#000,stroke-width:1px,color:#fff;
    classDef sharedStyle fill:#D3D3D3,stroke:#000,stroke-width:1px,color:#000;
```
