docsservicesCore-APICore-API

Core-API

The Core-API is the primary backend service handling all business logic for task tracking, time entries, goals, projects, habits, reminders, and reports.

Overview

Core-API is a Flask-based Python microservice that provides the main backend functionality for Goalixa. It follows a 3-layer architecture pattern:

Technology Stack

ComponentTechnology
FrameworkFlask (Python 3.11)
DatabasePostgreSQL
Driverpsycopg
AuthenticationJWT (dual-token)
MetricsPrometheus
LoggingStructured logging

Project Structure

Core-API/
├── main.py                      # Application entry point
├── app/
│   ├── __init__.py
│   ├── auth_client.py           # Auth service client
│   ├── metrics.py               # Prometheus metrics
│   ├── observability.py         # Logging configuration
│   ├── presentation/
│   │   └── routes.py            # API endpoints
│   ├── service/
│   │   └── task_service.py      # Business logic
│   ├── repository/
│   │   └── postgres_repository.py  # Database operations
│   └── auth/
│       ├── jwt.py               # JWT validation
│       ├── models.py            # Auth models
│       ├── oauth.py             # OAuth handlers
│       └── routes.py            # Auth endpoints
├── docker-compose.yml
└── k8s/                         # Kubernetes manifests

API Endpoints

Health

MethodEndpointDescription
GET/healthService health check

Tasks

MethodEndpointDescription
GET/api/tasksList all tasks
POST/api/tasksCreate new task
POST/api/tasks/<id>/startStart timer
POST/api/tasks/<id>/stopStop timer
POST/api/tasks/<id>/completeMark complete
POST/api/tasks/<id>/reopenReopen task
POST/api/tasks/<id>/deleteDelete task

Projects

MethodEndpointDescription
GET/api/projectsList projects
POST/api/projectsCreate project
POST/api/projects/<id>/editUpdate project
POST/api/projects/<id>/deleteDelete project

Goals

MethodEndpointDescription
GET/api/goalsList goals
POST/api/goalsCreate goal
POST/api/goals/<id>/editUpdate goal
POST/api/goals/<id>/deleteDelete goal
POST/api/goals/<id>/subgoalsAdd subgoals

Habits

MethodEndpointDescription
GET/api/habitsList habits
POST/api/habitsCreate habit
POST/api/habits/<id>/toggleToggle completion
POST/api/habits/<id>/updateUpdate habit
POST/api/habits/<id>/deleteDelete habit

Time Entries

MethodEndpointDescription
GET/api/timer/entriesList time entries
GET/api/timer/dashboardTimer dashboard data

Reminders

MethodEndpointDescription
GET/api/remindersList reminders
POST/api/remindersCreate reminder
POST/api/reminders/<id>/updateUpdate reminder
POST/api/reminders/<id>/toggleToggle reminder
POST/api/reminders/<id>/deleteDelete reminder

Labels

MethodEndpointDescription
GET/api/labelsList labels
POST/api/labelsCreate label
POST/api/labels/<id>/editUpdate label
POST/api/labels/<id>/deleteDelete label

Reports

MethodEndpointDescription
GET/api/reports/summarySummary report

Settings

MethodEndpointDescription
GET/api/settings/profileGet profile
POST/api/settings/profileUpdate profile
POST/api/settings/timezoneUpdate timezone
POST/api/settings/notificationsUpdate notifications

Data Models

Task

class Task:
    id: int
    title: str
    description: str
    status: str          # "pending", "in_progress", "completed"
    priority: str         # "low", "medium", "high"
    project_id: int
    labels: List[Label]
    created_at: datetime
    updated_at: datetime
    completed_at: Optional[datetime]
    due_date: Optional[date]
    daily_check: bool
    timer_start: Optional[datetime]

Project

class Project:
    id: int
    name: str
    color: str
    user_id: int
    created_at: datetime
    updated_at: datetime

Goal

class Goal:
    id: int
    title: str
    description: str
    target_date: date
    status: str           # "pending", "in_progress", "completed"
    progress: int          # 0-100
    user_id: int
    subgoals: List[SubGoal]
    created_at: datetime
    updated_at: datetime

Habit

