Skip to content

Commit a2e2cf0

Browse files
authored
Merge pull request #35 from undp/develop
Develop
2 parents aed63df + ea98193 commit a2e2cf0

132 files changed

Lines changed: 9748 additions & 3440 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/frontend-deployment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
deploy_front_end:
1212
runs-on: ubuntu-latest
1313
env:
14-
REACT_APP_BACKEND: https://ck5kt5uaw1.execute-api.us-east-1.amazonaws.com/dev/api
14+
REACT_APP_BACKEND: https://api.carbreg.org
1515
COUNTRY_NAME: 'Antarctic Region'
1616
COUNTRY_FLAG_URL: 'https://carbon-common-dev.s3.amazonaws.com/flag.png'
1717
COUNTRY_CODE: 'NG'

README.md

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# Carbon Registry
1717
The National Carbon Registry enables carbon credit trading in order to reduce greenhouse gas emissions.
1818

19-
As an online database, the National Carbon Registry uses standards national and international standards for quantifying and verifying greenhouse gas emissions reductions of programmes, tracking issued carbon credits and enabling credit transfers in an efficient and transparent manner. The Registry functions by receiving, processing, recording and storing data on mitigations projects, the issuance, holding, transfer, acquisition, cancellation, and retirement of emission reduction credits. This information is publicly accessible to increase public confidence in the emissions reduction agenda.
19+
As an online database, the National Carbon Registry uses national and international standards for quantifying and verifying greenhouse gas emissions reductions by programmes, tracking issued carbon credits and enabling credit transfers in an efficient and transparent manner. The Registry functions by receiving, processing, recording and storing data on mitigations projects, the issuance, holding, transfer, acquisition, cancellation, and retirement of emission reduction credits. This information is publicly accessible to increase public confidence in the emissions reduction agenda.
2020

2121
The National Carbon Registry enables carbon credit tracking transactions from mitigation activities, as the digital implementation of the Paris Agreement. Any country can customize and deploy a local version of the registry then connect it to other national & international registries, MRV systems, and more.
2222

@@ -34,8 +34,83 @@ https://digitalprinciples.org/
3434

3535
<a name="architecture"></a>
3636
## System Architecture
37-
UNDP Carbon Registry based on Serverless Architecture. It can be ported and hosted on any Function As A Service (FaaS) stack.
38-
![alt text](./documention/imgs/System%20Architecture.png)
37+
UNDP Carbon Registry is based on service oriented architecture (SOA). It can be ported and hosted on any Function As A Service (FaaS) stack.
38+
![alt text](./documention/imgs/System%20Architecture.svg)
39+
40+
As per the above diagram, system contains 4 main services.
41+
42+
<a name="services"></a>
43+
### **Services**
44+
#### *National Service*
45+
46+
Authenticate, Validate and Accept user (Government, Programme Developer/Certifier) API requests related to the following functionalities,
47+
- User and company CRUD operations.
48+
- User authentication.
49+
- Programme life cycle management.
50+
- Credit life cycle management.
51+
52+
Service is horizontally scalable and state maintained in the following locations,
53+
- File storage.
54+
- Operational Database.
55+
- Ledger Database.
56+
57+
Uses the Carbon Credit Calculator and Serial Number Generator node modules to estimate the programme carbon credit amount and issue a serial number.
58+
Uses Ledger interface to persist programme and credit life cycles.
59+
60+
#### *Analytics Service*
61+
Serve all the system analytics. Generate all the statistic using the operational database.
62+
Horizontally scalable.
63+
64+
#### *Replicator Service*
65+
Replicate ledger database new items to a operational database asynchronously. During the replication process it injects additional query information to the data.
66+
The current setup uses AWS QLDB as the ledger database. When it creates or updates data, the change is added to a AWS Kinesis Data Stream and the Replicator service consumes the stream.
67+
68+
#### *Operational Service*
69+
Service that use to do following system operations,
70+
1. Data migrations.
71+
2. User data creation and update.
72+
3. Resource creation.
73+
74+
Internal service. Cannot be invoked by external sources.
75+
76+
### **Database Architecture**
77+
Primary/secondary database architecture used to store carbon programme and account balances.
78+
Ledger database is the primary database. Add/update programmes and update account balances in a single transaction. Currently implemented only for AWS QLDB
79+
80+
Operational Database is the secondary database. Eventually replicated to this from primary database via data stream. Implemented based on PostgresSQL
81+
82+
**Why Two Database Approach?**
83+
1. Cost and Query capabilities - Ledger database (blockchain) read capabilities can be limited and costly. To support rich statistics and minimize the cost, data is replicated in to a cheap query database.
84+
2. Disaster recovery
85+
3. Scalability - Primary/secondary database architecture is scalable since additional secondary databases can be added as needed to handle more read operations.
86+
87+
**Why Ledger Database?**
88+
1. Immutable and Transparent - Track and maintain a sequenced history of every carbon programme and credit change.
89+
2. Data Integrity (Cryptographic verification by third party).
90+
3. Reconcile carbon credits and company account balance.
91+
92+
**Ledger Database Interface**
93+
94+
This enables the capability to add any blockchain or ledger database support to the carbon registry without functionality module changes. Currently the production system interface is implemented for AWS QLDB. For testing purposes the interface is implemented for PostgresSQL as well.
95+
96+
97+
98+
Single database approach used for user and company management.
99+
100+
101+
### **Ledger Layout**
102+
Carbon Registry contains 3 ledger tables.
103+
1. Programme ledger - Contains all the programme and credit transactions.
104+
2. Company Account Ledger (Credit) - Contains company accounts credit transactions.
105+
3. Country Account Ledger (Credit) - Contains country credit transactions.
106+
107+
The below diagram demonstrates the the ledger behavior of programme create, authorise, issue and transfer processes. Blue color document icon denotes a single data block in a ledger.
108+
109+
![alt text](./documention/imgs/Ledger.png)
110+
111+
### **Authentication**
112+
- JWT Authentication - All endpoints based on role permissions.
113+
- API Key Authentication - MRV System connectivity.
39114

