# nikvis01/couchbase_hack_25 architecture

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

- Interactive diagram: https://gitdiagram.com/nikvis01/couchbase_hack_25
- Repository: https://github.com/nikvis01/couchbase_hack_25

## Overview

##### Project type and purpose
- This is a full-stack hackathon application that combines:
- A Python-based backend service (ML-powered inference + query APIs)
- A Next.js React dashboard (user-facing UI, auth, and data views)
- A persistent data store (Couchbase, managed via Prisma)
- Dockerized deployment (Dockerfiles in both `/backend` and `/dashboard` and docker-compose files)

##### File structure
Top-level directories:
- `/backend`:
– `api_server.py`, `infer.py`, `query.py`, `client.py` → Python modules exposing REST endpoints for inference, querying, and client helpers
– `smartpylogger/` → custom logging library
– `Dockerfile`, `docker-compose.yaml` → containerization and local orchestration
– `pyproject.toml`, `requirements.txt`, `setup.py` → Python packaging/configuration
– `tests/` → unit tests
- `/dashboard`:
– Next.js “app” directory → React pages and layouts for auth and dashboard
– `components/`, `hooks/`, `lib/` → UI components, custom hooks (e.g., mobile detection), Prisma client, auth client, mail utilities
– `prisma/schema.prisma` → database schema for Couchbase
– `Dockerfile`, `docker-compose.yaml` → containerization and orchestration
– `middleware.ts`, `next.config.ts`, lint and build configs

