Skip to content

Commit 7500581

Browse files
committed
Add user auth and sessions
1 parent b0c650c commit 7500581

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4572
-205
lines changed

client/src/lib/api.ts

Lines changed: 127 additions & 182 deletions
Large diffs are not rendered by default.

database_setup.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- Database setup script for StudyMate microservices
2+
-- This script creates the three separate databases needed for the microservices architecture
3+
4+
-- Create the three databases
5+
CREATE DATABASE studymate_auth;
6+
CREATE DATABASE studymate_documents;
7+
CREATE DATABASE studymate_ai;
8+
9+
-- Grant permissions to postgres user
10+
GRANT ALL PRIVILEGES ON DATABASE studymate_auth TO postgres;
11+
GRANT ALL PRIVILEGES ON DATABASE studymate_documents TO postgres;
12+
GRANT ALL PRIVILEGES ON DATABASE studymate_ai TO postgres;
13+
14+
-- Connect to auth database and create extensions if needed
15+
\c studymate_auth;
16+
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
17+
18+
-- Connect to documents database and create extensions if needed
19+
\c studymate_documents;
20+
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
21+
22+
-- Connect to ai database and create extensions if needed
23+
\c studymate_ai;
24+
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
25+
26+
-- Switch back to default database
27+
\c postgres;

deploy-microservices.sh

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/bin/bash
2+
3+
# StudyMate Microservices Deployment Script
4+
# This script deploys all three microservices using Docker Compose
5+
6+
set -e
7+
8+
echo "🚀 Starting StudyMate Microservices Deployment..."
9+
10+
# Colors for output
11+
RED='\033[0;31m'
12+
GREEN='\033[0;32m'
13+
YELLOW='\033[1;33m'
14+
BLUE='\033[0;34m'
15+
NC='\033[0m' # No Color
16+
17+
# Function to print colored output
18+
print_status() {
19+
echo -e "${BLUE}[INFO]${NC} $1"
20+
}
21+
22+
print_success() {
23+
echo -e "${GREEN}[SUCCESS]${NC} $1"
24+
}
25+
26+
print_warning() {
27+
echo -e "${YELLOW}[WARNING]${NC} $1"
28+
}
29+
30+
print_error() {
31+
echo -e "${RED}[ERROR]${NC} $1"
32+
}
33+
34+
# Check if Docker is running
35+
if ! docker info > /dev/null 2>&1; then
36+
print_error "Docker is not running. Please start Docker and try again."
37+
exit 1
38+
fi
39+
40+
# Check if Docker Compose is available
41+
if ! command -v docker-compose &> /dev/null; then
42+
print_error "Docker Compose is not installed. Please install Docker Compose and try again."
43+
exit 1
44+
fi
45+
46+
# Function to check if a port is available
47+
check_port() {
48+
local port=$1
49+
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null ; then
50+
print_warning "Port $port is already in use. Make sure no other services are running on this port."
51+
return 1
52+
fi
53+
return 0
54+
}
55+
56+
# Check if required ports are available
57+
print_status "Checking port availability..."
58+
check_port 8081 || print_warning "Auth Service port 8081 may be in use"
59+
check_port 8082 || print_warning "Document Service port 8082 may be in use"
60+
check_port 8083 || print_warning "AI Service port 8083 may be in use"
61+
check_port 3000 || print_warning "Frontend port 3000 may be in use"
62+
check_port 5432 || print_warning "PostgreSQL port 5432 may be in use"
63+
64+
# Stop any existing containers
65+
print_status "Stopping existing containers..."
66+
docker-compose down --remove-orphans || true
67+
68+
# Build the images
69+
print_status "Building Docker images..."
70+
docker-compose build --no-cache
71+
72+
# Start the services
73+
print_status "Starting microservices..."
74+
docker-compose up -d
75+
76+
# Wait for services to be ready
77+
print_status "Waiting for services to be ready..."
78+
sleep 10
79+
80+
# Check service health
81+
print_status "Checking service health..."
82+
83+
# Function to check service health
84+
check_service_health() {
85+
local service_name=$1
86+
local port=$2
87+
local endpoint=$3
88+
89+
local max_attempts=30
90+
local attempt=1
91+
92+
while [ $attempt -le $max_attempts ]; do
93+
if curl -f -s "http://localhost:$port$endpoint" > /dev/null 2>&1; then
94+
print_success "$service_name is healthy"
95+
return 0
96+
fi
97+
98+
print_status "Waiting for $service_name to be ready... (attempt $attempt/$max_attempts)"
99+
sleep 2
100+
attempt=$((attempt + 1))
101+
done
102+
103+
print_error "$service_name failed to start properly"
104+
return 1
105+
}
106+
107+
# Check each service
108+
check_service_health "Auth Service" 8081 "/api/auth/health" || true
109+
check_service_health "Document Service" 8082 "/api/documents/health" || true
110+
check_service_health "AI Service" 8083 "/api/ai/health" || true
111+
check_service_health "Frontend" 3000 "/" || true
112+
113+
# Show running containers
114+
print_status "Running containers:"
115+
docker-compose ps
116+
117+
# Show service URLs
118+
echo ""
119+
print_success "🎉 StudyMate Microservices are now running!"
120+
echo ""
121+
echo "📋 Service URLs:"
122+
echo " Frontend: http://localhost:3000"
123+
echo " Auth Service: http://localhost:8081"
124+
echo " Document Service: http://localhost:8082"
125+
echo " AI Service: http://localhost:8083"
126+
echo " Traefik Dashboard: http://localhost:8080"
127+
echo ""
128+
echo "📊 To view logs:"
129+
echo " docker-compose logs -f [service-name]"
130+
echo ""
131+
echo "🛑 To stop services:"
132+
echo " docker-compose down"
133+
echo ""
134+
echo "🔄 To restart services:"
135+
echo " docker-compose restart"

