System_Architecture - SpecialAir123/Autio GitHub Wiki

System Architecture


πŸ“‘ Table of Contents


Overview

This page describes the end-to-end architecture for Autio’s MVP:

  • Frontend: React SPA for login & chat
  • Backend: FastAPI service exposing /auth/* and /chat/*
  • Database: SQLite (dev) β†’ PostgreSQL (prod)
  • AI Service: OpenAI Chat Completions API

Architecture Diagram


Components

1. Frontend

  • Framework: React (Create React App)
  • Routes:
    • /login β†’ email/password form, stores JWT in localStorage
    • /chat β†’ chat UI, sends messages with Bearer token
  • Responsibilities: UI state, input validation, message rendering.

2. Load Balancer (Optional)

  • Purpose: TLS termination, routing to backend instances.
  • Examples: Nginx, AWS ALB, Cloudflare.

3. FastAPI Backend

  • Routers:
    • Auth: /auth/signup, /auth/login
    • Chat: /chat/ (protected)
  • Security: OAuth2 password flow + JWT (python-jose, PassLib)
  • DB Access: SQLAlchemy sessions via dependency injection
  • AI Integration: calls OpenAI ChatCompletion in services/openai_client.py

4. Database

  • Dev: SQLite (file-based, no config)
  • Prod: PostgreSQL (managed service)
  • Tables:
    • users (id, email, hashed_pw, is_active)
    • (future) messages (id, user_id, role, text, timestamp)

5. External AI Service

  • Service: OpenAI Chat Completions API
  • Model: gpt-3.5-turbo (or newer)
  • Config: temperature 0.7, system prompt β€œYou are Autio, recommending cars.”

Data Flow

  1. User Login

    1. Frontend POST /auth/login with {email,password}
    2. Backend verifies or creates user β†’ issues JWT
    3. Frontend stores JWT
  2. Chat Interaction

    1. User sends message via React β†’ POST /chat/ + Authorization: Bearer <JWT>
    2. Backend validates JWT β†’ extracts user
    3. Backend calls OpenAI β†’ receives AI reply
    4. (Optional) Store user message & AI reply in DB
    5. Backend returns { reply: "..." }
    6. Frontend appends messages to chat window

Deployment & Scaling

  • Containerization: Dockerize both frontend & backend
  • Hosting:
    • Frontend β†’ Vercel, Netlify, S3+CloudFront
    • Backend β†’ AWS ECS/Fargate, Heroku, DigitalOcean App Platform
  • Database: Migrate to managed Postgres (AWS RDS, Cloud SQL)
  • Scaling Strategies:
    • Auto-scale backend instances behind load balancer
    • Introduce Redis for rate-limiting or caching
    • Use a queue (e.g. RabbitMQ, AWS SQS) for heavy processing or batching AI calls

This Wiki page captures Autio’s core system architecture for the MVP. Expand with network diagrams, security considerations, and operational runbooks as the project evolves.

⚠️ **GitHub.com Fallback** ⚠️