/Fokuso-API

Django REST API backend for Fokuso productivity platform. Features spaced repetition system, focus session tracking, task management, and comprehensive analytics.

Primary LanguagePythonMIT LicenseMIT

Fokuso API

Django Django REST Framework PostgreSQL Docker

Fokuso Logo

๐Ÿ”— Frontend Repository

โœจ Features โ€ข ๐Ÿš€ Quick Start โ€ข ๐Ÿ› ๏ธ Tech Stack โ€ข ๐Ÿ“ Project Structure โ€ข ๐Ÿค Contributing


๐Ÿ“– About

Fokuso API is the robust Django REST backend that powers the Fokuso productivity platform. Built with modern development practices, it provides a comprehensive suite of APIs for focus management, spaced repetition learning, task organization, and productivity analytics.

The API implements Test Driven Development (TDD) principles and includes comprehensive documentation via Swagger UI, making it easy for developers to integrate and extend the platform's capabilities.


โœจ Features

๐Ÿ” Authentication & User Management

  • Token-based Authentication: Secure user sessions with tokens
  • User Registration & Login: Complete auth flow
  • Profile Management: User data management

๐Ÿง  Spaced Repetition System

  • Flashcard Management: CRUD operations for learning cards
  • Deck Organization: Subject-based card grouping
  • SM-2 Algorithm: Scientifically-proven spaced repetition
  • Review Statistics: Comprehensive learning analytics
  • Daily Progress Tracking: Monitor learning consistency

๐Ÿ… Focus Session Management

  • Session Logging: Track focus and break periods
  • Duration Recording: Precise time measurement
  • Statistics Generation: Productivity insights and trends
  • Streak Calculation: Consistency tracking

โœ… Task Management

  • Todo CRUD Operations: Complete task management
  • Priority Levels: High, medium, low prioritization
  • Category System: Work, personal, health, education, etc.
  • Tag Management: Flexible organization system
  • Due Date Tracking: Deadline management

๐Ÿ“… Calendar System

  • Event Management: Create, update, delete events
  • Event Types: Focus, study, meeting, break, other
  • Time Tracking: Start/end time with duration calculation
  • Date Filtering: Efficient event querying
  • Grouped Responses: Events organized by date

๐Ÿ“Š Analytics & Statistics

  • Daily Review Stats: Flashcard performance tracking
  • Focus Statistics: Session analytics and trends
  • Progress Metrics: Comprehensive productivity insights
  • Historical Data: Long-term trend analysis

๐Ÿš€ Quick Start

Prerequisites

Before you begin, ensure you have the following installed:

  • Docker and Docker Compose
  • Git

Installation

  1. Clone the repository

    git clone https://github.com/lowskydev/Fokuso-API.git
    cd Fokuso-API
  2. Start the services

    docker compose up
  3. Access the application

  4. Setup the Fokuso Frontend

    Follow the instructions in the Frontend Repository to set up the frontend application.

Important Commands

Development Commands

# Start services
docker compose up

# Start services in background
docker compose up -d

# Stop services
docker compose down

Application Management

# Run tests
docker compose run --rm app sh -c "python manage.py test"

# Create superuser
docker compose run --rm app sh -c "python manage.py createsuperuser"

# Apply migrations
docker compose run --rm app sh -c "python manage.py migrate"

# Code linting
docker compose run --rm app sh -c "flake8"

# Access Django shell
docker compose run --rm app sh -c "python manage.py shell"

# Create new migrations
docker compose run --rm app sh -c "python manage.py makemigrations"

Database Management

# Reset database (careful - this deletes all fokuso data)
docker compose down
docker volume rm fokuso-api_dev-db-data
docker compose up

# Backup database
docker compose exec db pg_dump -U devuser devdb > backup.sql

# Restore database
docker compose exec -T db psql -U devuser devdb < backup.sql

๐Ÿ› ๏ธ Tech Stack

Backend Framework

  • ๐Ÿ Django 3.2 - Robust web framework
  • ๐Ÿ”ฅ Django REST Framework 3.12 - Powerful API toolkit
  • ๐Ÿ“š drf-spectacular - OpenAPI 3 schema generation

Database

  • ๐Ÿ˜ PostgreSQL 13 - Advanced relational database
  • ๐Ÿ”ง psycopg2 - PostgreSQL adapter for Python

Development & Deployment

  • ๐Ÿณ Docker & Docker Compose - Containerization
  • ๐Ÿ” flake8 - Code linting and style checking
  • ๐Ÿงช Django Test Framework - Comprehensive testing suite

API Features

  • ๐Ÿ” Token Authentication - Secure API access
  • ๐Ÿ“– Swagger UI Documentation - Interactive API docs
  • ๐ŸŒ CORS Headers - Cross-origin resource sharing
  • ๐Ÿ“Š Pagination - Efficient data loading
  • ๐Ÿ” Filtering & Search - Advanced query capabilities

๐Ÿ“ Project Structure

