How asgerrud/chalkolate works
Main Components
• Frontend Client: Represented by the Next.js pages (found in src/pages), UI components (in src/components and src/components/ui), and styling (TailwindCSS configuration and global styles in src/globals.css). This layer handles the user interface and interactions.
• API Layer: Built using tRPC (evident from src/pages/api/trpc and the server API routers in src/server/api/routers). This provides the endpoints for data retrieval and manipulation.
• Server & Business Logic: Located in src/server (including authentication logic in src/server/auth.ts, db handling in src/server/db.ts, and various API routers that encapsulate business logic for accounts, challenges, schedules, and more).
• Database: Managed through Prisma (see prisma/schema.prisma, prisma/data.ts, prisma/seed.ts), indicating models, seeding, and migration logic.
• Authentication: Handled through NextAuth.js (found in src/pages/api/auth/[...nextauth].ts) providing authentication flows and secure access.
Relationships and Interactions
• The API Layer routes requests to the Server & Business Logic component which processes business rules (such as creating challenges, updating user profiles, or scheduling changes).
• An authentication flow where the client interacts with the NextAuth endpoint, which then verifies user data and sets up secure sessions that affect data access on both client and server.
Architectural Patterns and Design Principles
• Next.js Page-Based Routing: Show separate flows for page navigation (profile, settings, etc.) that are handled by dedicated pages.
• Separation of Concerns: UI components (presentation) are decoupled from business logic (server/api routers) and data management (Prisma models).
• API-Centric Design using tRPC: Emphasize how endpoints are type-safe and connect directly to the React UI.
• Modular Component-based approach: Use separate component folders (Layout, Navbar, challenge sections, etc.) to illustrate UI composition and reusability.
• Middleware/authentication: Clearly show that before API calls can mutate data, authentication is enforced via next-auth flows and utility functions like requireAuth.