+ )
+}
diff --git a/src/app/about/page.tsx b/src/app/about/page.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..fc0363b76c71c9fb59686ef8417520503b0e5e68
--- /dev/null
+++ b/src/app/about/page.tsx
@@ -0,0 +1,244 @@
+import Link from "next/link"
+import { Button } from "@/components/ui/button"
+import {
+ Sparkles,
+ Zap,
+ Globe,
+ Shield,
+ Users,
+ Heart,
+ ArrowRight,
+ Github,
+ Twitter,
+ Mail
+} from "lucide-react"
+import { getPlatformStats } from "@/lib/data"
+
+export default async function AboutPage() {
+ const platformStats = await getPlatformStats()
+
+ const stats = [
+ { value: `${platformStats.totalImages}+`, label: "Images Generated" },
+ { value: `${platformStats.totalArtists}+`, label: "Active Artists" },
+ { value: "100", label: "Free Daily Credits" },
+ { value: "5", label: "Credits per Image" },
+ ]
+
+ const features = [
+ {
+ icon: Zap,
+ title: "Lightning Fast Generation",
+ description: "Powered by our AI edge network for instant image generation anywhere in the world."
+ },
+ {
+ icon: Globe,
+ title: "Global Edge Network",
+ description: "Our infrastructure spans 200+ cities worldwide, ensuring low latency no matter where you are."
+ },
+ {
+ icon: Shield,
+ title: "Privacy First",
+ description: "Your prompts and images are yours. We don't sell your data or use it for training without consent."
+ },
+ {
+ icon: Users,
+ title: "Community Driven",
+ description: "Share your creations with a vibrant community of digital artists and AI enthusiasts."
+ }
+ ]
+
+ return (
+
+ {/* Clean Background */}
+
+
+
+
+ {/* Hero Section */}
+
+
+
+
+
+ Our Story
+
+
+
+ Democratizing AI Art
+
+
+ For Everyone
+
+
+
+
+ Imyra was built with a simple mission: make AI-powered image generation accessible,
+ fast, and free for creators worldwide. No subscriptions, no hidden fees—just pure creativity.
+
+
+
+
+
+ {/* Stats Section */}
+
+
+
+ {stats.map((stat, index) => (
+
+
+ {stat.value}
+
+
+ {stat.label}
+
+
+ ))}
+
+
+
+
+ {/* Mission Section */}
+
+
+
+
+
+
+ Our Mission
+
+
+
+ Art Should Be Accessible
+
+
+
+
+ We believe everyone should have the power to create stunning visuals,
+ regardless of their artistic background or budget. That's why we offer
+ 100 free credits every single day.
+
+
+ Our platform leverages the best open-source AI models including Flux, Stable Diffusion,
+ and more—running on distributed GPU infrastructure for blazing-fast
+ generation times.
+
+
+ At just 5 credits per image,
+ you can generate up to 20 images daily
+ completely free. No strings attached.
+
+
+
+
+ {/* Feature Grid */}
+
+ {features.map((feature, index) => (
+
+
+
+
+
{feature.title}
+
{feature.description}
+
+ ))}
+
+
+
+
+
+ {/* Technology Section */}
+
+
+
+
+ Powered by Cutting-Edge Tech
+
+
+
+
+
🌐
+
Open Source
+
Built on community-driven OSS models
+
+
+
🎨
+
Flux & SD Models
+
State-of-the-art AI image generation
+
+
+
🚀
+
Next.js 15
+
Modern React framework for speed
+
+
+
+
+
+
+ {/* CTA Section */}
+
+
+
+
+
+
+ Ready to Start Creating?
+
+
+ Join our community of artists and start generating stunning AI art today.
+ It's completely free to get started.
+
+
+
+
+
+
+
+
+
+
+ {/* Footer */}
+
+
+ )
+}
diff --git a/src/app/actions/auth.ts b/src/app/actions/auth.ts
new file mode 100644
index 0000000000000000000000000000000000000000..15f412a71f846c36db67fe407ca1efaed3b9c3ed
--- /dev/null
+++ b/src/app/actions/auth.ts
@@ -0,0 +1,51 @@
+"use server"
+
+import { prisma } from "@/lib/prisma"
+import bcrypt from "bcryptjs"
+import { z } from "zod"
+
+const signupSchema = z.object({
+ name: z.string().min(2, "Name must be at least 2 characters"),
+ username: z.string().min(3, "Username must be at least 3 characters"),
+ email: z.string().email("Invalid email address"),
+ password: z.string().min(6, "Password must be at least 6 characters"),
+})
+
+export async function signup(data: z.infer) {
+ const result = signupSchema.safeParse(data)
+
+ if (!result.success) {
+ return { error: "Invalid input" }
+ }
+
+ const { name, username, email, password } = result.data
+
+ try {
+ const existingUser = await prisma.user.findFirst({
+ where: {
+ OR: [{ email }, { username }],
+ },
+ })
+
+ if (existingUser) {
+ return { error: "User with this email or username already exists" }
+ }
+
+ const hashedPassword = await bcrypt.hash(password, 10)
+
+ await prisma.user.create({
+ data: {
+ name,
+ username,
+ email,
+ password: hashedPassword,
+ credits: 50,
+ },
+ })
+
+ return { success: true }
+ } catch (error) {
+ console.error("Signup error:", error)
+ return { error: "Something went wrong. Please try again." }
+ }
+}
diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts
new file mode 100644
index 0000000000000000000000000000000000000000..42e2953e9453f1f5a64f71b9a6db8bdd021bf574
--- /dev/null
+++ b/src/app/api/auth/[...nextauth]/route.ts
@@ -0,0 +1,2 @@
+import { handlers } from "@/auth"
+export const { GET, POST } = handlers
diff --git a/src/app/api/gallery/route.ts b/src/app/api/gallery/route.ts
new file mode 100644
index 0000000000000000000000000000000000000000..afe7c31f277252b552416bf46b665b1cc87ac59b
--- /dev/null
+++ b/src/app/api/gallery/route.ts
@@ -0,0 +1,44 @@
+import { prisma } from "@/lib/prisma"
+import { NextResponse } from "next/server"
+
+export async function GET(request: Request) {
+ try {
+ const { searchParams } = new URL(request.url)
+ const cursor = searchParams.get("cursor")
+ const limit = parseInt(searchParams.get("limit") || "20")
+
+ const generations = await prisma.generation.findMany({
+ where: { isPublic: true },
+ orderBy: [{ createdAt: "desc" }, { id: "desc" }],
+ take: limit + 1, // Fetch one extra to check for next page
+ cursor: cursor ? { id: cursor } : undefined,
+ skip: cursor ? 1 : 0, // Skip the cursor itself if present
+ include: {
+ user: {
+ select: {
+ name: true,
+ username: true,
+ image: true,
+ },
+ },
+ },
+ })
+
+ let nextCursor: string | null = null
+ if (generations.length > limit) {
+ const nextItem = generations.pop() // Remove the extra item
+ nextCursor = nextItem?.id || null
+ }
+
+ return NextResponse.json({
+ data: generations,
+ nextCursor,
+ })
+ } catch (error) {
+ console.error("Gallery fetch error:", error)
+ return NextResponse.json(
+ { error: "Failed to fetch gallery images" },
+ { status: 500 }
+ )
+ }
+}
diff --git a/src/app/api/generate/route.ts b/src/app/api/generate/route.ts
new file mode 100644
index 0000000000000000000000000000000000000000..a227dffbb397cc20feaf27bdbb6bba487f338b23
--- /dev/null
+++ b/src/app/api/generate/route.ts
@@ -0,0 +1,118 @@
+import { auth } from "@/auth"
+import { checkAndResetDailyCredits, deductCredits } from "@/lib/credits"
+import { prisma } from "@/lib/prisma"
+import { NextRequest, NextResponse } from "next/server"
+
+export const DEFAULT_NEGATIVE_PROMPT = "blurry, low quality, bad anatomy, bad hands, distorted, ugly, pixelated, watermark, text, signature, grains, haze"
+
+export async function POST(req: NextRequest) {
+ try {
+ const session = await auth()
+ if (!session || !session.user || !session.user.id) {
+ return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
+ }
+
+ const { prompt, model = "flux-dev", width = 1024, height = 1024 } = await req.json()
+
+ if (!prompt) {
+ return NextResponse.json({ error: "Prompt is required" }, { status: 400 })
+ }
+
+ // 1. Check Credits
+ const credits = await checkAndResetDailyCredits(session.user.id)
+ // 2. Load Balancing Configuration
+ // Parse workers from Environment Variable (comma separated) or default to known instances
+ const envWorkers = process.env.CLOUDFLARE_WORKER_URL
+ ? process.env.CLOUDFLARE_WORKER_URL.split(",").map(url => url.trim())
+ : []
+
+ // Add hardcoded fallbacks/extras if they aren't in the env
+ // The user might put the primary in env and want to add others here or in env
+ const extraWorkers = [
+ "https://bitter-forest-7e87.bob17040246.workers.dev/"
+ ]
+
+ // Combine and Deduplicate
+ const ALL_WORKERS = Array.from(new Set([...envWorkers, ...extraWorkers])).filter(url => url.length > 0)
+
+ if (ALL_WORKERS.length === 0) {
+ return NextResponse.json({ error: "Server configuration error: No worker URLs found" }, { status: 500 })
+ }
+
+ // Round-robin selection
+ if (typeof (global as any).requestCounter === 'undefined') {
+ (global as any).requestCounter = 0
+ }
+
+ const counter = (global as any).requestCounter++
+ const selectedWorkerUrl = ALL_WORKERS[counter % ALL_WORKERS.length]
+
+ console.log(`[LoadBalancer] Request #${counter} -> Using Worker ${counter % ALL_WORKERS.length + 1}/${ALL_WORKERS.length}: ${selectedWorkerUrl}`)
+
+ // Clean up URL construction
+ const baseUrl = selectedWorkerUrl.endsWith("/") ? selectedWorkerUrl.slice(0, -1) : selectedWorkerUrl
+ // If model includes a slash, remove it for consistency
+ const cleanModel = model.startsWith("/") ? model.slice(1) : model
+ const url = `${baseUrl}/${cleanModel}`
+
+ // Prepare payload with Negative Prompt
+ const payload = {
+ prompt,
+ negative_prompt: DEFAULT_NEGATIVE_PROMPT, // Pass explicit negative prompt
+ width,
+ height,
+ steps: 30
+ }
+
+ // For Flux models that might ignore negative_prompt, we can optionally append it to the prompt
+ // IF the model is known to not support it. But standard practice is to send it separately first.
+
+ const response = await fetch(url, {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify(payload),
+ })
+ // }
+
+ if (!response.ok) {
+ const errorText = await response.text()
+ console.error("AI Generation failed:", errorText)
+ return NextResponse.json({ error: "Image generation failed upstream" }, { status: 500 })
+ }
+
+ const result = await response.json()
+
+ if (!result.success || !result.url) {
+ return NextResponse.json({ error: "Image generation returned no URL" }, { status: 500 })
+ }
+
+ // 3. Deduct Credits (Success confirmed) - 5 credits per generation
+ await deductCredits(session.user.id, 5)
+
+ // 4. Save to Database
+ const generation = await prisma.generation.create({
+ data: {
+ prompt,
+ model,
+ width,
+ height,
+ imageUrl: result.url,
+ userId: session.user.id,
+ isPublic: true, // Default to public as per requirement "gallery... new non auth users will be able to see"
+ }
+ })
+
+ return NextResponse.json({
+ success: true,
+ url: generation.imageUrl,
+ width: generation.width,
+ height: generation.height,
+ prompt: generation.prompt,
+ model: generation.model
+ })
+
+ } catch (error) {
+ console.error("Generate API error:", error)
+ return NextResponse.json({ error: "Internal Server Error" }, { status: 500 })
+ }
+}
diff --git a/src/app/api/generation/[id]/route.ts b/src/app/api/generation/[id]/route.ts
new file mode 100644
index 0000000000000000000000000000000000000000..588679f1147548e1986a67986b8a0949195a88a9
--- /dev/null
+++ b/src/app/api/generation/[id]/route.ts
@@ -0,0 +1,39 @@
+import { auth } from "@/auth"
+import { prisma } from "@/lib/prisma"
+import { NextResponse } from "next/server"
+
+export async function DELETE(
+ req: Request,
+ { params }: { params: Promise<{ id: string }> }
+) {
+ try {
+ const session = await auth()
+ if (!session?.user?.id) {
+ return new NextResponse("Unauthorized", { status: 401 })
+ }
+
+ const { id } = await params
+
+ // Verify ownership
+ const generation = await prisma.generation.findUnique({
+ where: { id },
+ })
+
+ if (!generation) {
+ return new NextResponse("Not Found", { status: 404 })
+ }
+
+ if (generation.userId !== session.user.id) {
+ return new NextResponse("Forbidden", { status: 403 })
+ }
+
+ await prisma.generation.delete({
+ where: { id },
+ })
+
+ return new NextResponse(null, { status: 204 })
+ } catch (error) {
+ console.error("[GENERATION_DELETE]", error)
+ return new NextResponse("Internal Error", { status: 500 })
+ }
+}
diff --git a/src/app/api/image/[id]/[filename]/route.ts b/src/app/api/image/[id]/[filename]/route.ts
new file mode 100644
index 0000000000000000000000000000000000000000..60582cf94620ff5441bed52d205432c9ec154741
--- /dev/null
+++ b/src/app/api/image/[id]/[filename]/route.ts
@@ -0,0 +1,42 @@
+import { NextRequest, NextResponse } from "next/server"
+import { prisma } from "@/lib/prisma"
+
+export async function GET(
+ req: NextRequest,
+ { params }: { params: Promise<{ id: string }> }
+) {
+ const { id } = await params
+
+ if (!id) {
+ return NextResponse.json({ error: "Image ID is required" }, { status: 400 })
+ }
+
+ try {
+ const generation = await prisma.generation.findUnique({
+ where: { id },
+ select: { imageUrl: true }
+ })
+
+ if (!generation || !generation.imageUrl) {
+ return NextResponse.json({ error: "Image not found" }, { status: 404 })
+ }
+
+ const response = await fetch(generation.imageUrl)
+ if (!response.ok) {
+ return NextResponse.json({ error: "Failed to fetch image" }, { status: response.status })
+ }
+
+ const contentType = response.headers.get("Content-Type") || "image/jpeg"
+ const buffer = await response.arrayBuffer()
+
+ return new NextResponse(buffer, {
+ headers: {
+ "Content-Type": contentType,
+ "Cache-Control": "public, max-age=31536000, immutable",
+ },
+ })
+ } catch (error) {
+ console.error("Image proxy error:", error)
+ return NextResponse.json({ error: "Internal Server Error" }, { status: 500 })
+ }
+}
diff --git a/src/app/api/user/route.ts b/src/app/api/user/route.ts
new file mode 100644
index 0000000000000000000000000000000000000000..7ead4f516497fe3d4e55f8bbd2779f8db40d67a6
--- /dev/null
+++ b/src/app/api/user/route.ts
@@ -0,0 +1,63 @@
+import { auth } from "@/auth"
+import { prisma } from "@/lib/prisma"
+import { NextResponse } from "next/server"
+import { z } from "zod"
+
+export async function PUT(req: Request) {
+ try {
+ const session = await auth()
+ if (!session?.user?.id) {
+ return new NextResponse("Unauthorized", { status: 401 })
+ }
+
+ const body = await req.json()
+ const { name, username } = z
+ .object({
+ name: z.string().min(2).max(50),
+ username: z.string().min(3).max(20).regex(/^[a-zA-Z0-9_]+$/, "Username must be alphanumeric"),
+ })
+ .parse(body)
+
+ // Check if username is taken (if changed)
+ if (username !== session.user.username) {
+ const existingUser = await prisma.user.findUnique({
+ where: { username },
+ })
+ if (existingUser) {
+ return new NextResponse("Username already taken", { status: 409 })
+ }
+ }
+
+ const updatedUser = await prisma.user.update({
+ where: { id: session.user.id },
+ data: { name, username },
+ })
+
+ return NextResponse.json(updatedUser)
+ } catch (error) {
+ if (error instanceof z.ZodError) {
+ return new NextResponse("Invalid data", { status: 422 })
+ }
+ console.error("[USER_UPDATE]", error)
+ return new NextResponse("Internal Error", { status: 500 })
+ }
+}
+
+export async function DELETE(req: Request) {
+ try {
+ const session = await auth()
+ if (!session?.user?.id) {
+ return new NextResponse("Unauthorized", { status: 401 })
+ }
+
+ // Delete user (Cascade will handle Generations, Accounts, Sessions)
+ await prisma.user.delete({
+ where: { id: session.user.id },
+ })
+
+ return new NextResponse(null, { status: 204 })
+ } catch (error) {
+ console.error("[USER_DELETE]", error)
+ return new NextResponse("Internal Error", { status: 500 })
+ }
+}
diff --git a/src/app/artwork/[id]/page.tsx b/src/app/artwork/[id]/page.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..c4025783c7ae1c535d21de139d87175635f6c649
--- /dev/null
+++ b/src/app/artwork/[id]/page.tsx
@@ -0,0 +1,181 @@
+import { prisma } from "@/lib/prisma"
+import { notFound } from "next/navigation"
+import Image from "next/image"
+import { Button } from "@/components/ui/button"
+import { ShareMenu } from "@/components/share-menu"
+import { Download, Info, ArrowLeft, Paintbrush, Calendar, User } from "lucide-react"
+import Link from "next/link"
+import { Metadata } from "next"
+
+// Force dynamic rendering to ensure fresh data and valid auth checks if needed
+// though this page is public
+export const dynamic = "force-dynamic"
+
+interface ArtworkPageProps {
+ params: Promise<{ id: string }>
+}
+
+export async function generateMetadata({ params }: ArtworkPageProps): Promise {
+ const resolvedParams = await params
+ const generation = await prisma.generation.findUnique({
+ where: { id: resolvedParams.id },
+ select: { prompt: true, id: true, imageUrl: true, user: { select: { name: true } } }
+ })
+
+ if (!generation) {
+ return {
+ title: "Artwork Not Found | Imyra",
+ }
+ }
+
+ return {
+ title: `${generation.prompt} by ${generation.user.name || "Anonymous"} | Imyra`,
+ description: `View this AI-generated artwork: "${generation.prompt}" created using Imyra.`,
+ openGraph: {
+ title: `Imyra: ${generation.prompt}`,
+ description: "Check out this amazing AI artwork generated on Imyra.",
+ images: [generation.imageUrl], // Use the direct URL for social preview
+ },
+ twitter: {
+ card: "summary_large_image",
+ title: `Imyra: ${generation.prompt}`,
+ description: "Check out this amazing AI artwork generated on Imyra.",
+ images: [generation.imageUrl],
+ }
+ }
+}
+
+export default async function ArtworkPage({ params }: ArtworkPageProps) {
+ const resolvedParams = await params
+ const generation = await prisma.generation.findUnique({
+ where: { id: resolvedParams.id },
+ include: {
+ user: {
+ select: {
+ name: true,
+ username: true,
+ image: true,
+ },
+ },
+ },
+ })
+
+ if (!generation) {
+ notFound()
+ }
+
+ const imageUrl = generation.imageUrl
+
+ return (
+