40115
<a name="structure"></a>
41116
## Project Structure
@@ -63,7 +138,7 @@ UNDP Carbon Registry based on Serverless Architecture. It can be ported and host
63138
<a name="local"></a>
64139
## Run Services Locally
65140
- Setup postgreSQL locally and create a new database.
66-
- Update following DB configurations in the .env.local file (If file does not exist please create a new .env.local)
141+
- Update following DB configurations in the .env.local file (If the file does not exist please create a new .env.local)
67142
- DB_HOST (Default localhost)
68143
- DB_PORT (Default 5432)
69144
- DB_USER (Default root)
@@ -73,7 +148,7 @@ UNDP Carbon Registry based on Serverless Architecture. It can be ported and host
73148
- Run `yarn run sls:install `
74149
- Initial user data setup `serverless invoke local --stage=local --function setup --data '{"rootEmail": "<Root user email>","systemCountryCode": "<System country Alpha 2 code>", "name": "<System country name>", "logoBase64": "<System country logo base64>"}'`
75150
- Start all the services by executing `sls offline --stage=local`
76-
- Now all the system services are up and running. Swagger documentation will be available on `http://localhost:3000/local/api/national/docs#/`
151+
- Now all the system services are up and running. Swagger documentation will be available on `http://localhost:3000/local/national`
77152

78153
<a name="cloud"></a>
79154
## Deploy System on the AWS Cloud
@@ -108,7 +183,7 @@ Serial Number generation implemented in a separate node module. [Please refer th
108183
## User Onboarding and Permissions Model
109184
110185
### User Roles
111-
System pre-defined user roles as follows,
186+
System pre-defined user roles are as follows,
112187
- Root
113188
- Company Level (National Government, Programme and Certification Company come under this level)
114189
- Admin
@@ -125,7 +200,7 @@ System pre-defined user roles as follows,
125200
126201
### User Management
127202
128-
All the CRUD operations can perform as per the following table,
203+
All the CRUD operations can be performed as per the following table,
129204
130205
| Company Role | New User Role | Authorized User Roles (Company) |
131206
| --- | --- | --- |

documention/Carbon Registry Architecture.drawio

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

documention/imgs/Ledger.png

47.1 KB
Loading

documention/imgs/Ledger.svg

Lines changed: 0 additions & 3 deletions
This file was deleted.
182 KB
Loading

documention/imgs/System Architecture.svg

Lines changed: 225 additions & 4 deletions
Loading

lambda/services/.env.dev

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ DB_USER=root
55
DB_PASSWORD=abcd1234
66
DB_NAME=carbondbdev
77
LOG_LEVEL=debug
8-
carbon_dev_common=carbon-www-common
8+
carbon_dev_common=carbon-www-common
9+
SOURCE_EMAIL=nce.digital@undp.org

lambda/services/serverless.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ functions:
4242
events:
4343
- http:
4444
method: any
45-
path: /api/national/{any+}
45+
path: /national/{any+}
46+
- http:
47+
method: any
48+
path: /national
4649
ssmToEnvironment:
4750
- DB_PASSWORD
4851
- USER_JWT_SECRET
@@ -60,7 +63,10 @@ functions:
6063
events:
6164
- http:
6265
method: any
63-
path: /api/stats/{any+}
66+
path: /stats/{any+}
67+
- http:
68+
method: any
69+
path: /stats
6470
ssmToEnvironment:
6571
- DB_PASSWORD
6672
- USER_JWT_SECRET

0 commit comments

Comments
 (0)