# advantailabs/kostra-boilerplate architecture

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

- Interactive diagram: https://gitdiagram.com/advantailabs/kostra-boilerplate
- Repository: https://github.com/advantailabs/kostra-boilerplate

## Overview

Kostra is a Next.js SaaS boilerplate with authentication, subscription billing, file management, and admin-facing content and campaign tools. Its principal workflow is an authenticated user interacting with the app and API; routes validate requests, invoke domain services or repositories, and return results backed by Prisma or external providers. The graph includes those documented capabilities, but sampled source does not establish most page-to-API wiring, so those links are omitted. Some subsystem relationships rely on SOURCE INDEX references or README descriptions rather than full source excerpts.

Main entry points: [`src/services/repositories/user/index.ts`](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/repositories/user/index.ts) (User repository), [`src/app/api/blogs/route.ts`](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/blogs/route.ts) (Blog endpoints), [`src/app/api/files/route.ts`](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/files/route.ts) (File endpoints), [`src/services/internal/auth/auth.ts`](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/internal/auth/auth.ts) (Account services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["App experience"]
  node_app["App Router<br/>[page.tsx]"]
end

subgraph group_identity["Identity and accounts"]
  node_authstate["Auth state<br/>[auth.ts]"]
  node_jwt["JWT authentication<br/>[jwt.ts]"]
  node_authservice["Account services<br/>[auth.ts]"]
  node_authapi["Auth endpoints<br/>[route.ts]"]
end

subgraph group_domains["SaaS domains"]
  node_blogapi["Blog endpoints<br/>[route.ts]"]
  node_categoryapi["Category endpoints<br/>[route.ts]"]
  node_packageapi["Package endpoints<br/>[route.ts]"]
  node_contactapi["Contact endpoints<br/>[route.ts]"]
  node_contactservice["Contact service<br/>[contact.ts]"]
  node_campaignapi["Campaign endpoints<br/>[route.ts]"]
  node_recipientapi["Recipient endpoints<br/>[route.ts]"]
  node_campaignservice["Campaign services<br/>[campaign.ts]"]
  node_recipientservice["Recipient services"]
  node_emailapi["Email template endpoints<br/>[route.ts]"]
  node_fileapi["File endpoints<br/>[route.ts]"]
  node_fileservice["File services<br/>[file.ts]"]
end

subgraph group_integrations["External integrations"]
  node_billing["Stripe billing<br/>[stripe.ts]"]
  node_stripewebhook["Stripe webhook handlers"]
  node_emaildriver["Email delivery<br/>[factory.ts]"]
  node_s3["AWS S3 storage<br/>[s3.ts]"]
end

subgraph group_data["Persistence"]
  node_blogrepo["Blog repository<br/>[index.ts]"]
  node_packagerepo["Package repository<br/>[index.ts]"]
  node_userrepo["User repository<br/>[index.ts]"]
  node_contactrepo["Contact repository<br/>[index.ts]"]
  node_prisma[("Prisma database<br/>[index.ts]")]
end

node_user(("SaaS user"))

node_user -->|"uses"| node_app
node_app -.->|"maintains session"| node_authstate
node_authapi -->|"delegates"| node_authservice
node_authservice -->|"issues tokens"| node_jwt
node_authservice -->|"reads and writes"| node_userrepo
node_authstate -->|"stores session"| node_user
node_blogapi -->|"authenticates"| node_jwt
node_blogapi -->|"loads author"| node_userrepo
node_blogapi -->|"creates and lists"| node_blogrepo
node_categoryapi -.->|"manages categories"| node_categoryapi
node_packageapi -->|"creates and lists"| node_packagerepo
node_contactapi -->|"delegates"| node_contactservice
node_contactservice -->|"persists submissions"| node_contactrepo
node_campaignapi -->|"delegates"| node_campaignservice
node_recipientapi -->|"delegates"| node_recipientservice
node_emailapi -->|"checks account"| node_userrepo
node_fileapi -->|"authenticates"| node_jwt
node_fileapi -->|"loads account"| node_userrepo
node_fileapi -->|"lists and uploads"| node_fileservice
node_stripewebhook -->|"updates plans"| node_userrepo
node_stripewebhook -->|"retrieves invoice"| node_billing
node_fileservice -.->|"stores files"| node_s3
node_userrepo -->|"queries"| node_prisma
node_contactapi -->|"checks identity"| node_userrepo

click node_app "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/app/page.tsx"
click node_authstate "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/store/auth.ts"
click node_jwt "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/lib/auth/jwt.ts"
click node_authservice "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/internal/auth/auth.ts"
click node_authapi "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/auth/route.ts"
click node_blogapi "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/blogs/route.ts"
click node_blogrepo "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/repositories/blogs/index.ts"
click node_categoryapi "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/categories/route.ts"
click node_packageapi "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/packages/route.ts"
click node_packagerepo "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/repositories/packages/index.ts"
click node_contactapi "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/contact/route.ts"
click node_contactservice "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/internal/contact.ts"
click node_campaignapi "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/campaigns/route.ts"
click node_recipientapi "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/campaign-recipients/route.ts"
click node_campaignservice "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/internal/campaign.ts"
click node_recipientservice "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/internal/campaign-recipient.ts"
click node_emailapi "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/email-templates/route.ts"
click node_fileapi "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/files/route.ts"
click node_fileservice "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/internal/files/file.ts"
click node_billing "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/external/stripe/stripe.ts"
click node_stripewebhook "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/external/stripe/webhook-event-handlers.ts"
click node_emaildriver "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/lib/email/factory.ts"
click node_s3 "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/external/aws/s3.ts"
click node_userrepo "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/repositories/user/index.ts"
click node_contactrepo "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/repositories/contact/index.ts"
click node_prisma "https://github.com/advantailabs/kostra-boilerplate/blob/main/src/lib/prisma/index.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_user toneBlue
class node_authstate,node_jwt,node_authservice,node_authapi toneAmber
class node_blogapi,node_categoryapi,node_packageapi,node_contactapi,node_contactservice,node_campaignapi,node_recipientapi,node_campaignservice,node_recipientservice,node_emailapi,node_fileapi,node_fileservice toneMint
class node_billing,node_stripewebhook,node_emaildriver,node_s3 toneRose
class node_blogrepo,node_packagerepo,node_userrepo,node_contactrepo,node_prisma toneIndigo
```

## Components

### App experience

- [App Router](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/app/page.tsx): `src/app/app/page.tsx`

### Identity and accounts

- [Auth state](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/store/auth.ts): `src/store/auth.ts`
- [JWT authentication](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/lib/auth/jwt.ts): `src/lib/auth/jwt.ts`
- [Account services](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/internal/auth/auth.ts): `src/services/internal/auth/auth.ts`
- [Auth endpoints](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/auth/route.ts): `src/app/api/auth/route.ts`

### SaaS domains

- [Blog endpoints](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/blogs/route.ts): `src/app/api/blogs/route.ts`
- [Category endpoints](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/categories/route.ts): `src/app/api/categories/route.ts`
- [Package endpoints](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/packages/route.ts): `src/app/api/packages/route.ts`
- [Contact endpoints](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/contact/route.ts): `src/app/api/contact/route.ts`
- [Contact service](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/internal/contact.ts): `src/services/internal/contact.ts`
- [Campaign endpoints](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/campaigns/route.ts): `src/app/api/campaigns/route.ts`
- [Recipient endpoints](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/campaign-recipients/route.ts): `src/app/api/campaign-recipients/route.ts`
- [Campaign services](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/internal/campaign.ts): `src/services/internal/campaign.ts`
- [Recipient services](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/internal/campaign-recipient.ts): `src/services/internal/campaign-recipient.ts`
- [Email template endpoints](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/email-templates/route.ts): `src/app/api/email-templates/route.ts`
- [File endpoints](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/app/api/files/route.ts): `src/app/api/files/route.ts`
- [File services](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/internal/files/file.ts): `src/services/internal/files/file.ts`

### External integrations

- [Stripe billing](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/external/stripe/stripe.ts): `src/services/external/stripe/stripe.ts`
- [Stripe webhook handlers](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/external/stripe/webhook-event-handlers.ts): `src/services/external/stripe/webhook-event-handlers.ts`
- [Email delivery](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/lib/email/factory.ts): `src/lib/email/factory.ts`
- [AWS S3 storage](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/external/aws/s3.ts): `src/services/external/aws/s3.ts`

### Persistence

- [Blog repository](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/repositories/blogs/index.ts): `src/services/repositories/blogs/index.ts`
- [Package repository](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/repositories/packages/index.ts): `src/services/repositories/packages/index.ts`
- [User repository](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/repositories/user/index.ts): `src/services/repositories/user/index.ts`
- [Contact repository](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/services/repositories/contact/index.ts): `src/services/repositories/contact/index.ts`
- [Prisma database](https://github.com/advantailabs/kostra-boilerplate/blob/main/src/lib/prisma/index.ts): `src/lib/prisma/index.ts`

### Other components

- **SaaS user**

## Connections

- SaaS user → App Router: uses (evidence: `README.md`)
- App Router → Auth state: maintains session
- Auth endpoints → Account services: delegates (evidence: `src/services/internal/auth/auth.ts`)
- Account services → JWT authentication: issues tokens (evidence: `src/services/internal/auth/auth.ts`)
- Account services → User repository: reads and writes (evidence: `src/services/internal/auth/auth.ts`)
- Auth state → SaaS user: stores session (evidence: `src/store/auth.ts`)
- Blog endpoints → JWT authentication: authenticates (evidence: `src/app/api/blogs/route.ts`)
- Blog endpoints → User repository: loads author (evidence: `src/app/api/blogs/route.ts`)
- Blog endpoints → Blog repository: creates and lists (evidence: `src/app/api/blogs/route.ts`)
- Category endpoints → Category endpoints: manages categories (evidence: `src/app/api/categories/route.ts`)
- Package endpoints → Package repository: creates and lists (evidence: `src/app/api/packages/route.ts`)
- Contact endpoints → Contact service: delegates (evidence: `src/app/api/contact/route.ts`)
- Contact service → Contact repository: persists submissions (evidence: `src/services/internal/contact.ts`)
- Campaign endpoints → Campaign services: delegates (evidence: `src/app/api/campaigns/route.ts`)
- Recipient endpoints → Recipient services: delegates (evidence: `src/app/api/campaign-recipients/route.ts`)
- Email template endpoints → User repository: checks account (evidence: `src/app/api/email-templates/route.ts`)
- File endpoints → JWT authentication: authenticates (evidence: `src/app/api/files/route.ts`)
- File endpoints → User repository: loads account (evidence: `src/app/api/files/route.ts`)
- File endpoints → File services: lists and uploads (evidence: `src/app/api/files/route.ts`)
- Stripe webhook handlers → User repository: updates plans (evidence: `src/services/external/stripe/webhook-event-handlers.ts`)
- Stripe webhook handlers → Stripe billing: retrieves invoice (evidence: `src/services/external/stripe/webhook-event-handlers.ts`)
- File services → AWS S3 storage: stores files
- User repository → Prisma database: queries (evidence: `src/services/repositories/user/index.ts`)
- Contact endpoints → User repository: checks identity (evidence: `src/app/api/contact/route.ts`)
