Skip to content

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

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

  1. Query Processing: Parse and normalize search terms
  2. Parallel Search: Query multiple APIs simultaneously
  3. Deduplication: Remove duplicate results
  4. Ranking: Score and sort results
  5. 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

feature-branch โ†’ Pull Request โ†’ Code Review โ†’ Merge to main โ†’ Auto-deploy

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.