import type { RequestHandler } from 'express';
type Bucket = { count: number; resetAt: number };
const buckets = new Map<string, Bucket>();
export function rateLimit(opts: { windowMs: number; max: number; key: (req: any) => string }): RequestHandler {
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
export async function withTxRetry<T>(fn: (tx: PrismaClient) => Promise<T>, attempts = 3): Promise<T> {
for (let i = 0; i < attempts; i++) {
import { z } from 'zod';
import type { RequestHandler } from 'express';
export function validateBody<T extends z.ZodTypeAny>(schema: T): RequestHandler {
return (req, res, next) => {
const parsed = schema.safeParse(req.body);
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
export function middleware(req: NextRequest) {
const { pathname } = req.nextUrl;
const protectedRoute = pathname.startsWith('/dashboard');
export type PostId = string & { readonly brand: unique symbol }
export type UserId = string & { readonly brand: unique symbol }
export interface User {
id: UserId
name: string
import { useEffect, useRef, ReactNode } from 'react'
import { createPortal } from 'react-dom'
interface ModalProps {
isOpen: boolean
onClose: () => void
type Toast = { id: string; message: string; kind: 'success' | 'error' };
const listeners = new Set<(t: Toast) => void>();
export const toastBus = {
on(fn: (t: Toast) => void) {
listeners.add(fn);
import { Helmet } from 'react-helmet-async'
interface SEOProps {
title: string
description: string
image?: string
import React, { Component, ReactNode } from 'react'
interface Props {
children: ReactNode
fallback?: ReactNode
onError?: (error: Error, errorInfo: React.ErrorInfo) => void
import { useForm } from 'react-hook-form'
import { useState } from 'react'
import api from '@/services/api'
interface SignupFormData {
email: string
import { useState } from 'react'
import { useQuery } from '@tanstack/react-query'
import { useDebounce } from '@/hooks/useDebounce'
import api from '@/services/api'
export function SearchInput() {
import { memo } from 'react'
import { Post } from '@/types'
interface PostListItemProps {
post: Post
onLike: (id: string) => void