Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 4 additions & 52 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
version: "3.9"

networks:
soko_net:
driver: bridge
soko-ml-bridge:
external: true

volumes:
auth_db_data:
Expand All @@ -16,7 +12,6 @@ volumes:
message_db_data:
blog_db_data:
ussd_db_data:
recommendation_db_data:
redis_data:


Expand All @@ -42,9 +37,9 @@ services:
- message_service
- blog_service
- ussd_service
- recommendation_service
networks:
- soko_net
- soko-ml-bridge
restart: on-failure

# ─────────────────────────────────────────
Expand Down Expand Up @@ -96,7 +91,7 @@ services:
DATABASE_URL: postgresql://auth_user:auth_pass@auth_db:5432/auth_db
USER_SERVICE_URL: http://user_service:8002
depends_on:
auth_db:
auth_db:
condition: service_healthy
networks:
- soko_net
Expand Down Expand Up @@ -174,8 +169,7 @@ services:
redis:
condition: service_healthy
networks:
soko_net: {}
soko-ml-bridge: {}
- soko_net
restart: on-failure

# ─────────────────────────────────────────
Expand Down Expand Up @@ -220,8 +214,7 @@ services:
payment_service:
condition: service_started
networks:
soko_net: {}
soko-ml-bridge: {}
- soko_net
restart: on-failure

# ─────────────────────────────────────────
Expand Down Expand Up @@ -417,45 +410,4 @@ services:
condition: service_started
networks:
- soko_net
restart: on-failure

# ─────────────────────────────────────────
# RECOMMENDATION SERVICE :8010
# ─────────────────────────────────────────
recommendation_db:
image: postgres:15-alpine
container_name: recommendation_db
environment:
POSTGRES_USER: rec_user
POSTGRES_PASSWORD: rec_pass
POSTGRES_DB: rec_db
volumes:
- recommendation_db_data:/var/lib/postgresql/data
networks:
- soko_net
healthcheck:
test: ["CMD-SHELL", "pg_isready -U rec_user -d rec_db"]
interval: 5s
timeout: 5s
retries: 5

recommendation_service:
build: ./services/recommendation
container_name: recommendation_service
ports:
- "127.0.0.1:8010:8010"
env_file: ./services/recommendation/.env
environment:
DATABASE_URL: postgresql://rec_user:rec_pass@recommendation_db:5432/rec_db
REDIS_URL: redis://redis:6379/2
USER_SERVICE_URL: http://user_service:8002
PRODUCE_SERVICE_URL: http://produce_service:8003
ORDER_SERVICE_URL: http://order_service:8004
depends_on:
recommendation_db:
condition: service_healthy
redis:
condition: service_healthy
networks:
- soko_net
restart: on-failure
123 changes: 31 additions & 92 deletions nginx/nginx.conf

Large diffs are not rendered by default.

116 changes: 0 additions & 116 deletions services/auth/alembic.ini

This file was deleted.

39 changes: 0 additions & 39 deletions services/auth/alembic/env.py

This file was deleted.

26 changes: 0 additions & 26 deletions services/auth/alembic/script.py.mako

This file was deleted.

36 changes: 29 additions & 7 deletions services/auth/app/routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,19 @@ async def register(payload: RegisterPayload, db: Session = Depends(get_db)):
db.commit()
db.refresh(cred)

except (httpx.HTTPStatusError, httpx.RequestError) as e:
logger.error(f"User Service call failed during register: {e}")
except httpx.HTTPStatusError as e:
db.rollback()
raise HTTPException(
status_code=503,
detail="Could not create user profile. Please try again."
)
try:
detail = e.response.json().get("detail", "Could not create user profile")
except Exception:
detail = "Could not create user profile"
status_code = 409 if e.response.status_code == 409 else 503
raise HTTPException(status_code=status_code, detail=detail)
except httpx.RequestError as e:
logger.error(f"User service unreachable: {e}")
db.rollback()
raise HTTPException(status_code=503, detail="Could not reach user service")


# ── 4. Issue tokens
access_token = create_access_token(str(cred.id), cred.role.value, cred.email)
Expand Down Expand Up @@ -180,4 +186,20 @@ def logout():

@router.get("/health")
def health():
return {"status": "ok", "service": "auth"}
return {"status": "ok", "service": "auth"}

@router.get("/verify-token-optional")
def verify_token_optional(
response: Response,
authorization: str = Header(default=None)
):
"""Like verify-token but returns 200 even without a token.
Used by nginx for routes that are public for GET but protected for writes."""
if authorization:
token = authorization.replace("Bearer ", "")
data = decode_token(token, token_type="access")
if data:
response.headers["x-user-id"] = data["sub"]
response.headers["x-user-role"] = data["role"]
response.headers["x-user-email"] = data["email"]
return {"valid": True}
3 changes: 2 additions & 1 deletion services/message/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ DATABASE_URL=postgresql://message:password@localhost:5432/soko_messaging
INTERNAL_SECRET=your_shared_secret
USER_SERVICE_URL=http://user-service:8002
PRODUCE_SERVICE_URL=http://produce-service:8003
NOTIFICATION_SERVICE_URL=http://notification-service:8008
NOTIFICATION_SERVICE_URL=http://notification-service:8008
SECRET_KEY=
1 change: 1 addition & 0 deletions services/message/app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class Settings(BaseSettings):
DATABASE_URL: str
INTERNAL_SECRET: str
SECRET_KEY: str
USER_SERVICE_URL: str = "http://user-service:8002"
PRODUCE_SERVICE_URL: str = "http://produce-service:8003"
NOTIFICATION_SERVICE_URL: str = "http://notification-service:8008"
Expand Down
4 changes: 3 additions & 1 deletion services/notification/.env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
DATABASE_URL=
INTERNAL_SECRET=
SECRET_KEY=
ALGORITHM=

#Africa is talking
AT_USERNAME=
AT_API_KEY=
AT_SENDER_ID=

# Other services
USER_SERVICE_URL=
USER_SERVICE_URL=
10 changes: 6 additions & 4 deletions services/notification/app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@


class Settings(BaseSettings):
DATABASE_URL: str
DATABASE_URL: str
INTERNAL_SECRET: str
SECRET_KEY: str
ALGORITHM: str = "HS256"

# Africa's Talking
AT_USERNAME: str
AT_API_KEY: str
AT_USERNAME: str
AT_API_KEY: str
AT_SENDER_ID: str = "Soko"

# Other services
USER_SERVICE_URL: str = "http://user-service:8002"
USER_SERVICE_URL: str = "http://user_service:8002"

class Config:
env_file = ".env"
Expand Down
Loading
Loading