- Tentang Project
- Arsitektur
- Teknologi yang Digunakan
- Prasyarat
- Instalasi
- Menjalankan Project
- Struktur Database
- Dokumentasi API
- Fitur Utama
- Struktur Project
- Environment Variables
- Testing GraphQL
- Troubleshooting
- Pengembangan
SpaceMaster adalah platform manajemen komprehensif yang dirancang untuk mengelola venue (lokasi), ruangan, dan jadwal booking. Project ini dibangun menggunakan arsitektur microservices yang memisahkan setiap domain bisnis menjadi service independen yang berkomunikasi melalui GraphQL API.
- ✅ Scalable: Setiap service dapat di-scale secara independen
- ✅ Modular: Pemisahan concern yang jelas antar service
- ✅ Flexible: Mudah untuk menambahkan service baru
- ✅ GraphQL First: API yang powerful dan flexible
- ✅ Production Ready: Menggunakan Docker untuk deployment
Project ini menggunakan arsitektur microservices dengan 5 service utama:
┌─────────────────────────────────────────────────────────────┐
│ SpaceMaster Gateway │
│ (Port: 8004) │
│ [Unified GraphQL API] │
└──────────┬──────────────┬──────────────┬───────────────────┘
│ │ │
▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐
│ Venue │ │ Room │ │ Schedule │
│ Service │◄──┤ Service │◄──┤ Service │
│ :8001 │ │ :8002 │ │ :8003 │
└────┬─────┘ └────┬─────┘ └────┬─────┘
│ │ │
▼ ▼ ▼
┌─────────┐ ┌─────────┐ ┌─────────┐
│ Venue │ │ Room │ │Schedule │
│ DB │ │ DB │ │ DB │
└─────────┘ └─────────┘ └─────────┘
┌──────────────────────────────────────┐
│ Auth Service (Port: 8000) │
│ [Authentication & Authorization] │
└────────────────┬─────────────────────┘
│
▼
┌─────────────┐
│ Auth DB │
└─────────────┘
- SpaceMaster Gateway - API Gateway yang menggabungkan semua service menjadi satu unified GraphQL endpoint
- Auth Service - Menangani autentikasi, registrasi, dan manajemen user
- Venue Service - Mengelola data venue (lokasi)
- Room Service - Mengelola data ruangan di setiap venue
- Schedule Service - Mengelola jadwal dan ketersediaan ruangan
- FastAPI - Modern, fast (high-performance) web framework
- Ariadne - Schema-first GraphQL library untuk Python
- SQLAlchemy - Python SQL toolkit dan ORM
- PostgreSQL 15 - Relational database untuk setiap service
- python-jose - JWT token handling
- bcrypt - Password hashing
- Docker - Container platform
- Docker Compose - Multi-container orchestration
- GraphQL - Query language untuk API
Sebelum menjalankan project ini, pastikan Anda telah menginstall:
- Docker (versi 20.10 atau lebih baru)
- Docker Compose (versi 2.0 atau lebih baru)
- Git (untuk cloning repository)
Untuk development lokal (optional):
- Python 3.11+
- PostgreSQL 15+
git clone <repository-url>
cd SpaceMasterPastikan struktur folder sebagai berikut:
SpaceMaster/
├── auth-service/
├── venue-service/
├── room-service/
├── schedule-service/
├── spacemaster-gateway/
├── docker-compose.yml
└── README.md
docker-compose up --builddocker-compose up -d --build# Semua services
docker-compose logs -f
# Service tertentu
docker-compose logs -f auth-service
docker-compose logs -f venue-servicedocker-compose downdocker-compose down -vcd auth-service
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8000cd venue-service
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8001cd room-service
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8002cd schedule-service
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8003cd spacemaster-gateway
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8004Table: users
| Column | Type | Description |
|---|---|---|
| id | INTEGER | Primary key (auto increment) |
| username | VARCHAR(100) | Username (unique) |
| password_hash | VARCHAR(255) | Hashed password |
| role | VARCHAR(50) | User role (admin/user) |
Table: venues
| Column | Type | Description |
|---|---|---|
| id | INTEGER | Primary key (auto increment) |
| name | VARCHAR(150) | Venue name (unique) |
| address | TEXT | Venue address |
| city | VARCHAR(100) | City location |
| description | TEXT | Venue description (nullable) |
Table: rooms
| Column | Type | Description |
|---|---|---|
| id | INTEGER | Primary key (auto increment) |
| name | VARCHAR(150) | Room name |
| capacity | INTEGER | Room capacity |
| venue_id | INTEGER | Foreign key to venue |
Table: schedules
| Column | Type | Description |
|---|---|---|
| id | INTEGER | Primary key (auto increment) |
| room_id | INTEGER | Foreign key to room |
| start_time | DATETIME | Schedule start time |
| end_time | DATETIME | Schedule end time |
| status | ENUM | Status: AVAILABLE/BLOCKED/MAINTENANCE |
| Service | Port | GraphQL Endpoint | GraphiQL UI |
|---|---|---|---|
| Gateway | 8004 | http://localhost:8004/graphql | ✅ Tersedia |
| Auth Service | 8000 | http://localhost:8000/graphql | ✅ Tersedia |
| Venue Service | 8001 | http://localhost:8001/graphql | ✅ Tersedia |
| Room Service | 8002 | http://localhost:8002/graphql | ✅ Tersedia |
| Schedule Service | 8003 | http://localhost:8003/graphql | ✅ Tersedia |
💡 Tip: Akses endpoint GraphQL melalui browser untuk membuka GraphiQL playground
mutation {
register(
username: "john_doe"
password: "securepassword123"
role: "admin"
) {
success
message
}
}mutation {
login(
username: "john_doe"
password: "securepassword123"
) {
success
message
access_token
role
}
}query {
health
}query {
venues {
id
name
city
address
description
}
}query {
venue(id: "1") {
id
name
city
address
description
}
}mutation {
createVenue(data: {
name: "Grand Hotel Jakarta"
city: "Jakarta"
address: "Jl. Sudirman No. 123"
description: "Hotel mewah di pusat kota"
}) {
success
message
venue {
id
name
city
}
}
}mutation {
updateVenue(id: "1", data: {
name: "Grand Hotel Jakarta Updated"
city: "Jakarta"
address: "Jl. Sudirman No. 123"
description: "Updated description"
}) {
success
message
venue {
id
name
}
}
}mutation {
deleteVenue(id: "1") {
success
message
}
}query {
roomsByVenue(venueId: "1") {
id
name
capacity
venueId
}
}query {
room(id: "1") {
id
name
capacity
venueId
}
}mutation {
createRoom(data: {
name: "Meeting Room A"
capacity: 50
venueId: "1"
}) {
id
name
capacity
venueId
}
}query {
schedules {
id
roomId
startTime
endTime
status
}
}query {
availableSlots(
roomId: 1
startDate: "2025-01-01T00:00:00"
endDate: "2025-01-31T23:59:59"
) {
startTime
endTime
}
}mutation {
createSchedule(data: {
roomId: 1
startTime: "2025-01-10T09:00:00"
endTime: "2025-01-10T12:00:00"
status: AVAILABLE
}) {
id
roomId
startTime
endTime
status
}
}mutation {
updateSchedule(id: "1", data: {
status: BLOCKED
}) {
id
status
}
}mutation {
blockSchedule(input: {
roomId: 1
startTime: "2025-01-15T09:00:00"
endTime: "2025-01-15T17:00:00"
}) {
success
message
}
}mutation {
deleteSchedule(id: "1")
}Gateway menggabungkan semua service dengan relationship antar entity:
query {
venues {
id
name
city
rooms {
id
name
capacity
}
}
}query {
room(id: "1") {
id
name
capacity
venue {
name
city
}
schedules {
id
startTime
endTime
status
}
}
}query {
schedules {
id
startTime
endTime
status
room {
name
capacity
venue {
name
city
}
}
}
}- ✅ User registration dengan role-based
- ✅ Login dengan JWT token
- ✅ Password hashing menggunakan bcrypt
- ✅ Role management (admin/user)
- ✅ CRUD operations untuk venue
- ✅ Unique constraint pada nama venue
- ✅ Relasi dengan rooms
- ✅ Search dan filter venue
- ✅ Create dan manage rooms per venue
- ✅ Capacity tracking
- ✅ Relasi dengan venue dan schedules
- ✅ Query rooms by venue
- ✅ Create dan manage schedules
- ✅ Status tracking (AVAILABLE/BLOCKED/MAINTENANCE)
- ✅ Check available time slots
- ✅ Block/unblock schedules
- ✅ Prevent scheduling conflicts
- ✅ Unified GraphQL endpoint
- ✅ Service orchestration
- ✅ Cross-service relationships
- ✅ Data aggregation dari multiple services
SpaceMaster/
│
├── auth-service/ # Authentication & Authorization Service
│ ├── app/
│ │ ├── schema/
│ │ │ ├── __init__.py
│ │ │ ├── mutation.py # GraphQL mutations (register, login)
│ │ │ ├── query.py # GraphQL queries
│ │ │ └── schema.graphql # GraphQL schema definition
│ │ ├── auth.py # JWT token handling
│ │ ├── database.py # Database connection
│ │ ├── jwt_middleware.py # JWT middleware
│ │ ├── main.py # FastAPI application
│ │ └── models.py # SQLAlchemy models (User)
│ ├── Dockerfile
│ └── requirements.txt
│
├── venue-service/ # Venue Management Service
│ ├── app/
│ │ ├── graphql/
│ │ │ ├── __init__.py
│ │ │ ├── mutation.py # Venue mutations (CRUD)
│ │ │ ├── query.py # Venue queries
│ │ │ └── schema.graphql # GraphQL schema
│ │ ├── auth.py # Auth middleware
│ │ ├── database.py # Database connection
│ │ ├── main.py # FastAPI application
│ │ ├── models.py # Venue model
│ │ └── seed.py # Database seeding
│ ├── Dockerfile
│ └── requirements.txt
│
├── room-service/ # Room Management Service
│ ├── app/
│ │ ├── graphql/
│ │ │ ├── __init__.py
│ │ │ ├── mutation.py # Room mutations
│ │ │ ├── query.py # Room queries
│ │ │ ├── schema.graphql # GraphQL schema
│ │ │ └── types.py # GraphQL types
│ │ ├── services/
│ │ │ ├── __init__.py
│ │ │ └── venue_client.py # Venue service client
│ │ ├── auth.py
│ │ ├── database.py
│ │ ├── main.py
│ │ ├── models.py # Room model
│ │ └── schema.py
│ ├── Dockerfile
│ └── requirements.txt
│
├── schedule-service/ # Schedule Management Service
│ ├── app/
│ │ ├── graphql/
│ │ │ ├── mutation.py # Schedule mutations
│ │ │ ├── query.py # Schedule queries
│ │ │ └── schema.graphql # GraphQL schema
│ │ ├── __init__.py
│ │ ├── auth.py
│ │ ├── database.py
│ │ ├── integrations.py # Service integrations
│ │ ├── main.py
│ │ ├── models.py # Schedule model
│ │ └── room_client.py # Room service client
│ ├── Dockerfile
│ └── requirements.txt
│
├── spacemaster-gateway/ # API Gateway (Unified GraphQL)
│ ├── app/
│ │ ├── graphql/
│ │ │ ├── resolvers/
│ │ │ │ ├── __init__.py
│ │ │ │ ├── room.py # Room resolvers
│ │ │ │ ├── schedule.py # Schedule resolvers
│ │ │ │ └── venue.py # Venue resolvers
│ │ │ └── schema.graphql # Unified GraphQL schema
│ │ ├── services/
│ │ │ ├── __init__.py
│ │ │ ├── room_client.py
│ │ │ ├── schedule_client.py
│ │ │ └── venue_client.py
│ │ └── main.py
│ ├── Dockerfile
│ └── requirements.txt
│
├── docker-compose.yml # Docker Compose configuration
└── README.md # Project documentation
DATABASE_URL=postgresql://postgres:postgres@auth-db:5432/auth_dbDATABASE_URL=postgresql://postgres:postgres@venue-db:5432/venue_dbDATABASE_URL=postgresql://postgres:postgres@room-db:5432/room_dbDATABASE_URL=postgresql://postgres:postgres@schedule-db:5432/schedule_dbVENUE_SERVICE_URL=http://venue-service:8000/graphql
ROOM_SERVICE_URL=http://room-service:8000/graphql
SCHEDULE_SERVICE_URL=http://schedule-service:8000/graphql-
Buka GraphiQL Interface
- Gateway: http://localhost:8004/graphql
- Auth: http://localhost:8000/graphql
- Venue: http://localhost:8001/graphql
- Room: http://localhost:8002/graphql
- Schedule: http://localhost:8003/graphql
-
Jalankan Query/Mutation
- Copy salah satu query/mutation dari dokumentasi API di atas
- Paste ke GraphiQL editor
- Klik tombol "Play" atau tekan Ctrl+Enter
curl -X POST http://localhost:8000/graphql \
-H "Content-Type: application/json" \
-d '{
"query": "mutation { register(username: \"admin\", password: \"admin123\", role: \"admin\") { success message } }"
}'curl -X POST http://localhost:8000/graphql \
-H "Content-Type: application/json" \
-d '{
"query": "mutation { login(username: \"admin\", password: \"admin123\") { success message access_token role } }"
}'curl -X POST http://localhost:8004/graphql \
-H "Content-Type: application/json" \
-d '{
"query": "query { venues { id name city address } }"
}'-
Setup Request
- Method: POST
- URL: http://localhost:8004/graphql
- Headers: Content-Type: application/json
-
Body (GraphQL)
{ "query": "query { venues { id name city } }" }
Solution:
# Check logs
docker-compose logs [service-name]
# Restart service
docker-compose restart [service-name]
# Rebuild service
docker-compose up --build [service-name]Solution:
# Wait for database to be ready
docker-compose ps
# Check database health
docker-compose exec auth-db pg_isready -U postgres
# Reset database
docker-compose down -v
docker-compose up --buildSolution:
# Check port usage
netstat -ano | findstr :8000
netstat -ano | findstr :8001
# Kill process or change port di docker-compose.ymlSolution:
- Pastikan format query benar
- Check GraphQL schema di masing-masing service
- Gunakan GraphiQL untuk auto-completion
- Periksa logs untuk error detail
Solution:
# Check network
docker network ls
docker network inspect spacemaster_spacemaster-net
# Ensure all services in same network
docker-compose ps-
Buat folder service baru
mkdir new-service cd new-service -
Setup struktur
new-service/ ├── app/ │ ├── main.py │ ├── models.py │ ├── database.py │ └── graphql/ │ ├── schema.graphql │ ├── query.py │ └── mutation.py ├── Dockerfile └── requirements.txt -
Tambahkan ke docker-compose.yml
new-service: build: ./new-service environment: DATABASE_URL: postgresql://postgres:postgres@new-db:5432/new_db ports: - "8005:8000" networks: - spacemaster-net
-
Code Organization
- Pisahkan business logic dari resolvers
- Gunakan service layer untuk inter-service communication
- Keep models clean dan focused
-
Error Handling
- Implement proper error handling di semua resolvers
- Return meaningful error messages
- Log errors untuk debugging
-
Security
- Implement authentication untuk protected endpoints
- Validate input data
- Sanitize user inputs
- Use environment variables untuk credentials
-
Testing
- Write unit tests untuk business logic
- Test GraphQL queries dan mutations
- Integration testing antar services
-
Documentation
- Document GraphQL schema dengan descriptions
- Keep README up to date
- Document API changes
Untuk production, gunakan Alembic untuk database migrations:
# Install Alembic
pip install alembic
# Initialize Alembic
alembic init alembic
# Create migration
alembic revision --autogenerate -m "description"
# Apply migration
alembic upgrade headJika Anda menemukan bug, silakan buat issue dengan:
- Deskripsi bug
- Steps to reproduce
- Expected behavior
- Screenshots (jika ada)
- Environment details
Untuk request fitur baru:
- Deskripsi fitur
- Use case
- Mockup/diagram (jika ada)
Pull requests are welcome! Untuk perubahan besar:
- Fork repository
- Create feature branch
- Commit changes
- Push to branch
- Create Pull Request
Project ini dibuat untuk keperluan pembelajaran dan pengembangan.
- FastAPI Framework
- Ariadne GraphQL
- PostgreSQL
- Docker & Docker Compose
- Python Community
Made with ❤️ using Python & GraphQL
SpaceMaster - Your Space Management Solution