Skip to content

πŸ“ 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 icons

Page 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 styles

Component 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

Released under the Dao Solution License.