Skip to content

Latest commit

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

SynapseAI

The AI agent that lives inside your workflow.
SynapseAI connects to your tools — Gmail, Slack, GitHub, Notion, and more — and takes real action on your behalf, with your approval.

FastAPINext.jsPythonTypeScriptLicense: MIT


Table of Contents


Overview

SynapseAI is a full-stack, production-ready AI Agent SaaS platform. Users connect their third-party tools via OAuth and interact with a conversational AI agent that can:

  • Read and write emails, calendar events, Slack messages, GitHub issues, and more
  • Search the web in real time via Tavily
  • Search a personal knowledge base (RAG over uploaded documents)
  • Pause and ask for confirmation before taking any sensitive or destructive action

The system is built around a multi-step agentic tool loop powered by Google Gemini (primary) with Groq LLaMA 3.3 70B as an automatic fallback.


Architecture

+--------------------------------------------------+
| Frontend |
| Next.js 14 (App Router) |
| Landing | Auth | Dashboard | Agent Chat |
+------------------------+-------------------------+
| HTTPS / WebSocket
+------------------------v-------------------------+
| Backend |
| FastAPI (async, Python 3.11+) |
| |
| +-------------+ +--------------------------+ |
| | REST API | | Agent Engine | |
| | /api/v1/* | | ChatAgent + ToolLoop | |
| +-------------+ +------------+-------------+ |
| | |
| +------------------------------v-------------+ |
| | Services Layer | |
| | AI Router | Composio | Payments | Email | |
| +------------------------------+------------+ |
+--------------------------------------------------+
|
+-------------------+--------------------+
| | |
Supabase Redis Stripe / SMTP
Postgres + (optional) Composio APIs
Storage token cache Tavily Search

Features

FeatureDescription
Agentic Tool LoopMulti-step reasoning — up to 5 tool call iterations per turn
AI FallbackGemini primary, Groq fallback — fully automatic, transparent to user
Human-in-the-LoopSensitive actions require explicit user approval before executing
OAuth IntegrationsGmail, Slack, GitHub, Notion, Linear, Calendar, Sheets, LinkedIn
Conversation MemorySliding-window history + automatic summarization for long sessions
Knowledge Base (RAG)Upload files, vector search, grounded answers
Web SearchReal-time search via Tavily, triggered on demand
Stripe BillingSubscription checkout, customer portal, webhook handling
AnalyticsPer-user usage tracking dashboard
JWT AuthAccess + refresh token rotation, bcrypt password hashing
Rate LimitingPer-user and global rate limiting via SlowAPI
Docker ReadyMulti-stage Dockerfile + Docker Compose for local stack

Tech Stack

Backend

LayerTechnology
FrameworkFastAPI 0.115 (async)
LanguagePython 3.11+
DatabaseSupabase (PostgreSQL + Storage)
CacheRedis (optional — token denylist)
AI PrimaryGoogle Gemini 2.0 Flash
AI FallbackGroq — LLaMA 3.3 70B
IntegrationsComposio (OAuth + tool execution)
Web SearchTavily Search API
PaymentsStripe (subscriptions + webhooks)
EmailSMTP / Resend
AuthJWT (access + refresh) + bcrypt
SchedulerAPScheduler (background jobs)
Loggingstructlog (JSON prod / pretty dev)
Rate LimitingSlowAPI
Testingpytest + pytest-asyncio
LintingRuff + mypy
ContainerDocker multi-stage + Docker Compose

Frontend

LayerTechnology
FrameworkNext.js 14 (App Router)
LanguageTypeScript 5
StylingTailwind CSS
AuthSupabase Auth (client SDK)
Real-timeWebSocket (agent streaming)
IconsLucide React

Project Structure

SynapseAI/
+-- backend/
| +-- app/
| | +-- agents/ # Agent engine
| | | +-- chat_agent.py # Core agentic tool loop
| | | +-- websocket_handler.py # WebSocket streaming
| | | +-- prompt_builder.py # System prompt construction
| | | +-- memory/ # Conversation history + summarization
| | | +-- tools/
| | | +-- composio_toolkit.py
| | | +-- tavily_search.py
| | | +-- knowledge_base.py
| | | +-- confirmation.py # Human-in-the-loop gate
| | | +-- router.py # Semantic tool routing
| | +-- api/v1/ # REST endpoints
| | | +-- agent/ # Chat, WebSocket, confirmations
| | | +-- ai/ # Direct AI completion endpoints
| | | +-- analytics/ # Usage statistics
| | | +-- files/ # File upload / storage
| | | +-- notifications/ # In-app + email notifications
| | | +-- payments/ # Stripe integration
| | | +-- preferences/ # User preferences
| | | +-- users/ # Profile management
| | +-- core/ # Config, auth, exceptions, DI
| | +-- db/ # Supabase async client singleton
| | +-- middleware/ # Logging, rate limiting
| | +-- services/
| | | +-- ai/ # Gemini, Groq, AI router
| | | +-- cache/ # Redis client
| | | +-- composio_oauth.py # OAuth wiring
| | | +-- email/ # Transactional email
| | | +-- payments/ # Stripe service
| | | +-- scheduler/ # Background jobs
| | +-- utils/
| +-- scripts/
| | +-- schema.sql # Supabase schema
| | +-- agent_migration.sql # Agent tables
| | +-- rag_setup.sql # Vector search setup
| +-- tests/
| +-- Dockerfile
| +-- docker-compose.yml
| +-- Makefile
| +-- requirements.txt
|
+-- frontend/
+-- app/
| +-- page.tsx # Landing page
| +-- sign-in/
| +-- sign-up/
| +-- dashboard/
| +-- page.tsx # Agent chat interface
| +-- analytics/
| +-- integrations/
| +-- settings/
+-- components/
+-- hooks/
+-- lib/
+-- package.json

Getting Started

Prerequisites


Backend Setup

cd backend
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate# Install dependencies
pip install -r requirements.txt -r requirements-dev.txt
# Configure environment
cp .env.example .env
# Fill in your keys in .env# Apply database schema (Supabase SQL Editor)# Run in order: schema.sql -> agent_migration.sql -> rag_setup.sql# Run dev server
make dev # Uvicorn with hot reload on :8000

API docs: http://localhost:8000/docs


Frontend Setup

cd frontend
npm install
cp .env.local.example .env.local
# Set NEXT_PUBLIC_API_URL and Supabase keys
npm run dev # Next.js on :3000

Environment Variables

Backend (backend/.env)

VariableDescription
SUPABASE_URLSupabase project URL
SUPABASE_SERVICE_KEYSupabase service role key
GEMINI_API_KEYGoogle AI Studio API key
GEMINI_MODELModel name (default: gemini-2.0-flash)
GROQ_API_KEYGroq API key (fallback AI)
COMPOSIO_API_KEYComposio API key
TAVILY_API_KEYTavily search API key
JWT_SECRET_KEYSecret for signing JWTs
STRIPE_SECRET_KEYStripe secret key
STRIPE_WEBHOOK_SECRETStripe webhook signing secret
REDIS_URLRedis connection URL (optional)
ALLOWED_ORIGINSComma-separated CORS origins
ENVdevelopment or production

See backend/.env.example for the full reference.

Frontend (frontend/.env.local)

VariableDescription
NEXT_PUBLIC_API_URLBackend API base URL
NEXT_PUBLIC_SUPABASE_URLSupabase project URL
NEXT_PUBLIC_SUPABASE_ANON_KEYSupabase anon/public key

API Reference

Authentication

MethodEndpointDescription
POST/api/v1/auth/registerRegister new user
POST/api/v1/auth/loginLogin, receive JWT tokens
POST/api/v1/auth/refreshRotate access token
POST/api/v1/auth/logoutInvalidate session

Agent

MethodEndpointDescription
WS/api/v1/agent/ws/{session_id}WebSocket agent chat (streaming)
POST/api/v1/agent/chatNon-streaming chat
POST/api/v1/agent/confirm/{id}Approve/reject pending action
GET/api/v1/agent/sessionsList conversation sessions
DELETE/api/v1/agent/sessions/{id}Delete a session

Files & AI

MethodEndpointDescription
POST/api/v1/files/uploadUpload file to knowledge base
GET/api/v1/files/List user files
DELETE/api/v1/files/{id}Delete a file
POST/api/v1/ai/chatDirect AI completion
POST/api/v1/ai/chat/streamSSE streaming completion

Payments

MethodEndpointDescription
POST/api/v1/payments/checkoutCreate Stripe checkout session
GET/api/v1/payments/subscriptionGet subscription status
POST/api/v1/payments/portalBilling portal link
POST/api/v1/payments/webhookStripe webhook receiver

AI Agent Design

The agent runs a deterministic tool loop (up to MAX_TOOL_ITERATIONS = 5):

User Message
|
v
Load Memory (sliding window + summary)
|
v
Semantic Tool Routing -> select relevant Composio apps
|
v
Gemini API call (with tools)
|
+-- finish_reason == "tool_calls"?
| +-- Yes -> needs_confirmation?
| | +-- Yes -> pause, yield ConfirmationEvent (wait for user)
| | +-- No -> execute tool -> append result -> loop
| +-- No -> yield text reply -> break
|
+ (on Gemini error) -> Groq Fallback (text only)
|
v
Save to Memory -> maybe_summarize
|
v
yield AgentTurn (metadata)

Confirmation gate: Actions tagged as sensitive (e.g. GMAIL_SEND_EMAIL, SLACK_SEND_MESSAGE) are intercepted. The agent pauses and surfaces a human-readable summary to the UI. Execution only proceeds when the user explicitly approves.


Integrations

Connected via Composio OAuth:

AppCapabilities
GmailRead, search, send, reply to emails
Google CalendarCreate, update, list events
SlackSend messages, read channels
GitHubCreate issues, open PRs, search repos
NotionCreate and update pages/databases
Google SheetsRead and write spreadsheet data
LinearCreate and update issues, projects
LinkedInPost updates, read profile
BrowserbaseHeadless browser automation

Deployment

Backend — Railway / Render

# Set all env vars from .env.example in your platform dashboard# The Dockerfile handles everything — platform auto-detects it# Set ENV=production to disable /docs and enable JSON logging

Frontend — Vercel

cd frontend
vercel
# Set NEXT_PUBLIC_API_URL in your Vercel project environment settings

Docker Compose (self-hosted)

cd backend
make dev-docker # Starts API + Redis

Contributing

  1. Fork the repo and create a feature branch: git checkout -b feature/my-feature
  2. Follow the existing code structure (router -> schemas -> service pattern)
  3. Run make lint && make typecheck && make test before submitting
  4. Open a PR with a clear description of what changed and why

License

MIT (c) 2025 SynapseAI

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages