{"id":20017758,"url":"https://github.com/kokizzu/street","last_synced_at":"2025-05-04T23:30:39.850Z","repository":{"id":158942236,"uuid":"634184480","full_name":"kokizzu/street","owner":"kokizzu","description":"Dummy complex example how to use Fiber, Svelte-MPA, Clickhouse, Tarantool, Gotro","archived":false,"fork":false,"pushed_at":"2025-04-20T06:56:50.000Z","size":90341,"stargazers_count":17,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-20T07:42:23.596Z","etag":null,"topics":["clickhouse","gofiber","golang-application","svelte","tarantool"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kokizzu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-04-29T10:11:51.000Z","updated_at":"2025-04-20T06:56:53.000Z","dependencies_parsed_at":"2025-04-20T07:51:49.024Z","dependency_job_id":null,"html_url":"https://github.com/kokizzu/street","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kokizzu%2Fstreet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kokizzu%2Fstreet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kokizzu%2Fstreet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kokizzu%2Fstreet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kokizzu","download_url":"https://codeload.github.com/kokizzu/street/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252414101,"owners_count":21744041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clickhouse","gofiber","golang-application","svelte","tarantool"],"created_at":"2024-11-13T08:18:22.047Z","updated_at":"2025-05-04T23:30:34.830Z","avatar_url":"https://github.com/kokizzu.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Street Project\n\nPeople can find house/building to buy/sell\n\n![admin dashboard](https://github.com/kokizzu/street/assets/1061610/13b2dce6-e6ce-408f-97f5-5baa7c115196)\n![manage user](https://github.com/kokizzu/street/assets/1061610/6b089f3b-ffba-4572-b634-2fdd2acf389d)\n![home](https://github.com/kokizzu/street/assets/1061610/1db79647-1718-4cd9-8e2d-ab9673c5cf3b)\n![managed property](https://github.com/kokizzu/street/assets/1061610/c7d94e17-e538-48d4-b210-19a684b573f7)\n\n[stream links](https://docs.google.com/document/d/1ATjUVawcWBM_axQBJU2Xdcu2WkF4sz9-NSGCSDzBHJ8/edit)\n\n## Architecture\n\nnothing fancy, just normal monolith but with multiple database connection\n\n```\nbrowser --\u003e svelte+monolith --\u003e tarantool/clickhouse\nmobile  --\u003e monolith --\u003e tarantool/clickhouse\n```\n\n## Project Structure\n\n- `conf`: shared configuration\n- `main`: inject all dependencies\n- `svelte`: web frontend\n- `deploy`: scripts for deploying to production\n\nMVC-like structure\n\n- `presentation` -\u003e serialization and transport\n- `domain` -\u003e business logic, DTO\n- `model` -\u003e persistence/3rd party endpoints, DAO\n\n## CQRS\n\nseparates read/query and write/command into different database/connection.\n\n- `rq` = read/query (OLTP) -\u003e to tarantool replica\n- `wc` = write/command (OLTP) -\u003e to tarantool master\n- `sa` = statistics/analytics (OLAP) -\u003e to clickhouse\n\n## Start dev mode\n\n```shell\n# first time for development\nmake setup\n\n# start docker\ndocker compose up # or docker-compose up\n\n# start frontend auto build \ncd svelte\npnpm i \nbun watch \n\n# do migration (first time, or everytime tarantool/clickhouse docker deleted, \n# or when there's new migration)\ngo run main.go migrate\ngo run main.go import\n\n# start golang backend server, also serving static html\nair web\n\n# manually\ngo run main.go web\n\n# start reverse proxy, if you need test oauth\ncaddy run # foreground\ncaddy start # background\n```\n\n## Execute Tarantool on Docker\n\n```shell\ndocker exec -it street-tarantool1-1 tarantoolctl connect userT:passT@127.0.0.1:3301\n# box.execute [[ SELECT * FROM \"users\" LIMIT 10 ]]\n```\n\n## Execute Clickhouse on Docker\n\n```shell\ndocker exec -it street-clickhouse1-1 clickhouse-client -u userC\n# SELECT * FROM actionLogs ORDER BY createdAt DESC LIMIT 10;\n```\n\n## Generate ORM\n\n```shell\n# input: \n# - model/m*.go\n\n./gen-orm.sh\n# or\ncd model\ngo test -bench=BenchmarkGenerateOrm\n# then go generate each file\n\n# output:\n# - model/m*/rq*/*.go  # -- read/query models\n# - model/m*/wc*/*.go  # -- write/command mutation models\n# - model/m*/sa*/*.go  # -- statistic/analytics models\n```\n\n## Generate Views\n\n```shell\n# input: \n# - domain/*.go\n# - model/m*/*/*.go\n# - svelte/*.svelte\n\n./gen-views.sh\n# or\ncd presentation\ngo test -bench=BenchmarkGenerateViews \n\n# output:\n# - presentation/actions.GEN.go     # -- all possible commands\n# - presentation/api_routes.GEN.go  # -- automatic API routes\n# - presentation/web_view.GEN.go    # -- all template that can be used in web_static.go\n# - presentation/cmd_run.GEN.go     # -- all CLI commands\n# - svelte/jsApi.GEN.js             # -- all API client SDK \n```\n\n## Importing data\n\n```shell\ngo run main.go migrate\ngo run main.go import\ngo run main.go import_location # require google API key\n\n```\n\n## Manual test\n\n```shell\n# using command line\ngo run main.go cli guest/register '{\"email\":\"a@b.c\"}'\n\n# using curl\ngo run main.go web\n\ncurl -X POST -d '{\"email\":\"test@a.com\"}' localhost:1234/guest/register\n```\n\n## Deploy to Production Server\n\n```shell\ncd deploy\n./deploy.sh\n```\n\n## Note\n\n```shell\n# docker spawning failed (because test terminated improperly), run this:\nalias dockill='docker kill $(docker ps -q); docker container prune -f; docker network prune -f'\n```\n\n## FAQ\n\n- **Q**: where to put SSR?\n  - **A**: `presentation/web_static.go`\n- **Q**: got error `there is no space with name [tableName], table default.\n  [tableName] does not exists`\n  - **A**: run `go run main.go migrate` to do migration\n- **Q**: got error `Command 'caddy' not found`\n  - **A**: install [caddy](//caddyserver.com/docs/install)\n- **Q**: got error `Command 'air' not found`\n  - **A**: install [air](//github.com/cosmtrek/air) or `make setup`\n- **Q**: got error `Command 'replacer' not found`\n  - **A**: install [replacer](//github.com/kokizzu/replacer) or `make setup`\n- **Q**: got error `Command 'gomodifytags' not found`\n  - **A**: install [gomodifytags](//github.com/fatih/gomodifytags) or `make setup`\n- **Q**: got error `Command 'farify' not found`\n  - **A**: install [farify](//github.com/akbarfa49/farify) or `make setup`\n- **Q**: got error `Command 'goimports' not found`\n  - **A**: install [goimports](//cs.opensource.google/go/x/tools) or `make setup`\n- **Q**: where to put secret that I don't want to commit?\n  - **A**: on `.env.override` file\n- **Q**: got error `.env.override` no such file or directory\n  - **A**: create `.env.override` file\n- **Q**: got error `failed to stat the template: index.html`\n  - **A**: run `cd svelte; npm run watch` at least once\n- **Q**: got error `TarantoolConf) Connect: dial tcp 127.0.0.1:3301: connect: connection refused\"`\n  - **A**: run `docker-compose up`\n- **Q**: got error `ClickhouseConf) Connect: dial tcp 127.0.0.1:9000: connect: connection refused`\n  - **A**: run `docker-compose up`\n- **Q**: got error `docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))`\n  - **A**: make sure docker service is up and running\n- **Q**: what's normal flow of development?\n  - **A**: \n      1. create new/modify model on `model/m[schema]/[schema]_tables.go` folder, create benchmark function to generate and migrate the tables in `RunMigration` function.\n      2. run `./gen-orm.sh`, create helper function on `model/w[schema]/[rq|wc|sa][schema]/[schema]_helper.go` or 3rd party wrapper in `model/x[repo]/x[provider].go`\n      3. create a role in `domain/[role].go` containing all business logic for that role\n      4. write test in `domain/[role]_test.go` to make sure all business requirement are met\n      5. generate domain routes `cd presentation; go get -bench=BenchmarkGenerateViews`, start web service `air web`\n      6. write frontend on `svelte/`, start frontend service `cd svelte; npm run watch`\n      7. generate frontend helpers `cd presentation; go get -bench=BenchmarkGenerateViews`\n      8. write SSR if needed on `presentation/web_static.go`\n- **Q**: how to add additional tech stack?\n  - **A**: put on `docker-compose.yml` and add to `domain/0_main_test.go` so it would run on integration test. Create the `conf/[provider].go` and `model/x[repo]/x[provider].go` to wrap the 3rd party connector. \n- **Q**: want to change the generated views?\n  - **A**: \n      1. change the template on `presentation/1_codegen_test.go`\n      2. run `cd presentation; go get -bench=BenchmarkGenerateViews`\n- **Q**: want to change generated ORM or schema migration has bug?\n  - **A**: create a pull request to [gotro](//github.com/kokizzu/gotro) \n- **Q**: generated html have bug?\n  - **A**: create a pull request to [svelte-mpa](//github.com/kokizzu/svelte-mpa) or [svelte](//github.com/sveltejs/svelte)\n- **Q**: where is the devlog?\n  - **A**: on [youtube livestream](//www.youtube.com/@kokizzu/streams)\n- **Q**: why secrets not encrypted?\n  - **A**: it's ok for PoC phase, since it's listen to localhost\n- **Q**: run test against local `docker compose` instead of `dockertest`?\n  - **A**: set env or export `USE_COMPOSE=x` before running test\n- **Q**: how SSR works?\n  - **A**: `npm run watch` will convert `.svelte` files into `.html`, `.\n    /gen-views.sh` will generate `vew_view.GEN.go` that can be called by `web_static.go` to render the `.html` files\n- **Q**: how route generator works?\n  - **A**: everytime you make `type XXIn`, `type XXOut`, `const XXAction`, \n    and `func (d Domain) XX(in XXIn) XXOut` inside `domain/` it will be \n    automatically \n    added \n    to `api_routes.GEN.go`\n- **Q**: how orm generator works?\n  - **A**: create `model/m[schema]/[schema]_tables.go` and `model/m[schema]/\n    [schema]_tables_test.go` then run `./gen-orm.sh`, it would generate \n    `model/[rq|wc|sa][schema].go`, you can extend the method of generated \n    structs (`[rq|wc|sa][schema]`) on another file inside the same package.\n- **Q**: how basic form and list/table works?\n  - **A**: create a `[schema]Meta` on `domain/`, then just call your query \n    method based on `zCrud.Pager` (it would generate the proper SQL query), \n    then use svelte component that can render the form and table/list for you.\n- **Q**: when to use each storage engine?\n  - **A**: `memtx` used for kv query pattern, anything that often being read \n    and updated (eg. transactions), `vinyl` used for range queries, anything \n    that rarely being updated (eg. mutation log, history), `clickhouse` used \n    for analytics queries pattern, anything that will never being updated \n    ever (eg. action logs, events)\n- **Q**: got `street/_tmpdb/*: open /*/street/*: permission denied` on `go mod tidy`\n  - **A**: run `sudo chmod a+rwx -R _tmpdb` or `make modtidy`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkokizzu%2Fstreet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkokizzu%2Fstreet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkokizzu%2Fstreet/lists"}