Skip to content

Commit 0d76a4e

Browse files
wilwadep5150jmattheworris
authored
Initial Documentation Content (#346)
This is the first pile of the documentation content. - Anything not for this PR is tagged with "Coming soon" - Lots of design to come - Currently pulls in the swagger via https://www.npmjs.com/package/openapi-to-md (could be changed and improved in the future) # Testing ``` cd docs mdbook serve open http://localhost:3000 ``` Closes Docs issues: - Closes #205 - Closes #204 - Closes #210 Closes embed issues: - Closes #225 - Closes #226 - Closes #227 - Closes #228 --------- Co-authored-by: Patrick <[email protected]> Co-authored-by: Matthew Orris <[email protected]>
1 parent e679cb8 commit 0d76a4e

Some content is hidden

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

55 files changed

+1179
-117
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
docs/book
22

3+
*drawio.bkp
4+
35
# Logs
46
logs
57
*.log

README.md

+2-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
# 📖 Gateway Services <a name="about-project"></a>
2424

25-
Gateway is a collection of services that helps make interacting with Frequency easy as working with any web2 API!
25+
Gateway is a collection of services that helps make interacting with Frequency as easy as working with any web2 API!
2626

2727
<!-- Mermaid Arch maps -->
2828

@@ -40,7 +40,6 @@ flowchart LR;
4040
GS[Graph Service]
4141
CPS[Content Publishing Service]
4242
CWS[Content Watcher Service]
43-
RS[Graph Reconnection Service]
4443
end
4544
S --> AS
4645
S --> GS
@@ -61,7 +60,7 @@ flowchart LR;
6160

6261
## 🛠 Built With
6362

64-
Each Gateway services is an independent microservice.
63+
Each Gateway service is an independent microservice.
6564

6665
### Tech Stack
6766

@@ -97,14 +96,6 @@ Each Gateway services is an independent microservice.
9796

9897
</details>
9998

100-
<details>
101-
<summary>Reconnection Service</summary>
102-
103-
- [API Documentation](https://projectlibertylabs.github.io/reconnection-service/)
104-
- [GitHub](https://github.com/ProjectLibertyLabs/reconnection-service)
105-
106-
</details>
107-
10899
<!-- LIVE Docs -->
109100

110101
## 🚀 Live Docs

docs/book.toml

+14
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,17 @@ language = "en"
44
multilingual = false
55
src = "src"
66
title = "Gateway"
7+
8+
[preprocessor.local]
9+
command = "node preprocessor.mjs"
10+
11+
12+
[output.html]
13+
no-section-label = true
14+
git-repository-url = "https://github.com/ProjectLibertyLabs/gateway"
15+
edit-url-template = "https://github.com/ProjectLibertyLabs/gateway/blob/main/docs/src/{path}"
16+
preferred-dark-theme = "coal"
17+
additional-css = ["css/extended.css"]
18+
19+
[output.html.fold]
20+
enable = true

docs/css/extended.css

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* Button Links */
2+
.button-links {
3+
display: flex;
4+
justify-content: space-around;
5+
align-content: center;
6+
align-items: stretch;
7+
flex-wrap: wrap;
8+
}
9+
10+
.button-links a,
11+
.button-links a:link {
12+
box-sizing: content-box;
13+
font-weight: 300;
14+
color: var(--sidebar-fg);
15+
background-color: var(--sidebar-bg);
16+
border: 2px solid transparent;
17+
border-radius: 15px;
18+
user-select: none;
19+
padding: 20px 10%;
20+
margin: 10px;
21+
display: flex;
22+
font-size: 2rem;
23+
font-weight: 400;
24+
flex: 0.5;
25+
transition-property: border, color;
26+
transition-duration: 0.5s;
27+
justify-content: center;
28+
align-items: center;
29+
text-align: center;
30+
white-space: nowrap;
31+
}
32+
33+
@media screen and (max-width: 1080px) {
34+
.button-links a,
35+
.button-links a:link {
36+
box-sizing: border-box;
37+
margin: 10px 6px;
38+
flex: 0 0 90%;
39+
width: 100%;
40+
white-space: normal;
41+
}
42+
}
43+
44+
@media screen and (max-width: 400px) {
45+
.button-links a,
46+
.button-links a:link {
47+
box-sizing: border-box;
48+
margin: 10px 6px;
49+
flex: 0 0 100%;
50+
width: 100%;
51+
white-space: normal;
52+
}
53+
}
54+
55+
.button-links a:hover,
56+
.button-links a:visited:hover {
57+
text-decoration: none;
58+
border: 2px solid var(--sidebar-active);
59+
color: var(--sidebar-fg);
60+
}

docs/preprocessor.mjs

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Debugging Help
2+
// Use console.error, not console.log
3+
//
4+
// This does a few things:
5+
// - Runs openapi-to-md when `{{#swagger-embed ../services/account/swagger.json}}` or other is found
6+
// - Replaces `{{#button-links}}` with the child links of that page in button form
7+
// - Replaces `{{#markdown-embed ../services/account/ENVIRONMENT.md [trim from top]}}` or other is found with the contents of that file
8+
9+
import { execSync } from 'node:child_process';
10+
import { readFileSync } from 'node:fs';
11+
12+
function runNpxCommand(script, args) {
13+
try {
14+
const command = `npx -y ${script} -- ${args.map((x) => `"${x}"`).join(' ')}`;
15+
const output = execSync(command, { encoding: 'utf-8' });
16+
return output;
17+
} catch (error) {
18+
throw new Error(`Error executing npx command: ${error}`);
19+
}
20+
}
21+
22+
function makeButtonLink({ Chapter }, parentPath) {
23+
// Remove any part of the path that the parent already has.
24+
// This assumes that there are no nested duplicate names
25+
const path = Chapter.path.split('/').filter((x) => !parentPath.has(x));
26+
return `<a href="${path.join('/').replace('.md', '.html')}">${Chapter.name}</a>`;
27+
}
28+
29+
function generateButtonLinks(parent) {
30+
// Remove the last /page.md as there might be collisions with that part
31+
const parentPath = new Set(parent.path.replace(/\/[^\/]*$/, '').split('/'));
32+
return (
33+
'<div class="button-links">' + parent.sub_items.map((x) => makeButtonLink(x, parentPath)).join('\n') + '</div>'
34+
);
35+
}
36+
function replaceButtonLinks(chapter) {
37+
if (chapter.sub_items && chapter.content.includes('{{#button-links}}')) {
38+
chapter.content = chapter.content.replace('{{#button-links}}', generateButtonLinks(chapter));
39+
}
40+
41+
if (chapter.sub_items) {
42+
chapter.sub_items.forEach((section) => {
43+
section.Chapter && replaceButtonLinks(section.Chapter);
44+
});
45+
}
46+
}
47+
48+
function swaggerEmbed(chapter) {
49+
const regex = /{{#swagger-embed\s(.+?)}}/;
50+
const match = chapter.content.match(regex);
51+
if (match) {
52+
const swaggerFile = match[1];
53+
const output = runNpxCommand('openapi-to-md', [swaggerFile]);
54+
const replaceWith = output.split('\n').slice(5).join('\n');
55+
chapter.content = chapter.content.replace(match[0], replaceWith);
56+
}
57+
if (chapter.sub_items) {
58+
chapter.sub_items.forEach((section) => {
59+
section.Chapter && swaggerEmbed(section.Chapter);
60+
});
61+
}
62+
}
63+
64+
function markdownEmbed(chapter) {
65+
const regex = /{{#markdown-embed\s(.+?)\s(.+?)}}/;
66+
const match = chapter.content.match(regex);
67+
if (match) {
68+
const markdownFile = match[1];
69+
const output = readFileSync(markdownFile, 'utf8');
70+
const replaceWith = output.split('\n').slice(match[2]).join('\n');
71+
chapter.content = chapter.content.replace(match[0], replaceWith);
72+
}
73+
if (chapter.sub_items) {
74+
chapter.sub_items.forEach((section) => {
75+
section.Chapter && markdownEmbed(section.Chapter);
76+
});
77+
}
78+
}
79+
80+
// Function to perform the preprocessing
81+
function preprocessMdBook([_context, book]) {
82+
// Button Links
83+
book.sections.forEach((section) => {
84+
section.Chapter && replaceButtonLinks(section.Chapter);
85+
});
86+
87+
// Swagger Embed
88+
book.sections.forEach((section) => {
89+
section.Chapter && swaggerEmbed(section.Chapter);
90+
});
91+
92+
// Markdown Embed
93+
book.sections.forEach((section) => {
94+
section.Chapter && markdownEmbed(section.Chapter);
95+
});
96+
97+
// Output the processed content in mdbook preprocessor format
98+
process.stdout.write(JSON.stringify(book));
99+
}
100+
101+
if (process.argv < 3) {
102+
throw new Error('Something strange is happening');
103+
}
104+
105+
if (process.argv[2] === 'supports') {
106+
process.exit(0);
107+
}
108+
109+
process.stdin.setEncoding('utf-8');
110+
process.stdout.setEncoding('utf-8');
111+
112+
// Read data from stdin
113+
let inputData = '';
114+
115+
process.stdin.on('data', (chunk) => {
116+
inputData += chunk;
117+
});
118+
119+
process.stdin.on('end', () => {
120+
preprocessMdBook(JSON.parse(inputData));
121+
});

docs/src/API/README.md

-3
This file was deleted.

docs/src/BestPractices/Performance.md

-3
This file was deleted.

docs/src/BestPractices/Security.md

-3
This file was deleted.

docs/src/Build/AccountService.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Account Service
2+
3+
The Account Service provides functionalities related to user accounts on the Frequency network.
4+
It includes endpoints for managing user authentication, account details, delegation, keys, and handles.
5+
6+
## API Reference
7+
8+
[Open Direct API Reference Page](https://projectlibertylabs.github.io/gateway/account)
9+
{{#swagger-embed ../services/account/swagger.json}}
10+
11+
## Configuration
12+
13+
{{#markdown-embed ../services/account/ENVIRONMENT.md 2}}
14+
15+
## Best Practices
16+
17+
- **Secure Authentication**: Always use secure methods (e.g., JWT tokens) for authentication to protect user data.
18+
- **Validate Inputs**: Ensure all input data is validated to prevent injection attacks and other vulnerabilities.
19+
- **Rate Limiting**: Implement rate limiting to protect the service from abuse and ensure fair usage.

docs/src/Build/ContentPublishing.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Content Publishing Service
2+
3+
The Content Publishing Service allows users to create, post, and manage content on the Frequency network. It supports various content types such as text, images, and videos.
4+
5+
## API Reference
6+
7+
[Open Full API Reference Page](https://projectlibertylabs.github.io/gateway/content-publishing)
8+
{{#swagger-embed ../services/content-publishing/swagger.json}}
9+
10+
## Configuration
11+
12+
{{#markdown-embed ../services/content-publishing/ENVIRONMENT.md 2}}
13+
14+
## Best Practices
15+
16+
- **Metadata Management**: Always ensure metadata is correctly associated with content to maintain data integrity.
17+
- **Content Validation**: Validate content to prevent the submission of inappropriate or harmful material.

docs/src/Build/ContentWatcher.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Content Watcher Service
2+
3+
The Content Watcher Service monitors and retrieves the latest feed state, including content updates, reactions, and other user interactions on the Frequency network. It ensures that applications can stay up-to-date with the latest content and user activity.
4+
5+
## API Reference
6+
7+
[Open Full API Reference Page](https://projectlibertylabs.github.io/gateway/content-watcher)
8+
{{#swagger-embed ../services/content-watcher/swagger.json}}
9+
10+
11+
## Configuration
12+
13+
{{#markdown-embed ../services/content-watcher/ENVIRONMENT.md 2}}
14+
15+
## Best Practices
16+
17+
- **Efficient Polling**: Implement efficient polling mechanisms to minimize load on the service.
18+
- **Webhook Security**: Secure webhooks by verifying the source of incoming requests.
19+
- **Rate Limiting**: Apply rate limiting to prevent abuse and ensure fair usage of the service.

docs/src/Build/GraphService.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Graph Service
2+
3+
The Graph Service manages the social graphs, including follow/unfollow actions, blocking users, and other social interactions. It allows applications to maintain and query the social connections between users on the Frequency network.
4+
5+
## API Reference
6+
7+
[Open Full API Reference Page](https://projectlibertylabs.github.io/gateway/graph)
8+
{{#swagger-embed ../services/graph/swagger.json}}
9+
10+
11+
## Configuration
12+
13+
{{#markdown-embed ../services/graph/ENVIRONMENT.md 2}}
14+
15+
16+
## Best Practices
17+
18+
- **Data Integrity**: Ensure the integrity of social graph data by implementing robust validation checks.
19+
- **Efficient Queries**: Optimize queries to handle large social graphs efficiently.
20+
- **User Privacy**: Protect user privacy by ensuring that graph data is only accessible to authorized entities.

docs/src/Build/README.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Services
2+
3+
<div class="button-links">
4+
<a href="./AccountService.html">Account Service</a>
5+
<a href="./ContentPublisher.html">Content PublisherService</a>
6+
<a href="./GraphService.html">Graph Service</a>
7+
<a href="./ContentWatcher.html">Content WatcherService</a>
8+
</div>
9+
10+
![Gateway Application Microservice Diagram](../gateway_arch-TopLevelServices.drawio.png)
11+
12+
## Account Service
13+
14+
Account Service is a service enabling easy interaction with accounts on Frequency.
15+
Accounts are be defined as an `msaId` (a 64 bit identifier) and can contain additional information such as a handle, keys, and more.
16+
17+
- Account creation using [SIWF](https://github.com/ProjectLibertyLabs/siwf)
18+
- Delegation management
19+
- User Handle creation and retrieval
20+
- User key retrieval and management
21+
22+
## Graph Service
23+
24+
The Graph Service is a service enabling easy interaction with graphs on Frequency.
25+
Each Graph connection on Frequency can be private or public and can be unidirectional (a follow) or bidiectional (double opt-in friend connection).
26+
27+
- Fetch user graph
28+
- Update delegated user graphs
29+
- Watch graphs for external updates
30+
31+
## Content Publishing Service
32+
33+
The Content Publishing Service is a service enabling the creation of new content related activity on Frequency.
34+
35+
- Create posts to be broadcast publicly
36+
- Create replies to posts
37+
- Create reactions to posts
38+
- Create updates to existing content
39+
- Request deletion of content
40+
- Asset creation with [IPFS](https://ipfs.tech)
41+
42+
## Content Watcher Service
43+
44+
The Content Watcher Service is a service enabling processing external content from Frequency.
45+
Feed content through your custom webhooks to connect to the larger ecosystem of content.
46+
47+
- Parses and validates Frequency content
48+
- Filterable webhooks
49+
- Scanning control

docs/src/CoreConcepts/ApiComparison.md

-1
This file was deleted.

docs/src/CoreConcepts/BlockchainBasics.md

-1
This file was deleted.

docs/src/CoreConcepts/FrequencyArchitecture.md

-1
This file was deleted.

0 commit comments

Comments
 (0)