class Habit:
    id: int
    name: str
    frequency: str         # "daily", "weekly"
    streak: int
    completed_dates: List[date]
    user_id: int
    created_at: datetime

TimeEntry

class TimeEntry:
    id: int
    task_id: int
    start_time: datetime
    end_time: Optional[datetime]
    duration: int          # seconds
    user_id: int

Code Examples

Creating a Task

curl -X POST http://localhost:5000/api/tasks \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <access_token>" \
  -d '{
    "title": "Implement new feature",
    "description": "Add authentication flow",
    "priority": "high",
    "project_id": 1,
    "due_date": "2026-04-15"
  }'

Response:

{
  "id": 123,
  "title": "Implement new feature",
  "status": "pending",
  "priority": "high",
  "project_id": 1,
  "created_at": "2026-04-06T10:00:00Z"
}

Starting Timer on Task

curl -X POST http://localhost:5000/api/tasks/123/start \
  -H "Authorization: Bearer <access_token>"

Response:

{
  "message": "Timer started",
  "timer_start": "2026-04-06T10:30:00Z"
}

Getting Goals with Subgoals

curl -X GET http://localhost:5000/api/goals/1 \
  -H "Authorization: Bearer <access_token>"

Response:

{
  "id": 1,
  "title": "Launch MVP",
  "description": "Release first version",
  "target_date": "2026-06-01",
  "status": "in_progress",
  "progress": 45,
  "subgoals": [
    {"id": 1, "title": "Setup CI/CD", "completed": true},
    {"id": 2, "title": "Add auth", "completed": true},
    {"id": 3, "title": "Create dashboard", "completed": false}
  ]
}

Creating a Habit

curl -X POST http://localhost:5000/api/habits \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <access_token>" \
  -d '{
    "name": "Morning exercise",
    "frequency": "daily"
  }'

Response:

{
  "id": 1,
  "name": "Morning exercise",
  "frequency": "daily",
  "streak": 0,
  "completed_dates": [],
  "created_at": "2026-04-06T10:00:00Z"
}

Configuration

Environment Variables

VariableDescriptionRequired
DATABASE_URLPostgreSQL connection stringYes
SECRET_KEYFlask secret keyYes
AUTH_JWT_SECRETJWT validation secretYes
AUTH_SERVICE_URLAuth service URLYes
LOG_LEVELLogging level (default: INFO)No

Docker

# Run locally with docker-compose
docker-compose up
 
# Run with custom configuration
docker run -e DATABASE_URL=postgresql://user:pass@host:5432/goalixa \
  -e SECRET_KEY=your-secret \
  goalixa-core-api:latest

Kubernetes Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: core-api
spec:
  replicas: 3
  selector:
    matchLabels:
      app: core-api
  template:
    metadata:
      labels:
        app: core-api
    spec:
      containers:
      - name: core-api
        image: goalixa/core-api:latest
        ports:
        - containerPort: 5000
        env:
        - name: DATABASE_URL
          valueFrom:
            secretKeyRef:
              name: goalixa-secrets
              key: database-url
        - name: SECRET_KEY
          valueFrom:
            secretKeyRef:
              name: goalixa-secrets
              key: secret-key
        - name: AUTH_JWT_SECRET
          valueFrom:
            secretKeyRef:
              name: goalixa-secrets
              key: jwt-secret
        - name: AUTH_SERVICE_URL
          value: http://auth-service:5001
        resources:
          requests:
            memory: "256Mi"
            cpu: "250m"
          limits:
            memory: "512Mi"
            cpu: "500m"
        livenessProbe:
          httpGet:
            path: /health
            port: 5000
          initialDelaySeconds: 30
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /health
            port: 5000
          initialDelaySeconds: 5
          periodSeconds: 5

Metrics

The service exposes Prometheus metrics at /metrics:

MetricTypeDescription
goalixa_requests_totalCounterTotal requests by endpoint
goalixa_request_duration_secondsHistogramRequest duration
goalixa_tasks_createdCounterTasks created
goalixa_timer_startedCounterTimers started
goalixa_goals_completedCounterGoals completed
goalixa_habits_completedCounterHabits completed

Health Checks

curl http://localhost:5000/health

Response:

{
  "status": "healthy",
  "database": "connected",
  "timestamp": "2026-04-06T10:00:00Z"
}