---
# System prepended metadata

title: Payroll Documentation
tags: [handover]

---

# Payroll Documentation
###### tags: `handover`

## Solution Hierarchy
![](https://i.imgur.com/rr7U9Ti.png)

## Setup Guide & Local Deployment

### Source Code
1. Make sure you have access to `https://github.com/FlairstechProductUnit/Payroll` first.
2. Perform a `git clone` operation where you need to run locally after you've logged in into the Git Client:
```git
git clone https://github.com/FlairstechProductUnit/Payroll.git
```
3. Perform a clean **Rebuild**, you should now be getting some errors.
4. Now we need to setup a new Nuget Package Source, open "Manage Packages for Solution" page.
5. ![](https://i.imgur.com/XHxNyey.png)
6. Click tha Add Button 
![](https://i.imgur.com/g7Up3QY.png)
7. Choose a suitable name, say: FlairsIdentityShared
8. Choose a suitable build location, say: `D:/Publish/FlairsIdentityShared`
9. Open Flairs Identity Solution
10. Right click the Shared Project, then publish it to the same location `D:/Publish/FlairsIdentityShared`
7. Click Add once more
8. Choose a suitable name, say: SSAShared
9. Choose a suitable build location, say: `D:/Publish/SSAShared`
10. Open Self Services Solution
11. Right click the Shared Project, then publish it to the same location `D:/Publish/SSAShared`
12. Try to perform another rebuild, and all errors should be gone by now

### Authentication and Authorization
- By default, authentication is turned off for the **Development Environment** for smoother development experience. If you ran the solution using the `Payroll-Staging` profile, authentication would be turned on again (normal behaviour).
- To dynamically inject an existing user as the currently logged in user while debugging, add a **Break Point** on the **`testAccount`** variable on the `UserDetailsMiddleware`, and provide a **valid Organization Email**
**OR**
Edit the `"TestAccountEmail": ""` element in `appsettings.json`
- To override this behaviour while in development mode, remove these blocks
```csharp
// Startup.cs
public void Configure(•••)
{
    app.UseEndpoints(endpoints =>
    {
        •••
        if (env.IsDevelopment())
            endpoints.MapControllers().WithMetadata(new AllowAnonymousAttribute());
        •••
    });
}
```
```csharp
// UserDetailsMiddleware.cs
public void InvokeAsync(•••)
{
    •••
    if (!isAuthenticated && environment.IsDevelopment())
    {
        var testAccount = await profileRepository.GetByOrganizationEmail(appSettingsOptions.Value.TestAccountEmail);
        userDetailsProvider.Initialize(testAccount, string.Empty);
        await _next(context);
        return;
    }
    •••
}
```
### JWT Token Generation
1. Make sure you have access to `https://github.com/FlairstechProductUnit/SelfServices` first.
2. Pull down the latest Master branch for the FlairsIdentity solution
```git
git clone https://github.com/FlairstechProductUnit/IdentityServer.git
```
3. Perform a clean **Rebuild**
4. Publish the applet called "TestClient"
5. Use it for token generation for a specific account.

### Kafka Brokers
To be able to run locally without consuming the staging server's own Kafka Brokers, you need to run other set of brokers on your local machine, the best method is by using **Docker (`docker-compose`)**.

1. Save this file somewhere safe with the name: `docker-compose.yml`
```yaml
version: '2'

services:
  zookeeper:
    image: 'docker.io/bitnami/zookeeper:3-debian-10'
    ports:
      - '2181:2181'
    volumes:
      - 'zookeeper_data:/bitnami'
    environment:
      - ALLOW_ANONYMOUS_LOGIN=yes
  kafka:
    image: 'docker.io/bitnami/kafka:2-debian-10'
    ports:
      - '9092:9092'
    volumes:
      - 'kafka_data:/bitnami'
    environment:
      - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
      - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092
      - ALLOW_PLAINTEXT_LISTENER=yes
    depends_on:
      - zookeeper

volumes:
  zookeeper_data:
    driver: local
  kafka_data:
    driver: local
```
2. Make sure you have Docker running, open up a new terminal instance where you've saved the previous file, and run:
```dockerfile
docker-compose up
```

