Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation #238

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,5 @@ pom.xml.asc
.clj-kondo/*
!.clj-kondo/config.edn
*.iml
/node_modules/
/package.json
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
![Xiana logo](resources/images/Xiana.png)
![Xiana logo](doc/resources/images/Xiana.png)

# Xiana framework

Xiana is a lightweight web-application framework written in Clojure, for Clojure. The goal is to be simple, fast, and
most importantly - a welcoming platform for web programmers with different backgrounds who want to experience the wonders
of functional programming!
most importantly - a welcoming platform for web programmers with different backgrounds who want to experience the
wonders of functional programming!

It's easy to install, fun to experiment with, and a powerful tool to produce monolithic web applications.

Expand All @@ -16,7 +17,9 @@ Xiana has its own Leiningen template, so you can create a skeleton project with
```shell
lein new xiana app
```
[getting-started](./doc/getting-started.md) explains how to use this to create a very simple app with a db, a backend offering an API, and a frontend that displays something from the database.

[getting-started](./doc/getting-started.md) explains how to use this to create a very simple app with a db, a backend
offering an API, and a frontend that displays something from the database.

### As a dependency

Expand All @@ -28,8 +31,6 @@ Add it to your project as a dependency from clojars:

- First check out the [conventions](./doc/conventions.md).
- To start working with xiana, read the [tutorials](./doc/tutorials.md).
- A hands-on approach in the [how-to](./doc/How-To.md)s.
- Check the available [modules](./doc/modules.md), and [interceptors](./doc/interceptors.md).
- To contribute, see the [contribution](./doc/contribution.md) docs.

### Examples
Expand All @@ -45,5 +46,7 @@ Visit [examples folder](examples), to see how you can perform
## References

### Concept of interceptors

http://pedestal.io/reference/interceptors

https://github.com/metosin/sieppari
19 changes: 13 additions & 6 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@
{:extra-deps {clj-kondo/clj-kondo {:mvn/version "2022.05.31"}}
:main-opts ["-m" "clj-kondo.main" "--lint" "src"]}

:codox {:extra-deps {codox/codox {:mvn/version "0.10.8"}}
:codox {:extra-deps {codox/codox {:mvn/version "0.10.8"}}
:extra-paths ["resources"]
:exec-fn codox.main/generate-docs
:exec-args {:output-path "docs/new/"
:themes [:default :xiana]
:source-paths ["src"]
:doc-files ["doc/getting-started.md", "doc/How-To.md", "doc/Development-Guide.md"]}}
:exec-fn codox.main/generate-docs
:exec-args {:output-path "docs/new/"
:themes [:default :xiana]
:metadata {:doc/format :markdown}
:source-uri "https://github.com/Flexiana/framework/blob/{git-commit}/{filepath}#L{line}"
:source-paths ["src"]
:doc-files ["doc/welcome.md"
"doc/conventions.md"
"doc/tutorials.md"
"doc/how-to.md"
"doc/contribution.md"
"doc/getting-started.md"]}}

:kibit
{:extra-deps {tvaughan/kibit-runner {:mvn/version "1.0.1"}}
Expand Down
27 changes: 0 additions & 27 deletions doc/Development-Guide.md

This file was deleted.

71 changes: 64 additions & 7 deletions doc/contribution.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
<img src="resources/images/Xiana.png" width="242">

# Contribution

- [Ticket system](#ticket-system)
- [Coding standards](#coding-standards)
- [Submitting a PR](#submitting-a-pr)
- [Development dependencies](#development-dependencies)
- [Setup](#setup)
- [Deps](#deps)
- [Releasing](#releasing)
- [Generating API docs](#generating-api-docs)

## Ticket system

We're using GitHub [issues](https://github.com/Flexiana/framework/issues) for tracking and discussing ideas and
requests.

## Coding standards

Please follow `clj-style` and `kondo` instructions. `Kibit` isn't a showstopper, but PRs are more welcomed if not
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"...more welcome if they don't break kibit.'

breaking `kibit`.

## Submitting a PR

Before you are submitting a PR be sure:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Before you submit a PR be sure:"


- You've updated the documentation and the [CHANGELOG](../CHANGELOG.md)
- the PR has an issue in GitHub, with a good description
- you have added tests
- you provided an example project for a new feature
- All PRs need at least two approvals
Copy link
Contributor

@soulflyer soulflyer Oct 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't really belong in a list of things to check. Maybe just move it to its own paragraph after the list.

- Follow [Semantic Versioning 2.0.0](https://semver.org/#semantic-versioning-200)

## Development dependencies

Expand Down Expand Up @@ -31,12 +58,8 @@
| nilenso/honeysql-postgres | 0.2.6 | PostGreSQL |
| org.postgresql/postgresql | 42.2.2 | PostGreSQL |
| crypto-password/crypto-password | 0.2.1 | Security |

#### Optional

| Name | Version | Provide |
|---------------------|---------|---------|
| clj-kondo/clj-kondo | RELEASE | Tests |
| clj-kondo/clj-kondo | RELEASE | Tests |
| npx | RELEASE | Documentation |

## Setup

Expand Down Expand Up @@ -84,4 +107,38 @@ clj -M:install

- Be sure all examples has the same framework version as it is in `release.edn` as dependency
- Execute `./example-tests.sh` script. It will install the actual version of xiana, and go through the examples folder
for `check-style` and `lein test`.
for `check-style` and `lein test`.

## Generating API Docs

This is done with using [mermaid-cli](https://github.com/mermaid-js/mermaid-cli) and a forked version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either "with" or "using". Not both.

of [Codox](https://github.com/Flexiana/codox).

We're using mermaid-cli for render UML-diagrams in markdown files, see the `doc/conventions_template.md` for example.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"...mermaid-cli to render..."

These files need to be added to the `/script/build-docs.sh` . For using it you need to have `npx`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"To use it you need...."


Codox is forked because markdown anchors aren't converted to HTML anchors in the official release. For use, you need to

```shell
git clone [email protected]:Flexiana/codox.git
cd codox/codox
lein install
```

it before generating the documentation.

To generate or update the current version run the script:

```shell
./script/build-docs.sh
```

This runs the following:

```shell
npx -py @mermaid-js/mermaid-cli mmdc -i doc/conventions_template.md -o doc/conventions.md
clj -X:codox
mv docs/new docs/{{version-number}}
```

It also updates the index.html file to point to the new version.
1 change: 1 addition & 0 deletions doc/conventions-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions doc/conventions-2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions doc/conventions-3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 30 additions & 7 deletions doc/conventions.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
<img src="resources/images/Xiana.png" width="242">

# Conventions

- [Overview](#overview)
- [State](#state)
- [Action](#action)
- [Handler](#handler)
- [Dependencies](#dependencies)
- [Interceptors](#interceptors)
- [Interceptors error handling](#interceptors-error-handling)

## Overview

The diagram bellow gives you an overview, how a request is processed in Xiana based applications.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"... an overview of how a request..."

![diagram](./conventions-1.svg)
## State

A state record. It is created for each HTTP request and represents the current state of the application. It contains:
State is created for each HTTP request and represents the current state of the application. It contains:

- the application's dependencies
- the application's dependencies and configuration
- request
- request-data
- response
Expand Down Expand Up @@ -49,11 +57,11 @@ Actions are defined in the routes vector

## Handler

Xiana's handler does all the processing. It runs on every request and does the following. It creates the state for every
request, matches the appropriate route, executes the interceptors, handles interceptor overrides, and not-found cases.
Xiana's handler creates the state for every request, matches the appropriate route, executes the interceptors, handles
interceptor overrides, and not-found cases.
It handles websocket requests too.

### Routing
## Routing

Routing means selecting the actions to execute depending on the request URL, and HTTP method.

Expand All @@ -64,5 +72,20 @@ the state on state creation, and defined on application startup.

## Interceptors

An interceptor is a pair of unary functions. Each function must recieve and return a state map. You can look at it as on an analogy to AOP's around aspect, or as on a pair of middlewares. They work mostly the same way as [pedestal](http://pedestal.io/reference/interceptors) and [sieppari](https://github.com/metosin/sieppari) interceptors.
Xiana provides a set of base [interceptors](interceptors.md), for the most common use cases.
An interceptor is a pair of unary functions. Each function must recieve and return a state map. You can look at it as on
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"look at it as an analogy...."

an analogy to AOP's around aspect, or as on a pair of middlewares. They work mostly the same way
as [pedestal](http://pedestal.io/reference/interceptors) and [sieppari](https://github.com/metosin/sieppari)
interceptors.
Xiana provides a set of base interceptors, for the most common use cases.

This figure shows how interceptors are executed ideally:
![diagram](./conventions-2.svg)
## Interceptors error handling:

The interceptor executor handles the exceptional states like sieppari does. If an exception happens, it tries to handle
first in the same interceptor. If it has and `:error` handler, it will call it, otherwise it'll search for `:error`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"If it has an..."

handlers for the beginning of the interceptor queue. When and `:error` function found, and matched with the given
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should "for" be "from"?
"When an :error function..."

exception, the executor calls the queue `:leave` functions in reserved order, where the handler has been found.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe "...calls the queue of :leave functions in reverse order from where the handler was found.


This diagram shows how the error cases handled:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"..cases are handled:"

![diagram](./conventions-3.svg)
Loading