Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sveri/stockfighter


https://github.com/sveri/stockfighter

Last synced: about 2 months ago
JSON representation

Awesome Lists containing this project

README

        

# ** THIS CODE CONTAINS SPOILERS **

# stockfigherui

Your new project at

Username: [email protected]
Password: admin

## Usage

1. Run `lein joplin migrate sqlite-dev-env` in the newly created project (This will add an admin user with username:
[email protected]_ and password: _admin_ to a new database)
2. Run `lein repl` and then `(start-dev-system)` to run the application in dev mode.
3. Run `lein figwheel` to start figwheel and compile the clojurescript.
4. Run `lein rel-jar` to generate a runnable jar file.

## Features
* closp-crud integration
* H2 database on filesystem as a default
* Joplin for database migrations
* Selmer as templating solution
* http-kit as a server
* cljc support
* Figwheel with clojurescript live reloading
* Reloading support for templates and clojure code
* Configuration with nomad
* User management with login/logout/registration with email activation (provided by postal)
* Authentication provided by buddy
* reagent and datascript on frontend side
* Ring Antiforgery middleware
* Clojure miniprofiler example
* Componentized application
* Datascript with reagent example
* Booststrap css styles
* Example for clj-webdriver tests
* Internationalization using tower

## Docker

There is a dockerfile attached which will fetch the latest version and run an example project.

## Configuration

There is a closp.edn file in the resources folder which should be adapted accordingly.
Closp uses nomad , so you can configure everything as you can do with nomad.
When you start your project from the repl it will load the default `closp.edn` from `resources` folder, which fits
for development.
For a different config in another environment you can pass in a file path via system environment setting like so:
`java -jar -Dclosp-config-path=C:\\path\\to\\iwf-prod.edn closp.jar`.
Please think of changing the :env key in the config to :prod instead of :dev when changing to a different
environment.

## closp-crud

This is a module that generates html, routing and sql files for a given table definition. For more
information please look here: .

## Database

Closp per default is configured to connect to a file H2 database.
Additionally I added support for joplin to handle migration of sql scripts.
To get started run `lein joplin migrate sql-dev-env` in the project folder. This is enough to get running.
Changing the jdbc url in the *closp.edn* file will switch to another database. But keep in mind you will have to
run the migration step again and change the jdbc url in the project.clj too.
The connection is handled by jdbc so everything that jdbc supports is supported
by closp out of the box.
Closp comes with korma for an abstraction layer over jdbc. See `db\users.clj` for
how it is used.

## Authentication and Authorization

We use the buddy () library for this.
Configuration is done in _ns.service.auth_
There is a concept of roles, _admin_ and _none_ are alreaded provided, you can add more in the auth namespace.
Or, create a database storage for this.
Next you can find a _rules_ def in the _auth_ namespace which defines the access rules for every available link. For
more information please look at the buddy documentation.

## Templating

Closp ships with selmer (django inspired) templating solution.

## Signup

There is a signup workflow implemented that sends out an email after regristration with a link to activate the account.
Until the account is activated the user won't be able to login.

## Recaptcha

The signup form is protected by recaptcha. To make it work open your closp.edn file and fill these values properly:
* :captcha-public-key
* :private-recaptcha-key
* :recaptcha-domain

## Admin user interface

Closp ships with an administrator interface (/admin/users) to activate / deactivate users and set roles accordingly.
There is also an option to add new users.

## Reloading of clojure code and templates

In dev mode changes the clojure code will be recompiled and reloaded on page refresh. The same is true for the templates.
Theoretically this results development without server restarts.

## Clojurescripth with figwheel

When running in dev mode cljs files will be auto compiled and sent to the browser via figwheel
.
If you want to autoload a different cljs function you have to adapt dev.cljs and the project.clj file at
[:cljsbuild :dev :figwheel].

## Email system

Closp uses postal for sending authentication links. This can be configured in closp.edn.

## Components

Closp comes with some predefined components

* Handler component
* Configuration component
* Database component
* Webserver component

To restart the components just hit `(reset)` in the running repl.

## Ring antiforgery

is enabled per default for every shipped form.
If you use ajax post / put / ... calls you need to provide a :X-CSRF-Token in the header. With cljs-ajax for example
it would look like this:

(ajax/ajax-request
{:uri url
:method method
:params content
:headers {:X-CSRF-Token (get-value "glob_anti_forgery")}})

## Transit and cljs-ajax

There is an example on how to use cljs-ajax for doing ajax requests to the server. The request will use transit as
a transport format. You can find that at the uri: `"/ajax/page/init"` and in the `ajax.cljs` file.
You need to run `lein figwheel` at least once to compile the clojurescript.
And finally open the `dev.cljs` namespace and change the requiring namespace from
`(:require [f.d.core :as core])` to `(:require [f.d.ajax :as core])`

## Reagent and Datascript

Closp includes a reagent and datascript
example taken from to get started
with frontend development.

## Support for flash messages with global flash div
To use it call (layout/flash-result "success message" "alert-success") and on the next page load
a div will appear with the success message on top of the page.

## Production

There is a leiningen task defined in the _project.clj_ to generate an uberjar. Just execute `lein uberjar`.
By default this will include your closp.edn config file in the build from resources folder. You should at least change
the :env entry to :prod or something else than :dev.
There are several ways to setup a more separated dev / staging / prod environment. Please lookup nomad for that.

## Internationalization

Closp uses for internationalization. It is configured as a component in
`your.ns.components.locale`. You have to add additional strings / translations there to use them in your web
application. For examples look at `your.ns.routes.user`.

## CLJ-Webdriver

Closp comes with some examples on how to use clj webdriver in your projects for integration tests. They reside in
`integtest\clj`.

Currently the support is some kind of tricky regarding support of latest firefox versions. Please look in the
`profiles->dev->ddependencies` section of the `project.clj` file for some comments on this matter. It is possible to use
both, the htmlunitdriver and an older firefox version or only a newer firefox version.

## Minor features.

* Miniprofiler example in `routes\user.clj -> admin-page function`.
The profiler is enabled in development only
* Namspace support: Add `-n name.space` option to `lein new closp projectname` to provide a namespace for the source
files.
* Self registration can be turned on or off in the closp.edn file in the resources folder.
* Test2junit plugin to create parseable test results.

## Planned features

* CRUD plugin to generate frontend to database CRUD for entities
* Whatever seems useful in the future.

## FAQ

### Could not find environment ':sqlite-dev-env'

Leiningen 2.5.2 introduced a change which broke existing joplin versions. You have to update your joplin dependencies
to at least 0.2.17 to make it work with leiningen 2.5.2

### I get this warning: Uncaught Error: Invariant Violation: _registerComponent(...): Target container is not a DOM element.

This will happen only in dev mode for every page where you did not explicitly register your clojurescript with.
Look at dev.cljs for this line `:jsload-callback (fn [] (core/main))` and change the call to `(core/main)` how you
need it for the page you are working on right now.

## License

Copyright © 2015 Sven Richter

Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.