# ilyayushchuk/forestlike architecture

> Architecture diagram of the GitHub repository ilyayushchuk/forestlike, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ilyayushchuk/forestlike
- Repository: https://github.com/ilyayushchuk/forestlike

## Overview

##### Project Type and Purpose
- ForestLike is a full-stack productivity application composed of:
- A client (ForestLike project) that runs timers, monitors activity, and displays UI.
- A server (Server project) that exposes storage and business endpoints.
- A serializer library (Serializer project) for converting domain entities to/from JSON or binary.
- The app’s core functions are timer management (solo and cooperative), activity observation, user authentication, rating/statistics, and local/remote persistence.

##### File Structure
- Top-level solution “ForestLike.sln” contains multiple projects:
- ForestLike (client/presentation + business logic)
- Server (API + data access)
- Serializer (shared serialization library)
- LR_3 (sample or legacy console project, can be ignored in microservice design)
- ForestLike/Services and ForestLike/ClientServerLogic hint at client-side API calls.
- Server/DBServices implements IStorageController with two adapters (local vs. remote).
- Serializer/Entities define DTOs: User, Record, CooperativeRecord.

##### README Insights
- Three layers are already defined: Presentation, Business-Logic, DataAccess.
- DataAccess uses a strategy pattern (IStorageController → DBController or LocalStorageController).
- Business-Logic manages User, Timer, CooperativeTimer, ActivityObserver, Statistic, Record entities.

##### Decompose into Microservices
a. API Gateway
- Single entry point for the client. Routes calls to downstream microservices.
- Handles SSL termination, authentication token validation, load balancing.
b. Auth Service
- Manages user registration, login, logout, password changes.
- Exposes endpoints: /auth/register, /auth/login, /auth/logout, /auth/me.
- Owns User data store and issues JWTs.
c. Timer Service
- Manages solo timers and cooperative timers.
- Exposes endpoints: /timers/start, /timers/stop, /timers/status.
- Publishes events (TimerStarted, TimerStopped, TimerFailed) to a message bus.
d. Cooperative Session Service
- Coordinates two-user sessions.
- Listens for Timer service events, enforces “both must succeed” rule.
- Exposes endpoints: /cooperative/join, /cooperative/leave.
e. Statistics Service
- Consumes events from message bus, aggregates stats (favorite themes, average time, leaderboards).
- Exposes endpoints: /stats/user/{id}, /stats/global.
f. Storage Service (DataStore)
- Central service (or multiple data stores) for persisting Users, Records, CooperativeRecords.
- Could be implemented as separate database microservices:
- User DB (SQL)
- Records DB (NoSQL or SQL)
- Alternatively, each microservice owns its own datastore.
g. Serializer Service (optional)
- Shared library rather than microservice—packaged as NuGet. Used by all services.

##### Relationships & Data Flow
- Client (ForestLike desktop/mobile app) → API Gateway → respective microservice.
- Auth Service returns JWT → Client attaches to Timer/Cooperative/Stats requests.
- Timer Service emits events to Message Bus (e.g., RabbitMQ, Kafka).
- Cooperative Service & Statistics Service subscribe to events.
- Each service reads/writes its own database.
- Serializer library is shared across services for consistent DTO formats.

##### Architectural Patterns & Technologies
- Patterns:
- API Gateway (routing, auth)
- Backend-for-Frontend (client-specific orchestration)
- Event-driven (Timer → Message Bus → Stats/Coop)
- Database per Service (bounded contexts)
- Technologies:
- .NET 8 / ASP.NET Core WebAPI for microservices
- JWT for authentication
- gRPC or HTTP REST (JSON) for inter-service calls
- RabbitMQ / Kafka for event bus
- SQL Server or SQLite (local fallback)
- Docker & Kubernetes for deployment

- Clear labels for each component (API Gateway, Auth Service, etc.).
- Notes on technology (e.g., .NET 8, RabbitMQ).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client["Client Application"]:::client
    click Client "https://github.com/ilyayushchuk/forestlike/tree/main/ForestLike/"

    %% API Gateway
    APIGateway["API Gateway\n(HTTPS)"]:::gateway

    %% Microservices
    AuthService["Auth Service\n.NET 8 WebAPI"]:::service
    TimerService["Timer Service\n.NET 8 WebAPI"]:::service
    CoopService["Cooperative Session Service\n.NET 8 WebAPI"]:::service
    StatsService["Statistics Service\n.NET 8 WebAPI"]:::service

    %% Message Bus
    MessageBus(("Message Bus\n(AMQP)")):::bus

    %% Databases
    AuthDB[(Auth DB\nSQL)]:::db
    TimerDB[(Timer DB\nSQL)]:::db
    CoopDB[(Coop DB\nSQL)]:::db
    StatsDB[(Stats DB\nNoSQL)]:::db

    %% Serializer Library
    SerializerLib["Serializer Library\n(shared NuGet)"]:::library
    click SerializerLib "https://github.com/ilyayushchuk/forestlike/tree/main/Serializer/Serializer/"

    %% Client to Gateway
    Client -->|HTTPS| APIGateway

    %% Gateway to Services
    APIGateway -->|HTTPS| AuthService
    APIGateway -->|HTTPS| TimerService
    APIGateway -->|HTTPS| CoopService
    APIGateway -->|HTTPS| StatsService

    %% Services to their DBs
    AuthService -->|SQL| AuthDB
    TimerService -->|SQL| TimerDB
    CoopService -->|SQL| CoopDB
    StatsService -->|NoSQL| StatsDB

    %% Event Flow
    TimerService -->|TimerStarted/Stopped| MessageBus
    MessageBus -->|subscribe| CoopService
    MessageBus -->|subscribe| StatsService

    %% Serializer usage
    AuthService -.-> SerializerLib
    TimerService -.-> SerializerLib
    CoopService -.-> SerializerLib
    StatsService -.-> SerializerLib

    %% Styles
    classDef client fill:#cccccc,stroke:#333,stroke-width:1px;
    classDef gateway fill:#add8e6,stroke:#333,stroke-width:1px;
    classDef service fill:#90ee90,stroke:#333,stroke-width:1px;
    classDef db fill:#ffa500,stroke:#333,stroke-width:1px;
    classDef bus fill:#dda0dd,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5;
    classDef library fill:#f0e68c,stroke:#333,stroke-width:1px;
```
