How piyush-eon/ai-car-marketplace works
Main Components
• Frontend (Client/UI)
• The entire UI is built in the Next.js app directory. Notice how the UI is broken into separate route groups (admin, auth, main) each handling different user flows:
▪ “(admin)” for administration tasks (managing cars, settings, dashboards, test drives).
▪ “(auth)” for authentication flows (sign-in and sign-up).
▪ “(main)” for the customer front-end (cars display, reservations, saved cars, test drive requests, and waitlist).
• Shared UI components in the “components” folder (e.g., car-card, header, home-search, test-drive-card) along with a UI kit under “components/ui” that leverages Shadcn UI.
• Server/Backend Actions
• The “actions” folder segments contain server actions related to various aspects such as admin, car listings, test drives, and settings. These likely serve as API endpoints or server-side logic triggered by Next.js server actions.
• The “middleware.js” file which may handle request validation, authentication checks, or redirects.
• Data Layer:
• The “prisma” directory holds all database schema definitions and migrations, ensuring that the ORM (Prisma) manages data structure and interactions.
• The “lib” folder includes modules for interacting with Supabase (“supabase.js”), Prisma (“prisma.js”), and other helpers (e.g., “data.js”, “checkUser.js”, “arcjet.js”).
• External Services:
• Authentication via Clerk is indicated by the environment variables (e.g., NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY) and the routes in the “(auth)” segment.
• ArcJet and Gemini API are external integrations whose keys are needed in the .env file.
Relationships and Interactions
• The Client (UI) interacts with the Server layer:
• When a user (admin or customer) interacts with the site, Next.js renders pages from the “app” segment.
• Server-side actions from the “actions” folder are called to fetch or mutate data.
• The Server layer communicates with the Data Layer:
• This interaction is managed by Prisma and Supabase through helper libraries (found in “lib”) to perform CRUD operations.
• External Connections:
• Authentication flows interact with Clerk.
• Integration with external APIs like ArcJet and Gemini occurs as needed through calls likely wrapped in the “lib” or “actions” modules.
Architectural Patterns and Design Principles
• Next.js with the new app directory promotes server-side rendering and server components where necessary.
• Clear separation between front-end route segments (admin vs. main vs. auth) indicates a domain-driven design.
• Use of “actions” for encapsulated server logic ensures clean separation between client and server responsibilities.
• Adherence to modularity: the usage of dedicated component, hooks, and helper libraries keeps concerns separated.
• Use of configuration and external environment variables emphasizes a twelve-factor app approach.