π Code Organization & Structure β
This document provides a comprehensive guide to the MyPit platform's codebase organization, explaining the purpose and structure of each directory and key files.
π Project Structure Overview β
mypit_core/
βββ π app/ # Next.js 15 App Router pages
βββ π components/ # Reusable React components
βββ π convex/ # Backend Convex functions & schema
βββ π hooks/ # Custom React hooks
βββ π lib/ # Utility libraries
βββ π smart_contracts/ # Ethereum smart contracts implementation
βββ π jwtoken_web_test/ # JWT token testing utilities
βββ π package.json # Dependencies & scripts
βββ π next.config.js # Next.js configuration
βββ π convex.config.ts # Convex configuration
βββ π middleware.ts # Next.js middleware
βββ π tailwind.config.ts # Tailwind CSS configurationπ Frontend Organization (/app) β
The Next.js App Router structure provides a file-system based routing mechanism with enhanced features.
Route Structure β
app/
βββ π layout.tsx # Root layout wrapper
βββ π page.tsx # Home page component
βββ π globals.css # Global styles
βββ π global-error.tsx # Global error boundary
βββ π middleware.ts # Route-level middleware
β
βββ π auth/ # Authentication flows
β βββ π login/
β β βββ π page.tsx # Login page
β β βββ π layout.tsx # Auth layout
β βββ π signup/
β βββ π page.tsx # Registration page
β βββ π components/ # Auth-specific components
β
βββ π dashboard/ # Main dashboard interface
β βββ π page.tsx # Dashboard home
β βββ π layout.tsx # Dashboard layout
β βββ π classes/ # Educational features
β βββ π page.tsx # Classes overview
β βββ π [classId]/ # Dynamic class pages
β
βββ π document/ # Document management
β βββ π [docID]/ # Dynamic document viewer
β βββ π page.tsx # Document display
β βββ π loading.tsx # Loading state
β
βββ π sandbox/ # Sandbox environments
β βββ π [id]/ # Dynamic sandbox instances
β βββ π page.tsx # Sandbox interface
β βββ π error.tsx # Error handling
β
βββ π role-application/ # Role request flows
β βββ π page.tsx # Application form
β βββ π login/ # Auth-required flow
β
βββ π payment/ # Payment processing
β βββ π page.tsx # Payment interface
β βββ π style.css # Payment-specific styles
β
βββ π verify/ # Verification flows
β βββ π badge/ # Badge verification
β βββ π page.tsx # Verification interface
β
βββ π collection/ # Badge collections
β βββ π [collection]/ # Dynamic collection pages
β
βββ π classDetails/ # Detailed class information
β βββ π [classId]/ # Dynamic class details
β
βββ π classEnrollment/ # Class enrollment flows
β βββ π [code]/ # Enrollment by code
β βββ π login/ # Auth-required enrollment
β
βββ π success/ # Success pages
βββ π error/ # Error pages
βββ π public/ # Static assets
βββ π google-icon.svg # OAuth provider iconsPage Component Structure β
typescript
// Example: app/dashboard/page.tsx
import { Metadata } from 'next';
import { redirect } from 'next/navigation';
import { getCurrentUser } from '@/convex/auth';
import DashboardComponent from '@/components/dashboard/holder-dashboard';
export const metadata: Metadata = {
title: 'Dashboard | MyPit',
description: 'Manage your badges and credentials',
};
export default async function DashboardPage() {
const user = await getCurrentUser();
if (!user) {
redirect('/auth/login');
}
return (
<div className="container mx-auto py-6">
<DashboardComponent user={user} />
</div>
);
}π§© Components Organization (/components) β
Organized by feature domains with shared UI components at the root level.
Component Hierarchy β
components/
βββ π TextEditor.tsx # Rich text editor (Quill.js)
β
βββ π ui/ # ShadCN UI components
β βββ π button.tsx # Base button component
β βββ π input.tsx # Form input component
β βββ π dialog.tsx # Modal dialog component
β βββ π alert.tsx # Alert/notification component
β βββ π avatar.tsx # User avatar component
β βββ π badge.tsx # Badge display component
β βββ π card.tsx # Card container component
β βββ π dropdown-menu.tsx # Dropdown menu component
β βββ π form.tsx # Form wrapper component
β βββ π label.tsx # Form label component
β βββ π select.tsx # Select dropdown component
β βββ π separator.tsx # Visual separator component
β βββ π sheet.tsx # Side panel component
β βββ π skeleton.tsx # Loading skeleton component
β βββ π table.tsx # Data table component
β βββ π tabs.tsx # Tab navigation component
β βββ π toast.tsx # Toast notification component
β βββ π tooltip.tsx # Tooltip component
β
βββ π convexProvider/ # Convex integration
β βββ π ConvexProvider.tsx # Convex client provider
β
βββ π customHooks/ # Reusable custom hooks
β βββ π queryWithStatus.tsx # Query state management
β
βββ π types/ # TypeScript type definitions
β βββ π userTypes.ts # User-related types
β
βββ π dashboard/ # Dashboard components
β βββ π header.tsx # Dashboard header
β βββ π sidebar.tsx # Navigation sidebar
β βββ π notifications.tsx # Notification panel
β βββ π profile-settings.tsx # User profile settings
β βββ π user-management-dashboard.tsx # Admin user management
β β
β βββ π holder-dashboard.tsx # Badge holder interface
β βββ π issuer-dashboard.tsx # Badge issuer interface
β βββ π verifier-dashboard.tsx # Badge verifier interface
β βββ π data-consumer-dashboard.tsx # Data consumer interface
β β
β βββ π classes/ # Educational components
β βββ π holder/ # Holder-specific components
β βββ π issuer/ # Issuer-specific components
β βββ π verifier/ # Verifier-specific components
β βββ π data-consumer/ # Data consumer components
β βββ π navigation/ # Navigation components
β βββ π sandbox/ # Sandbox components
β
βββ π purchase/ # Payment components
β βββ π Purchase.tsx # Payment form
β βββ π style.css # Payment styles
β
βββ π sandbox/ # Sandbox components
βββ π CodeRunner.tsx # Code execution interface
βββ π Select.tsx # Sandbox selector
βββ π style.css # Sandbox stylesComponent Design Patterns β
Compound Components β
typescript
// components/ui/card.tsx
const Card = React.forwardRef<HTMLDivElement, CardProps>(
({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("rounded-lg border bg-card text-card-foreground shadow-sm", className)}
{...props}
/>
)
);
const CardHeader = React.forwardRef<HTMLDivElement, CardHeaderProps>(
({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex flex-col space-y-1.5 p-6", className)}
{...props}
/>
)
);
export { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter };Feature Components β
typescript
// components/dashboard/holder-dashboard.tsx
interface HolderDashboardProps {
user: User;
badges?: Badge[];
classes?: Class[];
}
export default function HolderDashboard({ user, badges, classes }: HolderDashboardProps) {
const [activeTab, setActiveTab] = useState('badges');
return (
<div className="space-y-6">
<DashboardHeader user={user} />
<Tabs value={activeTab} onValueChange={setActiveTab}>
<TabsList>
<TabsTrigger value="badges">My Badges</TabsTrigger>
<TabsTrigger value="classes">Enrolled Classes</TabsTrigger>
<TabsTrigger value="requests">Access Requests</TabsTrigger>
</TabsList>
<TabsContent value="badges">
<BadgeGrid badges={badges} />
</TabsContent>
<TabsContent value="classes">
<ClassList classes={classes} />
</TabsContent>
<TabsContent value="requests">
<RequestsPanel />
</TabsContent>
</Tabs>
</div>
);
}Custom Hooks Pattern β
typescript
// components/customHooks/queryWithStatus.tsx
export function useQueryWithStatus<T>(
query: FunctionReference<"query", any, T>,
args?: any
) {
const [status, setStatus] = useState<'loading' | 'success' | 'error'>('loading');
const data = useQuery(query, args);
useEffect(() => {
if (data !== undefined) {
setStatus('success');
}
}, [data]);
return { data, status, isLoading: status === 'loading' };
}βοΈ Backend Organization (/convex) β
Convex functions organized by feature domain with shared utilities and configurations.
Backend Structure β
convex/
βββ π _generated/ # Auto-generated Convex types
βββ π convex.config.ts # Convex configuration
βββ π schema.ts # Database schema definitions
βββ π auth.config.ts # Authentication configuration
βββ π auth.ts # Authentication functions
βββ π http.ts # HTTP endpoints
βββ π crons.ts # Scheduled job definitions
βββ π triggers.ts # Database triggers
βββ π index.ts # Main exports
βββ π rateLimiter.ts # Rate limiting utilities
βββ π storage.ts # File storage functions
βββ π messages.ts # Messaging system
βββ π presence.ts # Real-time presence
βββ π documents.ts # Document management
βββ π documentViews.ts # Document viewing logic
βββ π teams.ts # Team management
βββ π teamsAdmin.ts # Team administration
βββ π user.ts # User management functions
βββ π sendEmails.ts # Email service integration
βββ π ResendOTP.ts # OTP email sending
βββ π ResendOTPPasswordReset.ts # Password reset emails
β
βββ π admin/ # Administrative functions
β βββ π adminActions.ts # Admin actions features: actions are external API calls
β βββ π adminMutations.ts #Admin Mutation features
β
βββ π holder/ # Badge holder functions
β βββ π holderActions.ts # External and internal API calls
β βββ π holderMutation.ts # Database mutations
β βββ π holderQueries.ts # Database queries
β
βββ π issuer/ # Badge issuer functions
β
βββ π verifier/ # Badge verifier functions
β
βββ π consumer/ # Data consumer functions
β
βββ π features/ # Platform additional features
β
βββ π ai_features/ # AI security module
β
βββ π blockchain_module/ # Blockchain integration
βββ π did_module/ # DID management
βββ π sandbox_module/ # Sandbox system
βββ π shamir_secret/ # Shamir's Secret Sharing
βββ π jwt_web/ # JWT token management
βββ π openAPI/ # Exposed API endpoints