Ecosyz Architecture Overview
This document provides a comprehensive overview of the Ecosyz platform architecture, design decisions, and technical implementation.
๐๏ธ System Architecture
High-Level Architecture
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Frontend โ โ Backend โ โ Database โ
โ (Next.js) โโโโโบโ (API Routes) โโโโโบโ (PostgreSQL) โ
โ โ โ โ โ โ
โ โข React/TSX โ โ โข REST APIs โ โ โข Prisma ORM โ
โ โข Tailwind CSS โ โ โข Auth Logic โ โ โข User Data โ
โ โข Components โ โ โข Business Logicโ โ โข Resources โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโ
โ External โ
โ Services โ
โ โ
โ โข Supabase Auth โ
โ โข AI Services โ
โ โข Search APIs โ
โโโโโโโโโโโโโโโโโโโ
๐ ๏ธ Technology Stack
Frontend Layer
- Framework: Next.js 14 (App Router)
- Language: TypeScript
- Styling: Tailwind CSS with custom design system
- State Management: React hooks + server state
- Forms: React Hook Form + Zod validation
- UI Components: Custom component library
Backend Layer
- Runtime: Node.js (Next.js API Routes)
- Authentication: Supabase Auth
- Database: PostgreSQL via Supabase
- ORM: Prisma
- API: RESTful endpoints
- Validation: Zod schemas
External Services
- Authentication: Supabase Auth
- Database: Supabase PostgreSQL
- File Storage: Supabase Storage
- Email: Resend (via Supabase)
- AI Services: OpenAI, custom summarization
- Search: Google Custom Search, arXiv, etc.
๐ Project Structure
Ecosyz/
โโโ app/ # Next.js App Router
โ โโโ (auth)/ # Authentication pages
โ โโโ (dashboard)/ # Protected pages
โ โโโ api/ # API routes
โ โ โโโ auth/ # Authentication endpoints
โ โ โโโ profile/ # Profile management
โ โ โโโ search/ # Search functionality
โ โ โโโ workspaces/ # Workspace management
โ โโโ components/ # React components
โ โ โโโ ui/ # Reusable UI components
โ โ โโโ auth/ # Auth-specific components
โ โ โโโ workspace/ # Workspace components
โ โโโ globals.css # Global styles
โโโ docs/ # Documentation
โโโ prisma/ # Database schema
โ โโโ schema.prisma # Database models
โ โโโ migrations/ # Database migrations
โโโ src/ # Shared utilities
โ โโโ lib/ # Core libraries
โ โ โโโ auth.ts # Authentication helpers
โ โ โโโ db.ts # Database client
โ โ โโโ supabase.ts # Supabase client
โ โ โโโ validation.ts # Zod schemas
โ โโโ types/ # TypeScript types
โโโ public/ # Static assets
โโโ tests/ # Test files
โโโ types/ # Global type definitions
๐ Authentication Architecture
Authentication Flow
1. User Login Request
โ
2. Frontend โ /api/auth/signin
โ
3. Supabase Auth Validation
โ
4. JWT Token Generation
โ
5. HTTP-Only Cookies Set
โ
6. Database User Sync
โ
7. Success Response
Session Management
- Storage: HTTP-only cookies (secure, XSS protection)
- Tokens: JWT access + refresh tokens
- Validation: Server-side on each request
- Refresh: Automatic token rotation
- Logout: Cookie clearing + Supabase session termination
Security Features
- Password Hashing: Handled by Supabase
- Token Encryption: JWT with secure signing
- CSRF Protection: SameSite cookie policy
- Rate Limiting: Supabase built-in protection
- Input Validation: Zod schemas on all inputs
๐๏ธ Database Architecture
Schema Design
-- Core Entities
Users (Supabase Auth) โโ Profiles (App Data)
โ
Workspaces (User's Projects)
โ
Resources (Papers, Articles, etc.)
โ
Annotations (User Notes)
Key Relationships
- User โ Profile: One-to-one (extended user data)
- User โ Workspaces: One-to-many (user's projects)
- Workspace โ Resources: One-to-many (project contents)
- Resource โ Annotations: One-to-many (user notes)
Data Flow
API Request โ Validation โ Business Logic โ Database โ Response
โ โ โ โ โ
Zod Schema โ Auth Check โ Service Layer โ Prisma โ JSON
๐ Search Architecture
Multi-Source Search
User Query โ Search Orchestrator โ Multiple APIs
โ โ โ
Results โ Deduplication โ Ranking โ Display
Supported Sources
- Academic: arXiv, Semantic Scholar, OpenAlex
- Web: Google Custom Search, Bing
- Code: GitHub Search API
- Media: YouTube Data API
Search Pipeline
- Query Processing: Parse and normalize search terms
- Parallel Search: Query multiple APIs simultaneously
- Deduplication: Remove duplicate results
- Ranking: Score and sort results
- Caching: LRU cache for performance
๐ค AI Integration
Summarization Engine
Input Text โ Preprocessing โ AI Model โ Postprocessing โ Summary
โ โ โ โ โ
Clean Text โ Chunking โ OpenAI API โ Formatting โ Structured Output
Key Features
- Multi-format Support: PDF, HTML, plain text
- Chunking Strategy: Intelligent text splitting
- Model Selection: GPT-4 for complex, GPT-3.5 for simple
- Caching: Avoid re-processing same content
- Error Handling: Fallback strategies
๐ Deployment Architecture
Vercel Deployment
Git Push โ Vercel Build โ Environment Setup โ Deployment
โ โ โ โ
main Build Command Env Variables Live Site
branch (pnpm build) (.env files) (CDN)
Environment Strategy
- Development: Local
.env.local
- Preview: Auto-created per PR
- Production: Separate environment variables
Scaling Considerations
- Serverless: Automatic scaling with Vercel
- CDN: Global content delivery
- Database: Supabase handles connection pooling
- Caching: Next.js ISR + Redis (future)
๐ง Development Workflow
Code Quality
# Linting
pnpm lint
# Type checking
pnpx tsc --noEmit
# Testing
pnpm test
# Build verification
pnpm build
Git Workflow
CI/CD Pipeline
- Linting: ESLint configuration
- Type Check: TypeScript compilation
- Build: Next.js production build
- Deploy: Vercel automatic deployment
๐ Performance Optimization
Frontend Optimizations
- Code Splitting: Route-based splitting
- Image Optimization: Next.js Image component
- Caching: Aggressive caching strategies
- Bundle Analysis: Bundle analyzer integration
Backend Optimizations
- Database Indexing: Optimized queries
- Caching: Redis for frequent data
- API Rate Limiting: Prevent abuse
- Response Compression: Gzip compression
๐ฎ Future Architecture
Planned Improvements
- Microservices: Split monolithic API
- GraphQL: Replace REST APIs
- Real-time: WebSocket integration
- Advanced AI: Custom model training
- Multi-region: Global deployment
Scalability Roadmap
- Database: Connection pooling, read replicas
- Caching: Redis cluster, CDN optimization
- Monitoring: Application performance monitoring
- Load Balancing: Advanced routing strategies
๐ Documentation Structure
- API Docs: Comprehensive endpoint documentation
- Component Library: Reusable component documentation
- Architecture Decisions: ADRs for major decisions
- Deployment Guide: Infrastructure as code
- Troubleshooting: Common issues and solutions
This architecture document is living and should be updated as the system evolves.