This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a portfolio repository containing 6 production-ready security and AI projects, plus numerous other experimental projects. The main security projects are located in their own subdirectories:
- topoguard/ - Topology-Inspired Anomaly Detection for FinTech (Python/FastAPI)
- tinyguardian/ - On-Device LLM + IoT Security Agent (Python/FastAPI/Ollama)
- captcha-fights-back/ - Adaptive Behavioral CAPTCHA with LLM (Python/Flask)
- meshlock/ - Decentralized Secure Mesh for IoT (Rust)
- finprompt/ - Local LLM for Secure Financial Querying (Python/Tauri)
- hack-toolkit/ - Collection of security scripts (Python)
Each project is a standalone git repository designed to be pushed to GitHub separately.
Setup:
cd <project-name>
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txtRun API server:
# TopoGuard
cd topoguard
uvicorn api.main:app --reload --port 8000
# TinyGuardian
cd tinyguardian
python main.py # Starts on port 8080
# CAPTCHA
cd captcha-fights-back
python app.pyTesting:
pytest tests/
pytest --cov=<project-name> tests/ # With coverageCode quality:
black <project-name>/
isort <project-name>/
mypy <project-name>/
ruff check <project-name>/ # For TopoGuardGenerate sample data:
# TopoGuard
python scripts/generate_sample_data.py --transactions 10000 --output data/sample_transactions.json
python scripts/run_detection.py --input data/sample_transactions.json
# TinyGuardian
python scripts/simulate_iot_logs.pyBuild:
cd meshlock
cargo build --releaseRun:
cargo run --releaseTest:
cargo testMany projects use Next.js. Common commands:
npm install
npm run dev # Development server (usually http://localhost:3000)
npm run build # Production build
npm run start # Production server
npm run lint # ESLintDeploy to Vercel:
# Install Vercel CLI if needed
npm i -g vercel
# Deploy to production
vercel --prod
# Or link to existing project
vercel link
vercel --prodAll Python projects follow a similar modular architecture:
project-name/
├── project_name/ # Main package
│ ├── __init__.py
│ └── core/ # Core logic modules
│ ├── detector.py / guardian.py / analyzer.py
│ └── [specific modules]
├── api/ # FastAPI/Flask REST API
│ └── main.py
├── config/ # Configuration files
│ └── config.yaml
├── scripts/ # Utility scripts
│ ├── generate_sample_data.py
│ └── run_detection.py
├── data/ # Data directory
├── docs/ # Documentation
│ └── screenshots/ # Screenshot placeholders
├── requirements.txt
└── README.md
Core Components:
graph_builder.py- Builds transaction graphs from streamstopology_analyzer.py- Performs TDA using persistent homologydetector.py- Main orchestrator combining graph and topology analysis
Data Flow: Transaction Stream → Graph Builder → TDA Engine → Anomaly Detector → Alert Dashboard
Key Dependencies:
- TDA libraries: giotto-tda, gudhi, ripser, persim
- Graph analysis: networkx
- API: FastAPI
Core Components:
guardian.py- Main monitoring orchestratorllm_client.py- LLM integration (Ollama/LM Studio/llama.cpp)threat_classifier.py- Threat categorization logic
Data Flow: IoT Devices → MQTT Broker → Log Collector → Local LLM Analyzer → Threat Classifier → Web Dashboard
Key Dependencies:
- LLM: ollama, llama-cpp-python
- MQTT: paho-mqtt
- API: FastAPI
Core Components:
captcha_generator.py- LLM-powered challenge generationbehavioral_analyzer.py- Behavioral fingerprintingbrowser_fingerprint.py- Browser fingerprintingtopology_hasher.py- Topological hashing of user paths
Framework: Flask with NetworkX for graph analysis
Language: Rust with Tokio async runtime
Core Concepts:
- Cryptographic identity based on network topology
- Self-organizing mesh using gossip protocols
- Noise Protocol for encryption
- Sybil resistance through topology verification
Multiple Next.js applications use modern React patterns with the App Router (Next.js 16+). Common projects include:
- meowscope/ - Audio analysis tool with Stripe integration
- linkedin-face-crm/ - Face recognition CRM with Supabase
- electrical-estimator-ai/ - AI-powered electrical estimation with OpenAI
- Plus numerous Stripe-related tools and dashboards
Standard Tech Stack:
- Next.js 16.1+ with App Router
- React 19+ with Server Components
- TypeScript 5+
- Tailwind CSS 4 (PostCSS-based)
- ESLint for code quality
Project Structure:
project-name/
├── app/ # App Router (Next.js 13+ convention)
│ ├── layout.tsx # Root layout
│ ├── page.tsx # Home page
│ ├── globals.css # Global styles
│ ├── api/ # API routes (Route Handlers)
│ │ ├── webhooks/
│ │ │ └── route.ts # Webhook endpoints
│ │ ├── checkout/
│ │ │ └── route.ts # Checkout API
│ │ └── [other-routes]/
│ ├── auth/ # Auth routes
│ │ └── callback/ # OAuth callbacks
│ ├── dashboard/ # Protected routes
│ │ ├── page.tsx
│ │ └── [id]/ # Dynamic routes
│ └── [other-routes]/
├── components/ # React components
│ ├── ComponentName.tsx
│ └── [other-components]/
├── lib/ # Utility libraries
│ ├── supabase/ # Supabase client & middleware
│ │ ├── client.ts # Browser client
│ │ ├── server.ts # Server client
│ │ └── middleware.ts # Auth middleware
│ ├── stripe.ts # Stripe configuration
│ ├── openai.ts # OpenAI configuration
│ └── s3.ts # AWS S3 configuration
├── public/ # Static assets
├── middleware.ts # Next.js middleware (auth, redirects)
├── .env.local # Environment variables (not committed)
├── .env.example # Environment variable template
├── next.config.ts # Next.js configuration
├── tailwind.config.ts # Tailwind configuration
├── tsconfig.json # TypeScript configuration
└── package.json
Common Integrations:
-
Supabase (Database & Auth)
- Location:
lib/supabase/ - Client types: Browser client, Server client, Middleware
- Used for: Authentication, database, real-time subscriptions
- Environment variables:
NEXT_PUBLIC_SUPABASE_URLNEXT_PUBLIC_SUPABASE_ANON_KEYSUPABASE_SERVICE_ROLE_KEY
- Location:
-
Stripe (Payments)
- Location:
lib/stripe.ts - Used for: Subscriptions, one-time payments, webhooks
- API routes:
/api/checkout,/api/webhooks,/api/create-portal-session - Environment variables:
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEYSTRIPE_SECRET_KEYSTRIPE_WEBHOOK_SECRETNEXT_PUBLIC_STRIPE_[TIER]_PRICE_ID
- Location:
-
OpenAI (AI Features)
- Location:
lib/openai.ts - Used for: AI-powered features, content generation, analysis
- Environment variables:
OPENAI_API_KEY
- Location:
-
AWS S3 (File Storage)
- Location:
lib/s3.ts - Used for: File uploads, media storage
- Environment variables:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_REGIONAWS_S3_BUCKET_NAME
- Location:
Middleware Pattern:
Most projects use Next.js middleware for authentication:
// middleware.ts
import { type NextRequest } from 'next/server';
import { updateSession } from '@/lib/supabase/middleware';
export async function middleware(request: NextRequest) {
return await updateSession(request);
}
export const config = {
matcher: [
'/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)',
],
};Server Components vs Client Components:
- Default: Server Components (for data fetching, SEO)
- Client Components: Add
'use client'directive for:- Interactive UI (useState, useEffect)
- Browser APIs (localStorage, audio/video)
- Event handlers
API Routes (Route Handlers):
- Located in
app/api/*/route.ts - Support GET, POST, PUT, DELETE, PATCH
- Return
ResponseorNextResponseobjects - Used for webhooks, server-side API calls, backend logic
Environment Variables:
- Development:
.env.local(not committed) - Template:
.env.example(committed) - Public vars: Prefix with
NEXT_PUBLIC_ - Server-only vars: No prefix (only accessible in server components/routes)
Deployment:
- Platform: Vercel (primary)
- Automatic deployments from git push
- Environment variables configured in Vercel dashboard
- Production URL pattern:
https://project-name.vercel.app
Common Patterns:
-
Protected Routes:
- Use middleware to check authentication
- Redirect unauthenticated users to
/login - Server-side session validation
-
Database Queries:
- Server Components: Direct Supabase queries
- Client Components: API routes or client-side queries
- Use Supabase RLS (Row Level Security)
-
Form Handling:
- Libraries: react-hook-form, zod for validation
- Server Actions for mutations (Next.js 14+)
- API routes for complex logic
-
Stripe Webhooks:
- Endpoint:
/api/webhooks/route.ts - Verify signature with
STRIPE_WEBHOOK_SECRET - Handle events:
checkout.session.completed,customer.subscription.updated - Update database on successful payments
- Endpoint:
Each project is isolated. When working on a specific project:
- Navigate to the project directory
- Activate the appropriate environment (Python venv, cargo environment, etc.)
- Make changes within that project's structure
- Test using the project-specific test commands
- Commit changes to that project's git repository
Initial Setup:
cd <project-name>
npm install
cp .env.example .env.local # Copy and fill in environment variablesEnvironment Variables Setup:
- Copy
.env.exampleto.env.local - Fill in required values:
- Supabase: Create project at supabase.com, get URL and keys
- Stripe: Get keys from stripe.com/dashboard
- OpenAI: Get API key from platform.openai.com
- AWS: Configure S3 bucket and IAM credentials
- Never commit
.env.local(already in.gitignore)
Development Workflow:
npm run dev # Start dev server on http://localhost:3000
# Make changes - hot reload is automatic
npm run lint # Check for errors
npm run build # Test production buildCommon Development Tasks:
-
Adding a new page:
- Create
app/new-route/page.tsx - Add layout if needed:
app/new-route/layout.tsx
- Create
-
Adding an API endpoint:
- Create
app/api/endpoint-name/route.ts - Export GET, POST, or other HTTP method handlers
- Create
-
Creating a component:
- Add to
components/ComponentName.tsx - Use
'use client'if it needs interactivity - Import in pages with
@/components/ComponentName
- Add to
-
Database queries (Supabase):
- Server Components: Use
lib/supabase/server.ts - Client Components: Use
lib/supabase/client.ts - Always check for errors in response
- Server Components: Use
-
Testing Stripe integration locally:
- Use Stripe CLI:
stripe listen --forward-to localhost:3000/api/webhooks - Get webhook signing secret and add to
.env.local - Test checkout with test card: 4242 4242 4242 4242
- Use Stripe CLI:
Debugging:
- Check browser console for client-side errors
- Check terminal for server-side errors
- Use
console.log()liberally (removed automatically in production) - Inspect Network tab for API requests
- Check Vercel logs for production issues
Deployment to Vercel:
# First time
vercel
# Follow prompts to link project
# Deploy to production
vercel --prod
# Check deployment
vercel lsEnvironment Variables in Vercel:
- Go to Vercel dashboard → Project → Settings → Environment Variables
- Add all variables from
.env.local - Select environments: Production, Preview, Development
- Redeploy for changes to take effect
Projects using local LLMs require Ollama or similar to be running:
# Install Ollama first (see ollama.ai)
ollama pull phi3:mini # or tinyllama, mistral:7b-instruct-q4_K_MConfiguration is in config/config.yaml:
llm:
provider: "ollama"
model: "phi3:mini"
base_url: "http://localhost:11434"Projects using Topological Data Analysis:
- Persistent homology computed via ripser/gudhi
- Features extracted: total persistence, number of features, max persistence
- Topology complexity scores used for anomaly detection
- Visualization via persistence diagrams (plotly/matplotlib)
Projects are designed to be pushed to GitHub as separate repositories.
Setup remotes:
cd <project-name>
git remote add origin https://github.com/yksanjo/<project-name>.git
git branch -M main
git push -u origin mainSee GITHUB_SETUP.md for detailed instructions.
Python Projects:
config/config.yaml- Main configuration.envfiles for secrets (not committed)
Next.js Projects:
.env.local- Local environment variables (not committed).env.example- Template for required variables (committed)next.config.ts- Next.js configurationtailwind.config.ts- Tailwind CSS configurationtsconfig.json- TypeScript compiler optionseslint.config.mjs- ESLint rules
These projects emphasize:
- Local-first processing - No cloud dependencies where possible
- Privacy-preserving - Data stays on-device
- Mathematically grounded - Uses topology, graph theory
- CISO-friendly - Transparent, auditable, explainable
- Production-ready - Comprehensive error handling and logging
- Each project has its own git repository (
.gitdirectory) - Projects are independent - changes in one don't affect others
- Screenshots are placeholders in
docs/screenshots/- need to be captured - All projects use MIT License
- Configuration should never contain hardcoded secrets
- LLM projects require local model installation (Ollama recommended)
- Next.js projects require environment variables to be set before running
- Never commit
.env.localfiles - they contain sensitive credentials - Use
.env.exampleas a template for required environment variables - Most Next.js projects are deployed on Vercel with automatic deployments
The root directory contains many projects. Key organizational files:
- README.md - Portfolio overview with all 6 main projects
- GITHUB_SETUP.md - Instructions for pushing to GitHub
- LICENSE - MIT License for the cursor-auto-approve-agent code
- Individual project directories are self-contained
Projects may share similar dependencies but maintain separate requirements.txt, Cargo.toml, or package.json files. Always install dependencies within each project's directory.
Python Projects:
- Install with:
pip install -r requirements.txt - Use virtual environments:
python -m venv venv
Rust Projects:
- Dependencies in
Cargo.toml - Install automatically with:
cargo build
Next.js Projects:
- Dependencies in
package.json - Install with:
npm install - Common dependencies:
- Core: next, react, react-dom, typescript
- Styling: tailwindcss
- Integrations: @supabase/supabase-js, stripe, openai
- Forms: react-hook-form, zod
- UI: lucide-react (icons)
Python projects using FastAPI include interactive API docs:
- Navigate to
http://localhost:<port>/docsfor Swagger UI - Navigate to
http://localhost:<port>/redocfor ReDoc
Python Projects:
- TopoGuard: <100ms latency, 10K transactions/second
- TinyGuardian: <2s per log analysis on Raspberry Pi 4
- Projects are designed for resource-constrained environments where applicable
Next.js Projects:
- Server Components used by default for optimal performance
- Image optimization with Next.js Image component
- Automatic code splitting and lazy loading
- Edge runtime for API routes when appropriate
- Vercel Edge Network for global CDN
- Build-time optimizations with
npm run build - Lighthouse scores typically 90+ for performance