app/
โ”œโ”€โ”€ ๐Ÿ“ app/                       # Main application configuration
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ settings.py            # Django settings
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ urls.py                # URL routing
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ calc.py                # Utility functions
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ core/                      # Core application models
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ models.py              # Database models
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ admin.py               # Admin interface
โ”‚   โ””โ”€โ”€ ๐Ÿ“ management/            # Custom management commands
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ user/                      # User authentication
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ views.py               # Auth views
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ serializers.py         # User serializers
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ urls.py                # User URLs
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ flashcards/                # Spaced repetition system
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ views.py               # Flashcard views
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ serializers.py         # Card serializers
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ sm2.py                 # SM-2 algorithm
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ urls.py                # Flashcard URLs
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ calendars/                 # Calendar management
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ views.py               # Calendar views
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ serializers.py         # Event serializers
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ urls.py                # Calendar URLs
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ todos/                     # Task management
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ views.py               # Todo views
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ serializers.py         # Task serializers
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ urls.py                # Todo URLs
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ stats/                     # Analytics system
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ views.py               # Statistics views
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ serializers.py         # Stats serializers
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ urls.py                # Stats URLs
โ”‚
โ””โ”€โ”€ ๐Ÿ“ notes/                     # Note management
    โ”œโ”€โ”€ ๐Ÿ“„ views.py               # Notes views
    โ”œโ”€โ”€ ๐Ÿ“„ serializers.py         # Note serializers
    โ””โ”€โ”€ ๐Ÿ“„ urls.py                # Notes URLs

Key Architecture Decisions

  • Modular App Structure: Features separated into Django apps
  • RESTful API Design: Consistent REST principles
  • Token Authentication: Stateless authentication system
  • Test-Driven Development: Comprehensive test coverage
  • Docker Containerization: Consistent development environment

๐Ÿ”ง API Endpoints

Authentication

POST   /api/user/create/                   # User registration
POST   /api/user/token/                    # Login & token generation
GET    /api/user/me/                       # User profile
PATCH  /api/user/me/                       # Update profile

Flashcards

GET    /api/flashcards/                    # List flashcards
POST   /api/flashcards/                    # Create flashcard
GET    /api/flashcards/{id}/               # Get flashcard
PATCH  /api/flashcards/{id}/               # Update flashcard
DELETE /api/flashcards/{id}/               # Delete flashcard
POST   /api/flashcards/{id}/review/        # Review flashcard

GET    /api/flashcards/decks/              # List decks
POST   /api/flashcards/decks/              # Create deck

Calendar

GET    /api/calendars/events/              # List events
POST   /api/calendars/events/              # Create event
GET    /api/calendars/events/{id}/         # Get event
PATCH  /api/calendars/events/{id}/         # Update event
DELETE /api/calendars/events/{id}/         # Delete event

GET    /api/calendars/events/grouped/      # Events grouped by date
GET    /api/calendars/events/today/        # Today's events

Todos

GET    /api/todos/                         # List todos
POST   /api/todos/                         # Create todo
GET    /api/todos/{id}/                    # Get todo
PATCH  /api/todos/{id}/                    # Update todo
DELETE /api/todos/{id}/                    # Delete todo

GET    /api/todos/tags/                    # List tags
POST   /api/todos/tags/                    # Create tag

Statistics

POST   /api/stats/session/                 # Log focus session
GET    /api/stats/sessions/                # List sessions
GET    /api/stats/user-stats/              # User statistics
GET    /api/stats/weekly-data/             # Weekly analytics
GET    /api/stats/hourly-data/             # Hourly analytics

๐Ÿงช Testing

Fokuso API follows Test-Driven Development principles with comprehensive test coverage:

# Run all tests
docker compose run --rm app sh -c "python manage.py test"

# Run specific app tests
docker compose run --rm app sh -c "python manage.py test flashcards"

# Run specific test class
docker compose run --rm app sh -c "python manage.py test flashcards.tests.test_flashcards_api"

Test Structure

  • Unit Tests: Model and utility function testing
  • API Tests: Comprehensive endpoint testing
  • Integration Tests: Feature workflow testing
  • Authentication Tests: Security validation

๐Ÿค Contributing

How to Contribute

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Write tests for your new feature
  4. Implement your feature following TDD principles
  5. Run the test suite to ensure everything passes
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

Development Guidelines

  • Follow Django best practices and PEP 8 style guide
  • Write comprehensive tests for all new features
  • Update API documentation for new endpoints
  • Use meaningful commit messages
  • Ensure all tests pass before submitting PR

๐Ÿ‘ฅ Contributors

lowskydev
lowskydev
๐Ÿš€ Project Leader & Full-Stack Developer
lyes0000
lyes0000
โšก Backend Developer

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ™ Acknowledgments

  • Django Software Foundation for the excellent web framework
  • Django REST Framework for powerful API tools
  • PostgreSQL for reliable database technology
  • Docker for consistent development environments

Made with โค๏ธ by the Fokuso team

โฌ† Back to top