docker-compose.dev-no-traefik.yml

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,69 @@ services:
1515
networks:
1616
- dev-network
1717
depends_on:
18-
- server
18+
- auth-service
19+
- document-service
20+
- ai-service
1921

20-
server:
22+
auth-service:
2123
build:
22-
context: ./server
24+
context: ./microservices/auth-service
2325
dockerfile: Dockerfile
24-
container_name: studymate-server-dev
26+
container_name: studymate-auth-service-dev
2527
restart: unless-stopped
2628
ports:
27-
- "8082:8082" # Spring Boot API
29+
- "8081:8081" # Auth Service API
2830
networks:
2931
- dev-network
3032
environment:
31-
- SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/studymate
33+
- SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/studymate_auth
3234
- SPRING_DATASOURCE_USERNAME=studymate_user
3335
- SPRING_DATASOURCE_PASSWORD=studymate_password
3436
- SPRING_PROFILES_ACTIVE=dev
35-
- GENAI_SERVICE_URL=http://genai:8081
37+
- JWT_SECRET=your-super-secret-jwt-key-for-development-only-change-in-production
38+
depends_on:
39+
- postgres
40+
41+
document-service:
42+
build:
43+
context: ./microservices/document-service
44+
dockerfile: Dockerfile
45+
container_name: studymate-document-service-dev
46+
restart: unless-stopped
47+
ports:
48+
- "8082:8082" # Document Service API
49+
networks:
50+
- dev-network
51+
environment:
52+
- SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/studymate_documents
53+
- SPRING_DATASOURCE_USERNAME=studymate_user
54+
- SPRING_DATASOURCE_PASSWORD=studymate_password
55+
- SPRING_PROFILES_ACTIVE=dev
56+
- AI_SERVICE_URL=http://ai-service:8083
57+
depends_on:
58+
- postgres
59+
- ai-service
60+
61+
ai-service:
62+
build:
63+
context: ./microservices/ai-service
64+
dockerfile: Dockerfile
65+
container_name: studymate-ai-service-dev
66+
restart: unless-stopped
67+
ports:
68+
- "8083:8083" # AI Service API
69+
networks:
70+
- dev-network
71+
environment:
72+
- SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/studymate_ai
73+
- SPRING_DATASOURCE_USERNAME=studymate_user
74+
- SPRING_DATASOURCE_PASSWORD=studymate_password
75+
- SPRING_PROFILES_ACTIVE=dev
76+
- DOCUMENT_SERVICE_URL=http://document-service:8082
77+
- AI_OPENAI_API_KEY=your-openai-api-key-here
3678
depends_on:
3779
- postgres
3880
- weaviate
39-
- genai
4081

4182
genai:
4283
build:
@@ -45,12 +86,12 @@ services:
4586
container_name: studymate-genai-dev
4687
restart: unless-stopped
4788
ports:
48-
- "8081:8081" # FastAPI GenAI service
89+
- "8085:8081" # FastAPI GenAI service (external:internal)
4990
networks:
5091
- dev-network
5192
environment:
5293
- WEAVIATE_HOST=weaviate
53-
- WEAVIATE_PORT=8083
94+
- WEAVIATE_PORT=8084
5495
- PYTHONPATH=/app
5596
depends_on:
5697
- weaviate
@@ -69,7 +110,7 @@ services:
69110
POSTGRES_PASSWORD: studymate_password
70111
volumes:
71112
- postgres_dev_data:/var/lib/postgresql/data
72-
- ./server/src/main/resources/database_setup.sql:/docker-entrypoint-initdb.d/database_setup.sql
113+
- ./database_setup.sql:/docker-entrypoint-initdb.d/database_setup.sql
73114
networks:
74115
- dev-network
75116

@@ -81,11 +122,11 @@ services:
81122
- --host
82123
- 0.0.0.0
83124
- --port
84-
- '8083'
125+
- '8084'
85126
- --scheme
86127
- http
87128
ports:
88-
- "8083:8083" # Weaviate vector database
129+
- "8084:8084" # Weaviate vector database
89130
- "50051:50051" # gRPC port
90131
volumes:
91132
- weaviate_dev_data:/var/lib/weaviate

0 commit comments

Comments
 (0)