##### Detailed guidance
- Beneath it, group the `/dashboard` containers and internal API routes in one slice; annotate Prisma interactions

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Entry Point
    Browser["User Browser"]:::frontend

    %% Dashboard Service
    subgraph "Dashboard Service"
        NextApp["Next.js Dashboard App"]:::frontend
        subgraph "Authentication Subsystem"
            LoginPage["login/page.tsx"]:::frontend
            OTPPage["otp/page.tsx"]:::frontend
            AuthLayout["auth-layout.tsx"]:::frontend
            LoginForm["login-form.tsx"]:::frontend
            OTPForm["otp-form.tsx"]:::frontend
            AuthClient["auth-client.ts"]:::frontend
            AuthLib["auth.ts"]:::frontend
            Middleware["middleware.ts"]:::frontend
        end
        APIAuth["API Route /api/auth"]:::frontend
        subgraph "Prisma ORM & Schema"
            Schema["schema.prisma"]:::db
            PrismaClient["prisma.ts"]:::backend
        end
        MailUtil["send-mail.ts"]:::external
    end

    %% Inference Service
    subgraph "Inference Service"
        APIServer["api_server.py"]:::backend
        Infer["infer.py"]:::backend
        Query["query.py"]:::backend
        Client["client.py"]:::backend
        subgraph "smartpylogger"
            SPInit["__init__.py"]:::backend
            SPLog["logger.py"]:::backend
            SPUtil["utils.py"]:::backend
        end
    end

    %% Database
    Couchbase["Couchbase DB"]:::db

    %% External AWS Services
    SES["AWS SES (Email)"]:::external
    Logs["AWS CloudWatch/S3"]:::external

    %% Containerization & Orchestration
    subgraph "Container Orchestration"
        BackDocker["Dockerfile (Backend)"]:::external
        BackCompose["docker-compose.yaml (Backend)"]:::external
        DashDocker["Dockerfile (Dashboard)"]:::external
        DashCompose["docker-compose.yaml (Dashboard)"]:::external
    end

    %% Connections
    Browser -->|"GET/POST"| NextApp
    Browser -->|"GET/POST"| LoginPage
    Browser -->|"GET/POST"| OTPPage

    NextApp -->|"POST /api/auth"| APIAuth
    APIAuth -->|"QUERY/INSERT"| PrismaClient
    APIAuth -->|"POST email"| MailUtil

    NextApp -->|"REST call GET /infer"| APIServer

    APIServer -->|"calls infer()"| Infer
    APIServer -->|"calls query()"| Query
    APIServer -->|"uses client"| Client
    APIServer -->|"logs via"| SPInit
    SPInit -->|"imports"| SPLog
    SPInit -->|"imports"| SPUtil
    SPLog -->|"push logs"| Logs

    PrismaClient -->|"connect"| Couchbase
    Client -->|"optional DB ops"| Couchbase

    MailUtil -->|"via SMTP API"| SES

    BackCompose -->|"deploys"| APIServer
    BackCompose -->|"deploys"| Infer
    BackCompose -->|"deploys"| Query
    BackCompose -->|"deploys"| Client
    BackCompose -->|"deploys"| SPInit

    DashCompose -->|"deploys"| NextApp
    DashCompose -->|"deploys"| APIAuth
    DashCompose -->|"deploys"| PrismaClient

    classDef frontend fill:#D6EAF8,stroke:#2980B9
    classDef backend fill:#D5F5E3,stroke:#27AE60
    classDef db fill:#FCF3CF,stroke:#F1C40F
    classDef external fill:#E5E7E9,stroke:#7F8C8D

    %% Click Events
    click APIServer "https://github.com/nikvis01/couchbase_hack_25/blob/main/backend/api_server.py"
    click Infer "https://github.com/nikvis01/couchbase_hack_25/blob/main/backend/infer.py"
    click Query "https://github.com/nikvis01/couchbase_hack_25/blob/main/backend/query.py"
    click Client "https://github.com/nikvis01/couchbase_hack_25/blob/main/backend/client.py"
    click SPInit "https://github.com/nikvis01/couchbase_hack_25/blob/main/backend/smartpylogger/__init__.py"
    click SPLog "https://github.com/nikvis01/couchbase_hack_25/blob/main/backend/smartpylogger/logger.py"
    click SPUtil "https://github.com/nikvis01/couchbase_hack_25/blob/main/backend/smartpylogger/utils.py"
    click BackDocker "https://github.com/nikvis01/couchbase_hack_25/tree/main/backend/Dockerfile"
    click BackCompose "https://github.com/nikvis01/couchbase_hack_25/blob/main/backend/docker-compose.yaml"
    click LoginPage "https://github.com/nikvis01/couchbase_hack_25/blob/main/dashboard/app/(auth)/login/page.tsx"
    click OTPPage "https://github.com/nikvis01/couchbase_hack_25/blob/main/dashboard/app/(auth)/otp/page.tsx"
    click AuthLayout "https://github.com/nikvis01/couchbase_hack_25/blob/main/dashboard/components/auth/auth-layout.tsx"
    click LoginForm "https://github.com/nikvis01/couchbase_hack_25/blob/main/dashboard/components/auth/login-form.tsx"
    click OTPForm "https://github.com/nikvis01/couchbase_hack_25/blob/main/dashboard/components/auth/otp-form.tsx"
    click AuthClient "https://github.com/nikvis01/couchbase_hack_25/blob/main/dashboard/lib/auth-client.ts"
    click AuthLib "https://github.com/nikvis01/couchbase_hack_25/blob/main/dashboard/lib/auth.ts"
    click Middleware "https://github.com/nikvis01/couchbase_hack_25/blob/main/dashboard/middleware.ts"
    click APIAuth "https://github.com/nikvis01/couchbase_hack_25/blob/main/dashboard/app/api/auth/[...all]/route.ts"
    click Schema "https://github.com/nikvis01/couchbase_hack_25/blob/main/dashboard/prisma/schema.prisma"
    click PrismaClient "https://github.com/nikvis01/couchbase_hack_25/blob/main/dashboard/lib/prisma.ts"
    click MailUtil "https://github.com/nikvis01/couchbase_hack_25/blob/main/dashboard/lib/send-mail.ts"
    click DashDocker "https://github.com/nikvis01/couchbase_hack_25/tree/main/dashboard/Dockerfile"
    click DashCompose "https://github.com/nikvis01/couchbase_hack_25/blob/main/dashboard/docker-compose.yaml"
```
