Linkarooie V4 is a modern Linktree alternative built with Astro and deployed on Cloudflare Pages. It transforms the previous static site (V3) into a full-featured web application with user authentication, profile management, analytics tracking, and more.
- User registration and authentication (email/password + 2FA)
- Profile customization (bio, avatar, banner, social links)
- Link and achievement management
- Visit analytics
- Dark/light mode
- Automatic Open Graph image generation
- Mobile-responsive design
- Frontend: Astro, TailwindCSS
- Backend: Cloudflare Pages Functions
- Database: Cloudflare D1 (SQLite)
- Storage: Cloudflare R2 (for uploaded files)
- Caching: Cloudflare KV
- Email: Resend API
- Build Tools: Bun, TypeScript, Vite
| File/Directory | Description |
|---|---|
astro.config.mjs |
Astro configuration with Cloudflare adapter settings, SSR mode, and route definitions |
wrangler.toml |
Cloudflare Workers configuration (D1, KV, R2 bindings) |
package.json |
Project dependencies and scripts |
tailwind.config.js |
TailwindCSS configuration with custom color schemes |
tsconfig.json |
TypeScript configuration |
.env.example |
Example environment variables template |
Static assets used throughout the application:
background.svg- Background pattern for landing pageastro.svg- Astro logo for attributionimages/- Contains default images, icons, and branding assets
| Component | Responsibility |
|---|---|
| Auth Components | |
LoginForm.astro |
Handles user login with username/password and optional 2FA verification |
RegisterForm.astro |
User registration form with validation |
TwoFactorForm.astro |
TOTP verification interface for 2FA |
ForgotPasswordForm.astro |
Password reset request form |
ResetPasswordForm.astro |
Form for setting a new password |
| Profile Components | |
ProfileHeader.astro |
Displays user avatar, name, and bio |
ProfileEditor.astro |
Form for editing profile information |
TagEditor.astro |
Interface for adding/removing tags |
SocialLinksEditor.astro |
Controls for managing social media links |
AvatarUploader.astro |
Interface for uploading and cropping profile images |
BannerUploader.astro |
Interface for uploading and cropping banner images |
| Link Components | |
LinkCard.astro |
Displays a user's link with title, description, and icon |
LinksList.astro |
Container that displays all user links |
LinkEditor.astro |
Form for creating and editing links |
LinkSorter.astro |
Drag-and-drop interface for reordering links |
| Achievement Components | |
AchievementCard.astro |
Displays an achievement with title, date, and description |
AchievementsList.astro |
Container for all user achievements |
AchievementEditor.astro |
Form for creating and editing achievements |
| Analytics Components | |
AnalyticsDashboard.astro |
Displays analytics overview with charts |
VisitorsChart.astro |
Line chart showing visits over time |
ReferrersList.astro |
Shows top traffic sources |
GeographyMap.astro |
Displays visitor countries on a map |
| Utility Components | |
AlertBox.astro |
Reusable alert component for success/error messages |
LoadingSpinner.astro |
Loading indicator for async operations |
ConfirmDialog.astro |
Confirmation dialog for dangerous actions |
Pagination.astro |
Paginated display for long lists |
Directory.astro |
Grid display of public profiles |
| Layout | Responsibility |
|---|---|
Layout.astro |
Base layout with common head tags, theme toggle, and footer |
DashboardLayout.astro |
Admin dashboard layout with sidebar navigation |
ProfileLayout.astro |
Public-facing profile layout for visitors |
| Page | Responsibility |
|---|---|
index.astro |
Landing page with featured profiles and app information |
login.astro |
User login page |
register.astro |
New user registration page |
verify-email.astro |
Email verification handler |
forgot-password.astro |
Password reset request page |
reset-password.astro |
Password reset confirmation page |
[username].astro |
Dynamic route for public user profiles |
/dashboard/index.astro |
User dashboard home with stats overview |
/dashboard/profile.astro |
Profile editing interface |
/dashboard/links.astro |
Link management interface |
/dashboard/achievements.astro |
Achievements management interface |
/dashboard/analytics.astro |
Analytics dashboard |
/dashboard/settings.astro |
Account settings (privacy, security, etc.) |
| Service | Responsibility |
|---|---|
auth.ts |
Authentication logic (login, register, JWT, 2FA) |
profile.ts |
Profile data management |
links.ts |
Link creation, updating, ordering |
achievements.ts |
Achievement management |
analytics.ts |
Visit tracking and statistics |
email.ts |
Email sending via Resend API |
storage.ts |
File upload handling with R2 |
og-image.ts |
Open Graph image generation |
| File | Responsibility |
|---|---|
schema.ts |
TypeScript definitions matching database schema |
/migrations/init.sql |
Initial database schema creation |
/migrations/updates/ |
Incremental schema updates |
| File | Responsibility |
|---|---|
index.ts |
Core TypeScript interfaces for the application |
env.d.ts |
Environment type definitions |
api.ts |
API request/response type definitions |
| Utility | Responsibility |
|---|---|
validation.ts |
Input validation helpers |
formatters.ts |
Date, number, and string formatting utilities |
security.ts |
Security-related helpers |
image-processing.ts |
Image manipulation utilities |
| Function | Responsibility |
|---|---|
[[path]].ts |
Catch-all middleware for auth verification |
/api/auth/login.ts |
Handle login requests |
/api/auth/register.ts |
Process new user registrations |
/api/auth/logout.ts |
Handle logout |
/api/auth/verify-email.ts |
Verify user email addresses |
/api/auth/reset-password.ts |
Handle password reset flow |
/api/auth/totp-setup.ts |
Configure 2FA for users |
/api/profiles/[username].ts |
Get public profile data |
/api/profiles/create.ts |
Create new profile |
/api/profiles/update.ts |
Update profile information |
/api/links/create.ts |
Add new link |
/api/links/update.ts |
Update existing link |
/api/links/delete.ts |
Remove link |
/api/links/reorder.ts |
Change link ordering |
/api/achievements/create.ts |
Add new achievement |
/api/achievements/update.ts |
Update existing achievement |
/api/achievements/delete.ts |
Remove achievement |
/api/analytics/track.ts |
Record profile visits |
/api/analytics/[username].ts |
Get analytics for a profile |
/api/og-image/generate.ts |
Generate Open Graph images |
| Script | Responsibility |
|---|---|
init-project.ts |
Set up initial project configuration |
seed-database.ts |
Populate database with sample data for development |
backup-database.ts |
D1 database backup utility |
generate-og-image.ts |
Utility for generating Open Graph images |
The authentication system uses JWT tokens stored in HTTP-only cookies for secure sessions, with email verification and optional TOTP-based two-factor authentication.
Key Files:
src/services/auth.ts- Core authentication logicfunctions/api/auth/*- Auth API endpointssrc/components/auth/*- Auth UI components
Flow:
- User registers with email/password
- Verification email sent via Resend API
- User verifies email by clicking link
- User logs in with credentials
- JWT token stored in HTTP-only cookie
- Optional 2FA verification step
- User session maintained until logout or expiration
The profile management system handles all aspects of a user's public profile.
Key Files:
src/services/profile.ts- Profile data operationsfunctions/api/profiles/*- Profile API endpointssrc/pages/dashboard/profile.astro- Profile editing interfacesrc/components/profile/*- Profile UI components
Features:
- Basic profile info (name, bio, description)
- Avatar and banner image upload and cropping
- Tags and categories
- Social media links
- Privacy settings
- SEO settings
The links system allows users to create, edit, and organize their collection of links.
Key Files:
src/services/links.ts- Link operationsfunctions/api/links/*- Link API endpointssrc/pages/dashboard/links.astro- Link management interfacesrc/components/LinkEditor.astro- Link editing component
Features:
- Add, edit, and delete links
- Customize link title, URL, description, and icon
- Drag-and-drop reordering
- Hide/show specific links
- Track click statistics
The achievements system showcases user accomplishments, certifications, and milestones.
Key Files:
src/services/achievements.ts- Achievement operationsfunctions/api/achievements/*- Achievement API endpointssrc/pages/dashboard/achievements.astro- Achievement management interfacesrc/components/AchievementEditor.astro- Achievement editing component
Features:
- Add, edit, and delete achievements
- Customize title, date, description, and icon
- Attach verification links
- Format dates flexibly
- Hide/show specific achievements
The analytics system tracks profile visits and provides insights to users.
Key Files:
src/services/analytics.ts- Analytics operationsfunctions/api/analytics/*- Analytics API endpointssrc/pages/dashboard/analytics.astro- Analytics dashboardsrc/components/analytics/*- Analytics UI components
Features:
- Profile visit tracking
- Unique visitor counts
- Referrer analysis
- Geographic distribution of visitors
- Time-based trends
- Optional public analytics page
Automatic generation of customized Open Graph images for sharing on social media.
Key Files:
src/services/og-image.ts- Image generation logicfunctions/api/og-image/generate.ts- Image generation APIsrc/components/profile/OgImagePreview.astro- Preview component
Features:
- Real-time OG image generation
- Customized with user profile data
- Multiple theme options (light/dark)
- Automatic updating when profile changes
- Cache with R2 storage for performance
Implementation:
- Uses satori to render React components as SVG
- Converts SVG to PNG using resvg/Sharp
- Stores generated images in R2 bucket
- Automatically regenerates when profile is updated
- Includes profile avatar, name, bio, and tags
The D1 database uses the following tables:
Stores core user account information:
id- Primary keyusername- Unique usernameemail- User's email addresspassword- Hashed passwordname- User's display namedescription- Short profile descriptionbio- Longer biographyavatar_url- Profile image URLbanner_url- Profile banner URLog_image_url- Open Graph image URLog_title- SEO titleog_description- SEO descriptionis_email_verified- Email verification statusis_public- Profile visibility toggleshow_in_directory- Directory inclusion toggletotp_secret- 2FA secret (if enabled)totp_enabled- 2FA status flagis_admin- Admin privileges flagcreated_at- Account creation timestampupdated_at- Last update timestamp
Stores available tags:
id- Primary keyname- Tag name
Junction table linking users to tags:
user_id- References users.idtag_id- References tags.id
Stores user's social media profiles:
id- Primary keyuser_id- References users.idplatform- Social platform identifierurl- Profile URL
Stores user's shared links:
id- Primary keyuser_id- References users.idlink_id- Unique identifier for the linktitle- Link titledescription- Link descriptionurl- Link URLicon- Icon identifieris_hidden- Visibility togglesort_order- Position in listcreated_at- Creation timestampupdated_at- Last update timestamp
Stores user's achievements:
id- Primary keyuser_id- References users.idachievement_id- Unique identifiertitle- Achievement titledescription- Achievement descriptiondate- Achievement dateurl- Verification linkicon- Icon identifiershow_full_date- Date format toggleis_hidden- Visibility togglesort_order- Position in listcreated_at- Creation timestampupdated_at- Last update timestamp
Stores profile visit data:
id- Primary keyuser_id- References users.idvisitor_ip- Visitor's IP address (hashed)user_agent- Browser user agentreferrer- Traffic sourcecountry- Visitor countrycity- Visitor cityvisited_at- Visit timestamp
Stores password reset tokens:
id- Primary keyuser_id- References users.idtoken- Unique reset tokenexpires_at- Token expiration timestampcreated_at- Token creation timestamp
Stores email verification tokens:
id- Primary keyuser_id- References users.idtoken- Unique verification tokenexpires_at- Token expiration timestampcreated_at- Token creation timestamp
| Endpoint | Method | Description |
|---|---|---|
/api/auth/register |
POST | Create new user account |
/api/auth/login |
POST | Authenticate user |
/api/auth/logout |
POST | End user session |
/api/auth/verify-email |
GET | Verify email address |
/api/auth/reset-password |
POST | Request password reset |
/api/auth/reset-password |
PUT | Complete password reset |
/api/auth/totp-setup |
POST | Initialize 2FA setup |
/api/auth/totp-verify |
POST | Verify and enable 2FA |
/api/auth/totp-disable |
POST | Disable 2FA |
| Endpoint | Method | Description |
|---|---|---|
/api/profiles/:username |
GET | Get public profile data |
/api/profiles/me |
GET | Get current user's profile |
/api/profiles/update |
PUT | Update profile information |
/api/profiles/social-links |
PUT | Update social media links |
/api/profiles/tags |
PUT | Update profile tags |
/api/profiles/avatar |
POST | Upload avatar image |
/api/profiles/banner |
POST | Upload banner image |
| Endpoint | Method | Description |
|---|---|---|
/api/links |
GET | Get user's links |
/api/links/create |
POST | Create new link |
/api/links/:linkId |
PUT | Update existing link |
/api/links/:linkId |
DELETE | Delete link |
/api/links/reorder |
PUT | Change link order |
| Endpoint | Method | Description |
|---|---|---|
/api/achievements |
GET | Get user's achievements |
/api/achievements/create |
POST | Create new achievement |
/api/achievements/:achievementId |
PUT | Update achievement |
/api/achievements/:achievementId |
DELETE | Delete achievement |
/api/achievements/reorder |
PUT | Change achievement order |
| Endpoint | Method | Description |
|---|---|---|
/api/analytics/:username |
GET | Get profile analytics |
/api/analytics/track |
POST | Record profile visit |
/api/analytics/clear |
DELETE | Clear analytics data |
| Endpoint | Method | Description |
|---|---|---|
/api/og-image/generate |
POST | Generate OG image |
/api/og-image/:username |
GET | Get user's OG image |
The Open Graph image generation system creates custom images for social media sharing.
-
Image Generation Service (
src/services/og-image.ts)- Uses satori to render React components as SVG
- Converts SVG to PNG or JPEG using resvg/sharp
- Handles different themes and layouts
- Caches generated images in R2 storage
-
Generation Process
- User profile data is fetched from the database
- Data is passed to a React template component
- Component is rendered to SVG using satori
- SVG is converted to PNG using resvg/sharp
- Image is stored in R2 bucket with appropriate cache headers
- URL is saved to user's profile
-
Trigger Points
- Initial profile creation
- Profile updates (name, bio, avatar, etc.)
- Theme changes
- Manual regeneration from settings
-
Templates
src/components/og-templates/ProfileTemplate.tsx- Standard profile OG imagesrc/components/og-templates/AchievementTemplate.tsx- Achievement showcase templatesrc/components/og-templates/LinkTemplate.tsx- Link-specific template
-
Preview Component
- Live preview of OG image in dashboard
- Allows testing different layouts/themes before saving
-
Build Process
- Astro builds optimized frontend assets
- TypeScript compilation for server functions
- Assets bundled for deployment
-
Database Setup
- D1 database created in Cloudflare dashboard
- Initial schema migration run via wrangler CLI
- Binding configured in wrangler.toml
-
Environment Variables
- JWT_SECRET - For secure token signing
- RESEND_API_KEY - For transactional emails
- Environment-specific variables (staging vs production)
-
Custom Domain Configuration
- DNS records set up in Cloudflare
- SSL certificate automatically provisioned
-
Continuous Deployment
- GitHub integration with Cloudflare Pages
- Automatic deployments on push to main branch
- Preview deployments for pull requests
-
Authentication
- Passwords hashed with bcrypt
- HTTP-only cookies for JWT
- Optional TOTP 2FA
- CSRF protection
- Rate limiting on auth endpoints
-
Input Validation
- All user input validated with Zod schemas
- Protection against XSS and injection
-
API Security
- Authentication middleware for protected routes
- Input sanitization
- Resource authorization checks
-
Privacy
- IP addresses hashed for analytics
- Profile privacy controls
- Data minimization principles
-
Monitoring & Logging
- Error tracking
- Security event logging
- Suspicious activity detection