### Manual Environment Variable Setup (Shell) Source: https://starter.yuris.dev/docs/installation Provides an alternative to the automated script for setting up environment variables. It involves manually copying example files and generating a secret key for the authentication server. ```shell # Copy example files cp apps/auth/.env.example apps/auth/.env cp apps/api/.env.example apps/api/.env cp apps/mcp/.env.example apps/mcp/.env cp packages/database/.env.example packages/database/.env # Generate auth secret openssl rand -base64 32 ``` -------------------------------- ### Navigate and Install Dependencies using PNPM Source: https://starter.yuris.dev/docs/installation This snippet shows how to navigate into the cloned project directory and install its dependencies using the pnpm package manager. This is a crucial step before running or developing the project. Ensure pnpm is installed globally. ```bash cd starter-kit pnpm install ``` -------------------------------- ### Run Database Setup and Migrations (Shell) Source: https://starter.yuris.dev/docs/installation This command initializes the database schema by generating Drizzle schema files and applying them to the running PostgreSQL instance. It ensures the database is ready for the application. ```shell pnpm db:setup ``` -------------------------------- ### Project Setup and Environment Variables Source: https://starter.yuris.dev/docs/installation This section describes the use of .env files for managing environment variables within the project. It highlights that an automated setup script is available to simplify this process, rather than manual file creation. This is essential for configuring the application's runtime settings. ```markdown The project uses .env files for managing environment variables. Instead of manually creating each\\nfile, you can use our automated setup script: ``` -------------------------------- ### Automated Environment Variable Setup (Shell) Source: https://starter.yuris.dev/docs/installation This command automates the process of copying environment variable example files to their active counterparts and generating a secure secret for the auth server. It ensures that existing configurations are preserved. ```shell pnpm setup:env ``` -------------------------------- ### Start PostgreSQL Database with Docker Source: https://starter.yuris.dev/docs/installation Starts a PostgreSQL database in detached mode using Docker. It sets a password for the 'postgres' user and assigns a name to the container. This command requires Docker to be installed and running. ```shell docker run -d --name auth-postgres -e POSTGRES_PASSWORD=password postgres ``` -------------------------------- ### Manual Environment File Copying Source: https://starter.yuris.dev/docs/installation Provides manual commands to copy example environment files to their respective .env files for different applications and packages. This method allows for granular control over environment configuration. ```shell # Copy example files cp apps/auth/.env.example apps/auth/.env cp apps/api/.env.example apps/api/.env cp apps/mcp/.env.example apps/mcp/.env cp packages/database/.env.example packages/database/.env ``` -------------------------------- ### Clone Project Repository using Git Source: https://starter.yuris.dev/docs/installation This snippet demonstrates how to clone the project repository from GitHub using the git clone command. It ensures you have a local copy of the project to work with. No specific dependencies are required beyond having Git installed. ```bash git clone https://github.com/yurisasc/starter-kit.git ``` -------------------------------- ### Install Dependencies with PNPM Source: https://starter.yuris.dev/docs/installation This code snippet demonstrates how to install project dependencies using the PNPM package manager. It's a common command-line operation for Node.js projects that utilize PNPM. Ensure PNPM is installed globally before running. ```shell pnpm install ``` -------------------------------- ### Development Commands (Bash) Source: https://context7_llms Commands for starting development servers. Includes options to start all servers or only application servers. Requires pnpm to be installed. ```bash # Start all development servers + Drizzle Studio pnpm dev # Start only the application development servers pnpm dev:app ``` -------------------------------- ### Project Installation (Bash) Source: https://context7_llms Commands to clone the repository, install dependencies using pnpm, and set up environment variables. Assumes Git, Node.js, and pnpm are installed. ```bash git clone https://github.com/yurisasc/starter-kit.git cd starter-kit pnpm install ``` -------------------------------- ### Development: Start All Development Servers Source: https://starter.yuris.dev/llms-full.txt Command to start all development servers, including the Auth server, API server, Documentation site, and Drizzle Studio. ```bash pnpm dev ``` -------------------------------- ### Example CLI Command for better-auth (Shell) Source: https://www.better-auth.com/docs This snippet illustrates a command-line instruction using pnpm to install and run the better-auth CLI. It includes the package name, scope, and the '--manual' flag, indicating a manual setup process. The command also specifies a URL for the better-auth builder. ```shell pnpm @better-auth/cli mcp --manual "url": "https://mcp.chonkie.ai/better-auth/better-auth-builder/mcp" ``` -------------------------------- ### Docker PostgreSQL Setup (Bash) Source: https://context7_llms Command to start a PostgreSQL database container using Docker. Configures name, password, database name, and port mapping. ```bash docker run -d \ --name auth-postgres \ -e POSTGRES_PASSWORD=password \ -e POSTGRES_DB=auth_db \ -p 5432:5432 \ postgres:18 ``` -------------------------------- ### Configure PostgreSQL Database Connection Source: https://starter.yuris.dev/docs/installation This snippet shows how to configure the PostgreSQL database connection using environment variables. It specifies the database name, host, and port. ```bash #!/bin/bash export POSTGRES_DB=auth_db ``` -------------------------------- ### Environment Setup Script (Bash) Source: https://context7_llms Automated script to copy .env.example files to .env and generate secrets. Skips existing files. Alternatively, manual setup instructions are provided. ```bash # Run the automated environment setup script pnpm setup:env # Manual setup (Alternative) # Copy example files cp apps/auth/.env.example apps/auth/.env cp apps/api/.env.example apps/api/.env cp apps/mcp/.env.example apps/mcp/.env cp packages/database/.env.example packages/database/.env # Generate auth secret openssl rand -base64 32 ``` -------------------------------- ### Development Server Start (Bash) Source: https://context7_llms Command to start all development servers including Auth, API, Documentation site, and Drizzle Studio. Requires pnpm. ```bash # Start all development servers pnpm dev ``` -------------------------------- ### Development Servers: Start All or Application Only Source: https://starter.yuris.dev/llms-full.txt Commands to start development servers. 'pnpm dev' starts all development servers including Drizzle Studio, while 'pnpm dev:app' starts only the application development servers. ```bash pnpm dev pnpm dev:app ``` -------------------------------- ### Automated Project Setup with pnpm Source: https://www.better-auth.com/docs This command automates the project setup process using pnpm. It installs necessary dependencies and configures the project for using Claude Code or Open Code. ```shell pnpm @better-auth/cli mcp --claude-code ``` ```shell pnpm @better-auth/cli mcp --open-code ``` -------------------------------- ### Install pnpm on Windows using PowerShell Source: https://pnpm.io/installation This snippet shows how to install pnpm on a Windows system using PowerShell. It fetches the installation script from the official pnpm URL and executes it. Note: Microsoft Defender may slow down package installations; a command to add pnpm's store path to exclusions is also provided. ```powershell Invoke-WebRequest https://get.pnpm.io/install.ps1 -UseBasicParsing | Invoke-Expression # To add pnpm store path to Microsoft Defender exclusions (run as administrator): # Add-MpPreference -ExclusionPath $(pnpm store path) ``` -------------------------------- ### Node.js: Basic Server Response Example Source: https://nodejs.org/en This example demonstrates a basic server response setup in Node.js, showing how to define headers such as 'Content-Type'. It's a foundational snippet for understanding HTTP responses. ```javascript ("200", { "Content-Type": "text/plain" }) ``` -------------------------------- ### Node.js HTTP Server Setup Source: https://nodejs.org/en This snippet shows the fundamental setup for an HTTP server in Node.js. It imports the 'http' module and defines a callback function to handle incoming requests and outgoing responses. The server is then started on a specified port. ```javascript import http from "node:http"; const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader("Content-Type", "text/plain"); res.end("Hello, World!\n"); }); const port = 3000; server.listen(port, () => { console.log(`Server running at http://localhost:${port}/`); }); ``` -------------------------------- ### Workspace Protocol Example in package.json Source: https://pnpm.io/workspaces Demonstrates how to use the `workspace:` protocol in `package.json` to ensure dependencies are exclusively linked from local workspace packages. This prevents unexpected installations from the registry and ensures that only versions present within the workspace are used. ```json { "dependencies": { "foo": "workspace:2.0.0" } } ``` -------------------------------- ### Initialize Hono App and Define a Basic Route Source: https://hono.dev/ This snippet shows how to initialize a new Hono application instance and define a simple GET route that responds with 'Hello Hono!'. It demonstrates the core setup for creating a web application with Hono. ```javascript import { Hono } from 'hono'; const app = new Hono(); app.get('/', (c) => c.text('Hello Hono!')); export default app; ``` -------------------------------- ### Start Node.js HTTP Server Source: https://nodejs.org/en This snippet shows how to create and start a basic HTTP server in Node.js. It utilizes the built-in 'http' module to listen for connections on a specified port (3000 in this case) and logs a message indicating the server has started. Dependencies include the Node.js runtime. ```javascript const http = require('http'); const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello, World!\n'); }); const PORT = 3000; server.listen(PORT, () => { console.log(`Server running on http://localhost:${PORT}/`); }); ``` -------------------------------- ### Install pnpm using Scoop Source: https://pnpm.io/installation Installs the latest LTS version of Node.js and pnpm using the Scoop package manager on Windows. This command simplifies the setup for Node.js and pnpm users on Windows. ```shell scoop install nodejs-lts pnpm ``` -------------------------------- ### Environment Setup: Automated and Manual .env File Creation Source: https://starter.yuris.dev/llms-full.txt Commands for setting up environment variables. 'pnpm setup:env' automates copying .env.example files and generating secrets. Manual commands are provided as an alternative. ```bash pnpm setup:env # Manual Setup (Alternative) cp apps/auth/.env.example apps/auth/.env cp apps/api/.env.example apps/api/.env cp apps/mcp/.env.example apps/mcp/.env cp packages/database/.env.example packages/database/.env openssl rand -base64 32 ``` -------------------------------- ### Install pnpm using Choco Source: https://pnpm.io/installation Installs pnpm on Windows systems that have Chocolatey package manager installed. This command leverages Chocolatey for a straightforward installation process. ```shell choco install pnpm ``` -------------------------------- ### Install pnpm with Volta Source: https://pnpm.io/installation This command uses Volta to install the pnpm package manager. Ensure Volta is installed and configured in your environment before running this command. ```bash volta install pnpm ``` -------------------------------- ### Install pnpm using winget Source: https://pnpm.io/installation Installs pnpm on Windows systems with winget package manager. This command ensures that pnpm is installed efficiently within the Windows ecosystem. ```shell winget install -e --id pnpm.pnpm ``` -------------------------------- ### Database Setup with pnpm Source: https://context7_llms This command sets up the database for new projects. It automatically generates the authentication schema, creates necessary migrations, and applies them to the database. ```bash pnpm db:setup # Generates auth schema, creates migrations, and applies them ``` -------------------------------- ### Install pnpm using Homebrew Source: https://pnpm.io/installation Installs pnpm on macOS or Linux systems that have Homebrew package manager installed. This is a convenient method for users already utilizing Homebrew. ```shell brew install pnpm ``` -------------------------------- ### Install Specific pnpm Version via Script Source: https://pnpm.io/installation Installs a specific version of pnpm by setting the PNPM_VERSION environment variable before running the installation script. This method allows for precise version control. ```shell curl -fsSL https://get.pnpm.io/install.sh | env PNPM_VERSION= sh - ``` -------------------------------- ### Install pnpm on POSIX systems using wget Source: https://pnpm.io/installation This command installs pnpm on POSIX-compliant systems (Linux, macOS) using wget. It downloads the installation script quietly and pipes it to the shell for execution. This is an alternative to the curl method if wget is preferred or curl is not installed. ```bash wget -qO- https://get.pnpm.io/install.sh | sh - ``` -------------------------------- ### Install pnpm using npm Source: https://pnpm.io/installation Installs the latest stable version of pnpm globally using npm. Two packages are available: `pnpm` which requires Node.js, and `@pnpm/exe` which is packaged with Node.js for environments without Node.js installed. ```shell npm install -g pnpm@latest-10 ``` ```shell npm install -g @pnpm/exe@latest-10 ``` -------------------------------- ### Build: Production Build for Apps and Packages Source: https://starter.yuris.dev/llms-full.txt Command to build all applications and packages within the monorepo for production deployment. ```bash pnpm build ``` -------------------------------- ### Install pnpm on POSIX systems using curl Source: https://pnpm.io/installation This command installs pnpm on POSIX-compliant systems (Linux, macOS) using curl. It downloads the installation script and pipes it directly to the shell for execution. This method is suitable for environments where curl is available. ```bash curl -fsSL https://get.pnpm.io/install.sh | sh - ``` -------------------------------- ### Database Operations: Schema, Migration, and Studio Source: https://starter.yuris.dev/llms-full.txt Commands for managing the database using Drizzle ORM. Includes generating schema, creating migrations, applying migrations, opening Drizzle Studio, and a full setup command. ```bash pnpm db:schema pnpm db:generate pnpm db:migrate pnpm db:studio pnpm db:setup ``` -------------------------------- ### Install pnpm in Docker containers Source: https://pnpm.io/installation These commands demonstrate how to install pnpm within Docker containers using different shells (bash, sh, dash). They utilize wget to download and execute the installation script, specifying the environment file and shell for proper execution within the container context. ```bash # bash wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.bashrc" SHELL="$(which bash)" bash - # sh wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.shrc" SHELL="$(which sh)" sh - # dash wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.dashrc" SHELL="$(which dash)" dash - ``` -------------------------------- ### Updating Authentication Configuration and Migrating Schema Source: https://starter.yuris.dev/llms-full.txt This section details the command-line steps to update the authentication configuration and apply the corresponding database schema migrations. It involves modifying the auth configuration file, generating the updated auth schema, and then generating and applying the necessary migrations. ```bash # 1. Update Better Auth configuration # Edit apps/auth/src/lib/auth.ts to add fields, plugins, etc. # 2. Generate updated auth schema pnpm db:schema # 3. Generate and apply migration pnpm db:generate && pnpm db:migrate ``` -------------------------------- ### Uninstall pnpm Package Manager Source: https://pnpm.io/installation This section refers to the process of completely removing the pnpm CLI and any associated files from your system. For detailed instructions, users should consult the uninstallation guide. ```markdown See [Uninstalling pnpm](/uninstall). ``` -------------------------------- ### Database Management Commands (Bash) Source: https://context7_llms Commands for managing the project's database using Drizzle ORM. Includes schema generation, migration, and studio access. Requires pnpm and Docker. ```bash # Generate auth schema from Better Auth config pnpm db:schema # Generate a new SQL migration from schema changes pnpm db:generate # Apply all pending migrations to the database pnpm db:migrate # Open the Drizzle Studio GUI in your browser pnpm db:studio # Run the complete setup: schema -> generate -> migrate pnpm db:setup ``` -------------------------------- ### Build Command (Bash) Source: https://context7_llms Command to build all applications and packages within the monorepo for production deployment. Executed using pnpm. ```bash # Build all apps and packages for production pnpm build ``` -------------------------------- ### Generating and Migrating Custom Data Models Source: https://starter.yuris.dev/llms-full.txt This command-line instruction is used after defining custom data models to generate and apply the necessary database migrations. It ensures that the changes made to the schema are reflected in the actual database. ```bash # Generate and apply migration pnpm db:generate && pnpm db:migrate ``` -------------------------------- ### Troubleshooting pnpm Module Not Found Error Source: https://pnpm.io/installation This section details how to troubleshoot a 'MODULE_NOT_FOUND' error when running 'pnpm install'. It involves finding the pnpm executable location, manually removing pnpm files from the directory, and then reinstalling pnpm. ```bash which pnpm ``` ```bash where.exe pnpm.* ``` -------------------------------- ### Database Schema Generation and Migration Workflow Source: https://starter.yuris.dev/llms-full.txt This workflow illustrates the process of generating and migrating database schemas. It begins with Better Auth configuration, leading to generated authentication schemas, custom schemas, SQL migrations, and finally, the PostgreSQL database. Commands like `pnpm db:schema`, `pnpm db:generate`, and `pnpm db:migrate` are used. ```mermaid graph TD A["Better Auth Config
(apps/auth/src/lib/auth.ts)"] -->|"pnpm db:schema"| E["Generated Auth Schema
(packages/database/src/schema/auth.ts)"]; C["Custom Schemas
(packages/database/src/schema/resources.ts)"] -->|"pnpm db:generate"| F["SQL Migrations
(packages/database/drizzle/migrations/)"]; E -->|"pnpm db:generate"| F; F -->|"pnpm db:migrate"| H[PostgreSQL Database]; ``` -------------------------------- ### Database Schema Generation Workflow Source: https://context7_llms This section outlines the command-line workflow for managing database schema changes, including generating new schemas, creating migrations, and applying them to the database. It covers both authentication-related schemas and custom data models. ```bash pnpm db:schema pnpm db:generate && pnpm db:migrate ``` -------------------------------- ### Auth Server API Source: https://starter.yuris.dev/llms-full.txt Handles user authentication (sign-up, sign-in, sign-out) and issues tokens. Supports both web and API clients. ```APIDOC ## Auth Server API ### Purpose This is the dedicated **Authentication Server** for the project. Built with Hono and powered by [Better Auth](https://www.better-auth.com/), its sole responsibility is to handle user authentication (sign-up, sign-in, sign-out) and issue tokens. It acts as the central authority for user identity. ### The Hybrid Token Flow The Auth Server employs a hybrid approach to support both traditional web applications and modern clients (like mobile apps or SPAs). * **Web Clients**: Use secure, `HttpOnly` session cookies for authenticating to the primary application. * **API/Mobile Clients**: Use short-lived JWT (JSON Web Token) Bearer Tokens for all API communication. **Flow Description:** 1. **Authentication**: A user logs in against the Auth Server. A web client gets a session cookie, while a mobile client gets a session token. 2. **Token Issuance**: When a client needs to access a resource server, it makes an authenticated request to the Auth Server to get a short-lived JWT. 3. **API Access**: The client includes this JWT in the `Authorization` header for all requests to the resource servers. 4. **Verification**: The resource servers verify the JWT's signature by fetching public keys from the Auth Server's JWKS endpoint (`/api/v1/auth/jwks`). ### Security Considerations * **Stolen JWTs**: Because JWTs are stateless, a stolen token can be used by an attacker until it expires. **Our primary defense is keeping token lifetimes short (15 minutes)**. This limits the window of opportunity for an attacker. * **JWKS Caching**: Resource servers **must** cache the JWKS response from the Auth Server. Fetching the keys on every request would create a massive performance bottleneck. Standard libraries like `jose` handle this caching automatically. * **Concurrent Requests**: If multiple API requests are made when a JWT has just expired, it can lead to a race condition where multiple new tokens are requested. Advanced client-side interceptors can solve this by queuing requests while a single new token is fetched. ``` -------------------------------- ### Update Corepack and Enable pnpm Source: https://pnpm.io/installation Updates Corepack to the latest version and then enables pnpm as the package manager for the current environment. This is necessary due to potential issues with outdated Corepack signatures. ```shell npm install --global corepack@latest ``` ```shell corepack enable pnpm ``` -------------------------------- ### Update pnpm Package Manager Source: https://pnpm.io/installation This command is used to update the pnpm package manager to its latest version. It utilizes pnpm's built-in self-update functionality to ensure you are running the most recent release. ```bash pnpm self-update ``` -------------------------------- ### Abort Controller Setup Source: https://www.docker.com/get-started Sets up an AbortController to manage and abort asynchronous operations. This snippet checks if AbortController is available and initializes it, enabling the cancellation of ongoing tasks when needed. ```javascript try{this.removeOnAbort=new AbortController}catch(e){} ``` -------------------------------- ### Agent Initialization and Feature Management Source: https://www.docker.com/get-started This snippet outlines the core initialization logic for an agent. It manages a set of desired features, determines which ones to run based on configuration and dependencies, and instantiates them. It also handles SPA navigation overrides and feature dependency checks. Dependencies include various constants like `O`, `n.K7`, and utility functions like `_.bQ` and `a.j`. ```javascript new class extends r{ constructor(e){ var t; super(), y.gm?( this.features={}, (0,_.bQ)(this.agentIdentifier,this), this.desiredFeatures=new Set(e.features||[]), this.desiredFeatures.add(O), this.runSoftNavOverSpa=[...this.desiredFeatures].some((e=>e.featureName===n.K7.softNav)), (0,a.j)(this,e,e.loaderType||"agent"), t=this, p(u.cD,(function(e,r,n=!1){ if("string"==typeof e){ if("string","number","boolean".includes(typeof r)||null===r) return g(t,e,r,u.cD,n); (0,l.R)(40,typeof r) }else (0,l.R)(39,typeof e) }),t), function(e){ p(u.Dl,(function(t){ if("string"==typeof t||null===t) return g(e,"enduser.id",t,u.Dl,!0); (0,l.R)(41,typeof t) }),e) }(this), function(e){ p(u.nb,(function(t){ if("string"==typeof t||null===t) return g(e,"application.version",t,u.nb,!1); (0,l.R)(42,typeof t) }),e) }(this), function(e){ p(u.d3,(function(){ e.ee.emit("manual-start-all") }),e) }(this), this.run() ): (0,l.R)(21) } get config(){ return{info:this.info,init:this.init,loader_config:this.loader_config,runtime:this.runtime} } get api(){ return this } run(){ try{ const e=function(e){ const t={}; return o.forEach((r=>{ t[r]=!!e[r]?.enabled })), t }(this.init), t=[...this.desiredFeatures]; t.sort(((e,t)=>n.P3[e.featureName]-n.P3[t.featureName])), t.forEach((t=>{ if(!e[t.featureName]&&t.featureName!==n.K7.pageViewEvent) return; if(this.runSoftNavOverSpa&&t.featureName===n.K7.spa) return; if(!this.runSoftNavOverSpa&&t.featureName===n.K7.softNav) return; const r=function(e){ switch(e){ case n.K7.ajax: return[n.K7.jserrors]; case n.K7.sessionTrace: return[n.K7.ajax,n.K7.pageViewEvent]; case n.K7.sessionReplay: return[n.K7.sessionTrace]; case n.K7.pageViewTiming: return[n.K7.pageViewEvent]; default: return[] }} (t.featureName).filter((e=>!(e in this.features))); r.length>0&& (0,l.R)(36,{targetFeature:t.featureName,missingDependencies:r}), this.features[t.featureName]=new t(this) })) }catch(e){ (0,l.R)(22,e); for(const e in this.features) this.features[e].abortHandler?.(); const t=(0,_.Zm)(); delete t.initializedAgents[this.agentIdentifier]?.features, delete this.sharedAggregator; return t.ee.get(this.agentIdentifier).abort(), !1 } } }({f ```