# dj-no1/sih_scira architecture

> Architecture diagram of the GitHub repository dj-no1/sih_scira, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dj-no1/sih_scira
- Repository: https://github.com/dj-no1/sih_scira

## Overview

##### Project Type and Purpose
- Scira is a full-stack, server-rendered AI-powered search engine built on Next.js 13 (app-router).
- It provides both client-side React UI and server-side API routes (serverless functions), integrates multiple AI/search providers, and persists user data via Drizzle ORM.

##### File Structure
- Frontend:
- `app/` directory (React server & client components, layouts, pages, page.tsx files)
- `components/`, `contexts/`, `hooks/` directories (reusable UI, state providers, custom hooks)
- Backend/API:
- `app/api/*` route handlers (auth, search, transcribe, OG image)
- `lib/` (utilities, AI-provider clients, database queries via Drizzle)
- Database:
- Drizzle ORM config and migration files under `drizzle/`
- SQL schema and index scripts
- Deployment & Config:
- `Dockerfile`, `docker-compose.yml`, `.env.example`
- `next.config.ts`, Vercel config (`vercel.json`)
- Environment typing under `env/client.ts` & `env/server.ts`

##### README for Insights
- Key external integrations: Vercel AI SDK, Exa.AI, OpenAI, Anthropic, xAI, Google Maps, OpenWeather, TMDB, Aviation Stack, Mem0, Tavily, Daytona sandbox, Better Auth.
- Core features grouped by domain: Web/Memory/Analysis/Chat/X/Reddit/Academic/YouTube/Extreme.

##### Main Components & Their Relationships
a. Client (Browser / Frontend)
- Renders UI from `app/`, interacts with user, calls Next.js page endpoints and API routes via HTTP/fetch.
b. Next.js Server (Server Components + API Routes)
- Server Components generate HTML (SSR/SSG).
- API routes handle dynamic logic: search orchestration, authentication, image generation, session management.
- Uses `lib/` for business logic and external-service clients.
c. Database Layer
- Postgres (or any SQL) managed via Drizzle ORM.
- Stores user sessions, memories, usage data.
d. External Services
- AI Providers (OpenAI, xAI, Anthropic, Groq) via Vercel AI SDK
- Web search & content retrieval (Exa.AI, Tavily)
- Maps & location (Google Maps, Mapbox)
- Weather (OpenWeather)
- Flight tracking (Aviation Stack)
- Media metadata (TMDB)
- Authentication (Better Auth + OAuth providers)
- Analytics (PostHog)
- Code sandbox (Daytona)
- Memory management (Mem0)

##### Architectural Patterns & Design Principles
- Containerization: Docker multi-stage build, Docker Compose for local dev.
- Modularization: Clear separation of concerns–UI (`app/`, `components/`), state & contexts (`contexts/`, `hooks/`), business logic (`lib/`), data schema & migrations (`drizzle/`).
- Serverless micro-endpoints: Each `app/api/.../route.ts` acts as an isolated function.
- C4-like layering:
- Level 1: System Context (User ↔ Scira)
- Level 2: Containers (Browser, Next.js Backend, Database, External Services)
- Level 3: Components (e.g., Auth API, Search Orchestrator, OG Image Generator, Drizzle ORM, AI-SDK client)

##### Capturing Essential Details
- Only major feature groups in the high-level view (e.g., Search, Auth, Memory, Analytics).
- In detailed view, break down complex modules (e.g., within “Search Orchestrator,” show calls to Exa, AI models, streaming).

## Diagram (Mermaid)

```mermaid
flowchart TD
    user("User"):::user

    subgraph Browser
        direction TB
        ReactUI["React UI"]:::frontend
        Providers["Context Providers & Hooks"]:::frontend
    end

    subgraph "Next.js Server"
        direction TB
        ServerComp["Server Components"]:::backend
        APIRoutes["API Routes"]:::backend
        BizLogic["Business Logic & External-Service Clients"]:::backend
    end

    Database(("Drizzle ORM Database")):::database

    subgraph "External Services"
        direction TB
        OpenAI["AI Providers\n(OpenAI/Anthropic/xAI/Groq)"]:::external
        WebSearch["Web Search\n(Exa.AI/Tavily)"]:::external
        Maps["Maps & Location\n(Google Maps/Mapbox)"]:::external
        Weather["Weather\n(OpenWeather)"]:::external
        Flight["Flight Tracker\n(Aviation Stack)"]:::external
        Media["Media Metadata\n(TMDB)"]:::external
        AuthExt["Auth Providers\n(Better Auth/OAuth)"]:::external
        Analytics["Analytics\n(PostHog)"]:::external
        Sandbox["Code Sandbox\n(Daytona)"]:::external
        MemorySvc["Memory Service\n(Mem0)"]:::external
    end

    subgraph "Configuration & Deployment"
        direction TB
        Config["Env Typings & Config"]:::backend
        Deploy["Containerization\n(Docker & Compose)"]:::backend
    end

    %% Connections
    user -->|uses| ReactUI
    ReactUI -->|SSR & Fetch| ServerComp
    ReactUI -->|Fetch API| APIRoutes

    ServerComp -->|calls| BizLogic
    APIRoutes -->|uses| BizLogic

    BizLogic -->|queries/mutates| Database

    BizLogic -->|calls| OpenAI
    BizLogic -->|calls| WebSearch
    BizLogic -->|calls| Maps
    BizLogic -->|calls| Weather
    BizLogic -->|calls| Flight
    BizLogic -->|calls| Media
    BizLogic -->|calls| AuthExt
    BizLogic -->|calls| Analytics
    BizLogic -->|calls| Sandbox
    BizLogic -->|calls| MemorySvc

    user -->|configures| Config
    Config -->|used by| ServerComp
    Deploy -->|deploys| ServerComp
    Deploy -->|deploys| Database

    %% Click Events
    click ReactUI "https://github.com/dj-no1/sih_scira/tree/main/app/"
    click Providers "https://github.com/dj-no1/sih_scira/tree/main/contexts/"
    click ServerComp "https://github.com/dj-no1/sih_scira/tree/main/app/"
    click APIRoutes "https://github.com/dj-no1/sih_scira/tree/main/app/api/"
    click BizLogic "https://github.com/dj-no1/sih_scira/tree/main/lib/"
    click Database "https://github.com/dj-no1/sih_scira/tree/main/drizzle/"
    click Config "https://github.com/dj-no1/sih_scira/blob/main/.env.example"
    click Deploy "https://github.com/dj-no1/sih_scira/tree/main/Dockerfile"

    %% Styles
    classDef frontend fill:#bbdefb,stroke:#1e88e5,color:#0d47a1
    classDef backend fill:#c8e6c9,stroke:#388e3c,color:#1b5e20
    classDef database fill:#ffe0b2,stroke:#f57c00,color:#e65100
    classDef external fill:#eeeeee,stroke:#9e9e9e,color:#424242
    classDef user fill:#f8bbd0,stroke:#d81b60,color:#880e4f
```
