···11+# sfsu 317 final project
22+33+Decentralized collaborative code challenges platform built on ATProto. Create
44+challenges and face your friends on various metrics (code length, runtime and
55+more!).
66+77+The goal is just to have a neat place to challenge you are your friends on dumb
88+on some golf code or stupid optimization problems. You could do a challenge
99+where you have to have as little as possible python code, or the fastest C as
1010+an optimization problem, or even the shortest assembly generated code (with gcc,
1111+no LLVM compilers).
1212+1313+1414+## data ownership
1515+1616+All your data is yours. You'll connect to the application using your
1717+[internet handle](https://internethandle.org/) (aka. atproto identity, also
1818+known as bluesky account).
1919+2020+All the data you'll produce will be stored on your
2121+[PDS](https://atproto.com/guides/data-repos) (Personal Data Server). When you
2222+create a challenge, create tests cases, solutions, etc. everything is stored
2323+on your PDS by default (you can store it privately on the platform, but this
2424+is opt-in by design). The problems you'll write solutions for will be stored
2525+on your PDS by default as well.
2626+2727+The goal is to allow users to own their data, be able to change platforms as
2828+they see fit, even after the project dies. As long as their account exists
2929+on *THEIR* PDS, they can access their data and continue using it. For the
3030+moment, we wont permit the creation of new accounts on this app, users will have
3131+to create it on any other platform on the atmosphere (as it requires more
3232+unesserary deployment complexity). I want to have the platform as open as
3333+possible. The user with just have to log in with their handle/did, complete
3434+the OAuth flow with their PDS, and then they can start using the platform
3535+without having to create an account on this platform.
3636+3737+3838+## data / lexicon
3939+4040+This is a draft, but we could imagine the collections:
4141+```mermaid
4242+%%{init: {'theme': 'default', 'themeVariables': {'fontFamily': 'monospace'}}}%%
4343+4444+erDiagram
4545+4646+ User["com.example.user (user's PDS)"] {
4747+ string did "DID"
4848+ string handle "e.g. alice.bsky.social"
4949+ blob avatar "profile picture"
5050+ }
5151+5252+ Problem["com.example.problem (creator's PDS)"] {
5353+ string rkey "TID"
5454+ string title ""
5555+ string description "markdown body"
5656+ string difficulty "easy | medium | hard"
5757+ string_array tags "e.g. dp, graphs"
5858+ string_array supportedLangs "python, js, rust, etc."
5959+ blob starterCode "optional"
6060+ datetime createdAt ""
6161+ }
6262+6363+ TestCase["com.example.testcase (creator's PDS)"] {
6464+ string rkey "TID"
6565+ at_uri problem "-> problem"
6666+ string input ""
6767+ string expected ""
6868+ bool hidden "hidden from solvers"
6969+ }
7070+7171+ Solution["com.example.solution (solver's PDS)"] {
7272+ string rkey "TID"
7373+ at_uri problem "-> problem (cross-PDS)"
7474+ string lang "language used"
7575+ blob code "solution source"
7676+ datetime submittedAt ""
7777+ }
7878+7979+ ExecutionResult["execution_results (centralized DB)"] {
8080+ uuid id ""
8181+ string solutionUri "at:// of solution"
8282+ int runtimeMs ""
8383+ int memoryKb ""
8484+ int passedTests ""
8585+ int totalTests ""
8686+ jsonb perTestResults "per-test breakdown"
8787+ timestamp executedAt ""
8888+ }
8989+9090+ User ||--o{ Problem : "creates"
9191+ User ||--o{ Solution : "submits"
9292+ Problem ||--o{ TestCase : "has"
9393+ Problem ||--o{ Solution : "solved by"
9494+ Solution ||--o{ ExecutionResult : "produces"
9595+```
9696+9797+9898+## stack + deployment strategy
9999+100100+The app was planned to be a Golang + SvelteKit app deployed on Cloudflare
101101+workers, but because of too many issues with the Go app compiled to WASM
102102+on the workers runtime, I decided to switch to a full-stack app using
103103+[Tanstack Start](https://tanstack.com/start/latest) + [Solid](https://www.solidjs.com/).
104104+105105+The app is going to be deployed automatically on Cloudflare workers by a
106106+Continuous Integration & Deployment [pipeline](./.github/workflows/frontend.yml)
107107+using GitHub Actions, with decentralized data ownership using [ATProto](https://atproto.com/)
108108+and a [Cloudflare D1](https://developers.cloudflare.com/d1/) database for
109109+storing data alongside that won't be stored on the atmosphere. The deployment
110110+and database both will be deployed on serverless technologies because of its
111111+deployment as code strategy and near-zero cost for early projects such as this
112112+one.
113113+114114+For the text editor, I'll probably go with a [Monaco Editor](https://microsoft.github.io/monaco-editor/).
115115+running on the client-side (maybe integrating local WASM lsps later), and will
116116+use an external service dedicated to executing the code in a containerized,
117117+reproducible environment. Some examples may include [sprites.dev](https://sprites.dev/)
118118+and [judge0](https://judge0.com) or even a custom solution with Docker.
119119+120120+121121+## development environment
122122+123123+I setuped a reproducible development environment using a [Nix](https://nixos.org/)
124124+flake. The whole project uses the [pnpm](https://pnpm.io/) package manager,
125125+and uses [Typescript](https://www.typescriptlang.org/) everywhere. It uses
126126+[Tanstack Start](https://tanstack.com/start/latest/), [Solid](https://www.solidjs.com/),
127127+[Tailwind](https://tailwindcss.com/). I will use [Prisma](https://www.prisma.io/)
128128+as a database ORM, alongside [Tanstack Query](https://tanstack.com/query/latest/),
129129+and the [@atcute](https://github.com/mary-ext/atcute) atproto tools ecosystem
130130+(OAuth, Lexicons, etc.).
131131+132132+133133+## acknowledgements
134134+135135+Code competitive platforms:
136136+- [codewars](https://www.codewars.com/)
137137+- [leetcode](https://leetcode.com/) (more data-structure focused)
138138+- [codingame](https://www.codingame.com/) (more game-focused)
139139+140140+ATProto apps using decentralized ATProto data ownership:
141141+- [bluesky](https://bsky.app/)
142142+- [tangled](https://tangled.org/)
143143+- [margin](https://margin.at/)
144144+145145+To be fair, this project is both because I wanted a platform like that where I
146146+could easily create dump contests with my friends, but I also really wanted to
147147+hack on the atmosphere :)