2
2
3
3
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
4
5
+ DONT HALLUCIATE THINGS. IF YOU DONT KNOW LOOK AT THE CODE OR ASK FOR DOCS
6
+
5
7
## Project Overview
6
8
7
9
Gitea Mirror is a web application that automatically mirrors repositories from GitHub to self-hosted Gitea instances. It uses Astro for SSR, React for UI, SQLite for data storage, and Bun as the JavaScript runtime.
@@ -40,7 +42,7 @@ bun run start # Start production server
40
42
- ** Frontend** : Astro (SSR) + React + Tailwind CSS v4 + Shadcn UI
41
43
- ** Backend** : Bun runtime + SQLite + Drizzle ORM
42
44
- ** APIs** : GitHub (Octokit) and Gitea APIs
43
- - ** Auth** : JWT tokens with bcryptjs password hashing
45
+ - ** Auth** : Better Auth with email/ password, SSO, and OIDC provider support
44
46
45
47
### Project Structure
46
48
- ` /src/pages/api/ ` - API endpoints (Astro API routes)
@@ -68,22 +70,34 @@ export async function POST({ request }: APIContext) {
68
70
69
71
3 . ** Real-time Updates** : Server-Sent Events (SSE) endpoint at ` /api/events ` for live dashboard updates
70
72
71
- 4 . ** Authentication Flow** :
73
+ 4 . ** Authentication System** :
74
+ - Built on Better Auth library
75
+ - Three authentication methods:
76
+ - Email & Password (traditional auth)
77
+ - SSO (authenticate via external OIDC providers)
78
+ - OIDC Provider (act as OIDC provider for other apps)
79
+ - Session-based authentication with secure cookies
72
80
- First user signup creates admin account
73
- - JWT tokens stored in cookies
74
- - Protected routes check auth via ` getUserFromCookie() `
81
+ - Protected routes use Better Auth session validation
75
82
76
83
5 . ** Mirror Process** :
77
84
- Discovers repos from GitHub (user/org)
78
85
- Creates/updates mirror in Gitea
79
86
- Tracks status in database
80
87
- Supports scheduled automatic mirroring
81
88
82
- 6 . ** Mirror Strategies** : Three ways to organize repositories in Gitea:
89
+ 6 . ** Mirror Strategies** : Four ways to organize repositories in Gitea:
83
90
- ** preserve** : Maintains GitHub structure (default)
91
+ - Organization repos → Same organization name in Gitea
92
+ - Personal repos → Under your Gitea username
84
93
- ** single-org** : All repos go to one organization
94
+ - All repos → Single configured organization
85
95
- ** flat-user** : All repos go under user account
86
- - Starred repos always go to separate organization (starredReposOrg)
96
+ - All repos → Under your Gitea username
97
+ - ** mixed** : Hybrid approach
98
+ - Organization repos → Preserve structure
99
+ - Personal repos → Single configured organization
100
+ - Starred repos always go to separate organization (starredReposOrg, default: "starred")
87
101
- Routing logic in ` getGiteaRepoOwner() ` function
88
102
89
103
### Database Schema (SQLite)
@@ -102,11 +116,18 @@ export async function POST({ request }: APIContext) {
102
116
103
117
### Development Tips
104
118
- Environment variables in ` .env ` (copy from ` .env.example ` )
105
- - JWT_SECRET auto-generated if not provided
119
+ - BETTER_AUTH_SECRET required for session signing
106
120
- Database auto-initializes on first run
107
121
- Use ` bun run dev:clean ` for fresh database start
108
122
- Tailwind CSS v4 configured with Vite plugin
109
123
124
+ ### Authentication Setup
125
+ - ** Better Auth** handles all authentication
126
+ - Configuration in ` /src/lib/auth.ts ` (server) and ` /src/lib/auth-client.ts ` (client)
127
+ - Auth endpoints available at ` /api/auth/* `
128
+ - SSO providers configured through the web UI
129
+ - OIDC provider functionality for external applications
130
+
110
131
### Common Tasks
111
132
112
133
** Adding a new API endpoint:**
@@ -125,6 +146,73 @@ export async function POST({ request }: APIContext) {
125
146
2 . Run ` bun run init-db ` to recreate database
126
147
3 . Update related queries in ` /src/lib/db/queries/ `
127
148
149
+ ## Configuration Options
150
+
151
+ ### GitHub Configuration (UI Fields)
152
+
153
+ #### Basic Settings (` githubConfig ` )
154
+ - ** username** : GitHub username
155
+ - ** token** : GitHub personal access token (requires repo and admin: org scopes)
156
+ - ** privateRepositories** : Include private repositories
157
+ - ** mirrorStarred** : Mirror starred repositories
158
+
159
+ ### Gitea Configuration (UI Fields)
160
+ - ** url** : Gitea instance URL
161
+ - ** username** : Gitea username
162
+ - ** token** : Gitea access token
163
+ - ** organization** : Destination organization (for single-org/mixed strategies)
164
+ - ** starredReposOrg** : Organization for starred repositories (default: "starred")
165
+ - ** visibility** : Organization visibility - "public", "private", "limited"
166
+ - ** mirrorStrategy** : Repository organization strategy (set via UI)
167
+ - ** preserveOrgStructure** : Automatically set based on mirrorStrategy
168
+
169
+ ### Schedule Configuration (` scheduleConfig ` )
170
+ - ** enabled** : Enable automatic mirroring (default: false)
171
+ - ** interval** : Cron expression or seconds (default: "0 2 * * * " - 2 AM daily)
172
+ - ** concurrent** : Allow concurrent mirror operations (default: false)
173
+ - ** batchSize** : Number of repos to process in parallel (default: 10)
174
+
175
+ ### Database Cleanup Configuration (` cleanupConfig ` )
176
+ - ** enabled** : Enable automatic cleanup (default: false)
177
+ - ** retentionDays** : Days to keep events (stored as seconds internally)
178
+
179
+ ### Mirror Options (UI Fields)
180
+ - ** mirrorReleases** : Mirror GitHub releases to Gitea
181
+ - ** mirrorMetadata** : Enable metadata mirroring (master toggle)
182
+ - ** metadataComponents** (only available when mirrorMetadata is enabled):
183
+ - ** issues** : Mirror issues
184
+ - ** pullRequests** : Mirror pull requests
185
+ - ** labels** : Mirror labels
186
+ - ** milestones** : Mirror milestones
187
+ - ** wiki** : Mirror wiki content
188
+
189
+ ### Advanced Options (UI Fields)
190
+ - ** skipForks** : Skip forked repositories (default: false)
191
+ - ** skipStarredIssues** : Skip issues for starred repositories (default: false) - enables "Lightweight mode" for starred repos
192
+
193
+ ### Authentication Configuration
194
+
195
+ #### SSO Provider Configuration
196
+ - ** issuerUrl** : OIDC issuer URL (e.g., https://accounts.google.com )
197
+ - ** domain** : Email domain for this provider
198
+ - ** providerId** : Unique identifier for the provider
199
+ - ** clientId** : OAuth client ID from provider
200
+ - ** clientSecret** : OAuth client secret from provider
201
+ - ** authorizationEndpoint** : OAuth authorization URL (auto-discovered if supported)
202
+ - ** tokenEndpoint** : OAuth token exchange URL (auto-discovered if supported)
203
+ - ** jwksEndpoint** : JSON Web Key Set URL (optional, auto-discovered)
204
+ - ** userInfoEndpoint** : User information endpoint (optional, auto-discovered)
205
+
206
+ #### OIDC Provider Settings (for external apps)
207
+ - ** allowedRedirectUris** : Comma-separated list of allowed redirect URIs
208
+ - ** clientId** : Generated client ID for the application
209
+ - ** clientSecret** : Generated client secret for the application
210
+ - ** scopes** : Available scopes (openid, profile, email)
211
+
212
+ #### Environment Variables
213
+ - ** BETTER_AUTH_SECRET** : Secret key for signing sessions (required)
214
+ - ** BETTER_AUTH_URL** : Base URL for authentication (default: http://localhost:4321 )
215
+
128
216
## Security Guidelines
129
217
130
218
- ** Confidentiality Guidelines** :
0 commit comments