ALX Webstack Portfolio Project

January 24, 2025 View on GitHub Live Demo

Afrikai Microservices System

๐Ÿ“– Project Overview

The Afrikai Microservices System is a modular, scalable, and secure task management platform designed with a microservices architecture. It empowers users to manage tasks with labeling features while ensuring secure authentication and seamless inter-service communication. This system is built with Spring Boot, Spring Cloud, and Netflix Eureka, following industry best practices for distributed systems.

๐ŸŽฏ Core Objectives

  • Scalability: Designed for horizontal scaling to handle increasing workloads.
  • Modularity: Decoupled services for maintainability and independent deployment.
  • Security: Role-Based Access Control (RBAC) with JWT Authentication.
  • Resilience: Fault-tolerant communication through service discovery and gateway routing.

๐Ÿ—๏ธ Project Structure

afrikai_apis/
โ”œโ”€โ”€ api-gateway/           # Centralized API Gateway for routing and security
โ”œโ”€โ”€ docs/                  # Documentation for all microservices
โ”œโ”€โ”€ label-service/         # Microservice for managing labels
โ”œโ”€โ”€ service-registry/      # Eureka-based service discovery
โ”œโ”€โ”€ task-service/          # Microservice for managing tasks
โ”œโ”€โ”€ user-service/          # Handles user management and authentication
โ”œโ”€โ”€ pom.xml                # Parent Maven configuration
โ””โ”€โ”€ README.md              # Project documentation

โš™๏ธ Technology Stack

  • Java 17

  • Spring Boot 3.x

  • Spring Cloud (Eureka, Gateway)

  • Spring Security (JWT Authentication)

  • MySQL (Database for services)

  • Feign Clients for inter-service communication

  • Maven (Build tool)


๐Ÿ”ฅ Core Features

๐Ÿท๏ธ Label Management

Users can create, update, and delete labels to organize tasks.

โœ… Task Management

Users can create tasks, assign labels, and manage task workflows.

๐Ÿ” User Authentication & Authorization

JWT-based authentication

Role-based access control (Client, Admin, Manager)

๐Ÿ”„ Service Discovery

Dynamic service registration and discovery using Netflix Eureka.

๐Ÿšช API Gateway

Central entry point for all services with routing and security handled by the Gateway.


๐Ÿš€ Getting Started

๐Ÿ“ฆ Prerequisites

Java 17

Maven 3.8+

MySQL running locally or in Docker (if you choose to run Docker for MySQL)

Docker (optional for deployment)

๐Ÿ”ง Setup Instructions

Clone the Repository

git clone https://github.com/Nadira3/afrikai_apis.git
cd afrikai_apis

Configure Databases

Ensure MySQL databases are created for each service:

user_service_db

task_service_db

label_service_db

Create these databases and update the connection configurations in application.yml files for each service with the correct username and password.

Update Environment Variables

Each service has its own application.yml or .env file. Configure database credentials and JWT secrets accordingly.

Build the Project

mvn clean install

Run Services Individually

Service Registry

cd service-registry
mvn spring-boot:run

API Gateway

cd api-gateway
mvn spring-boot:run

User Service

cd user-service
mvn spring-boot:run

Task Service

cd task-service
mvn spring-boot:run

Label Service

cd label-service
mvn spring-boot:run

Verify Eureka Dashboard Visit http://localhost:8761 to confirm that all services are registered.


๐Ÿ“ก API Overview

๐Ÿ” Authentication Endpoints (User Service)

โœ… Task Management (Task Service)

๐Ÿท๏ธ Label Management (Label Service)


๐Ÿงช Testing

โœ… Running Tests

Execute unit and integration tests across all services:

mvn test

๐Ÿ“ Sample Test Case (User Authentication)

@Test
void whenValidUser_thenReturnsJwtToken() throws Exception {
    AuthRequest authRequest = new AuthRequest("user@example.com", "password123");
    
    mockMvc.perform(post("/api/auth/login")
            .contentType(MediaType.APPLICATION_JSON)
            .content(objectMapper.writeValueAsString(authRequest)))
        .andExpect(status().isOk())
        .andExpect(jsonPath("$.token").exists());
}

๐ŸŒ Architecture Diagram

proposed design Architectural Design

exexcution flow

graph LR
    A[Service Registry - Eureka] --> B[API Gateway]
    
    %% Microservices
    B --> C[Task Service]
    B --> D[Label Service]
    B --> E[User Service]
    B --> F[Payment Service]
    
    %% Databases
    C --> G[Task Database]
    D --> H[Label Database]
    E --> I[User Database]
    F --> J[Payment Database]
    
    %% Authentication
    B --> K[Authentication and Authorization Service]
    K --> L[JWT Authentication]
    
    %% Wallet System
    E --> M[User Wallet]
    F --> M
    
    %% Monitoring and Health Checks
    B --> N[Monitoring Service]
    N --> O[Health Check]
    N --> P[Metrics]
    
    %% Subgraph Representation
    subgraph Eureka [Service Registry - Eureka]
        A
    end

    subgraph Gateway [API Gateway]
        B
    end

    subgraph Services [Microservices]
        C[Task Service]
        D[Label Service]
        E[User Service]
        F[Payment Service]
    end

    subgraph Databases [Databases]
        G[Task Database]
        H[Label Database]
        I[User Database]
        J[Payment Database]
    end
    
    subgraph Security [Security]
        K[Authentication Service]
        L[JWT Authentication]
    end

    subgraph Monitoring [Monitoring]
        N[Monitoring Service]
        O[Health Check]
        P[Metrics]
    end

Key Workflow:

  1. Service Discovery All microservices register with Eureka Service Registry upon startup.

  2. API Gateway The API Gateway acts as the entry point for all incoming requests, routing them to the appropriate service based on the endpoint. It also handles authentication and authorization.

  3. Communication between Services

Task Service communicates with Label Service and queries the MySQL database for task and label management.

User Service manages authentication, user details, and JWT generation.


๐Ÿค Contribution Guidelines

  1. Fork the repository.

  2. Clone the forked repo.

  3. Create a feature branch (git checkout -b feature/your-feature).

  4. Commit changes (git commit -m "feat: add new feature").

  5. Push to the branch (git push origin feature/your-feature).

  6. Submit a Pull Request.


๐Ÿ“„ License

Distributed under the ALX Backend Curriculum License.