Skip to content

Commit

Permalink
Add code_structure & database_design doc
Browse files Browse the repository at this point in the history
Signed-off-by: Arnob kumar saha <arnob@appscode.com>
  • Loading branch information
ArnobKumarSaha committed May 12, 2024
1 parent 50b155d commit 9b74072
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 0 deletions.
51 changes: 51 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Description on each of the packages

# cmd
Under the root command, there is only one subcommand named start_server. We use the routers package from it & start the server.

# routes
We have these types of routes:

`user_auth`: signUp, signIn, signOut

`course`:
i) get/list -> general authenticated users can do it.
ii) create/update -> admin or moderators can do.
iii) delete -> only admin can do it.

For get,update & delete calls(those work on a specific course uid), we utilize a context middleware for injecting context data.

There is one special route for providing role to a user. It requires the admin access.

# pkg
-`pkg.auth`:

We store these fields in the redis session:
i) authenticated, ii) role, iii) userName, iv) userIP, v) user_agent
There are some getters implemented in the session.go file.



-`pkg.error`

-`pkg.middleware`:

There are 4 types of middlewares in this package.
i) global middleware: For example logger, urlFormatter etc.

ii) common security middleware: To check if a session is valid & authenticated.

iii) access related middleware: To check if the role(in session) is matched.

iv) context middleware: To append additional info to the context.


# handlers
routes -> handlers -> models

# models
1) `models.course`
2) `models.db`
3) `models.user`


106 changes: 106 additions & 0 deletions docs/database_design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
## API
```
type Course struct {
CourseId string `json:"courseId" bson:"_id"`
Title string `json:"title" bson:"title"`
Description string `json:"description" bson:"description"`
Instructors []string `json:"instructors" bson:"instructors"`
Moderators []string `json:"moderators" bson:"moderators"`
StartDate date.Date `json:"startDate" bson:"startDate"`
EndDate date.Date `json:"endDate" bson:"endDate"`
Duration int `json:"duration" bson:"duration"` // Duration in week
Capacity int `json:"capacity" bson:"capacity"`
Students []string `json:"students" bson:"students"`
Price string `json:"price" bson:"price"`
}
type Lesson struct {
UUID string `json:"uuid" bson:"uuid"`
Serial string `json:"uuid" bson:"serial"`
Title string `json:"title" bson:"title"`
Content []string `json:"content" bson:"content"`
}
type Content struct {
ID string `json:"uuid" bson:"_id"`
Name string `json:"Name" bson:"name"`
Type string `json:"type" bson:"type"` // video, resource, quiz, lab
}
```


## A complete Example
```
Course name: Mastering golang
Lessons:
Introduction:
Why Go?
Installation
<resources>
<quiz>
Concurrency in Go:
channels
mutex
<lab1>
<resources>
go routines
<lab2>
Conclusion
thank you
```

For the lab1 under 'Concurrency in Go', url will be like:
http://praromvik.com/course/mastering_golang/concurrency_lab_1/
Intentionally cutting off the lesson id part to keep the url shorter.

So the restrictions are:
i) course ids have to be unique.
ii) content ids within a course have to be unique.
iii) both course & content ids have to be <= 24 characters, as they will be used as _id in mongodb.


### `praromvik.courses` collection
```
{
"_id": "mastering_golang",
"title": "Mastering Golang",
"instructors": []string{<some_user_ids>},
"students": []string{<some_user_ids>}
}
```
### `mastering_golang.lessons` collection
```
{
"_id": "<mongo-generated-id>",
"title": "Introduction",
"serial": 1,
"contents": []string{<_ids>}
},
{
"_id": "<mongo-generated-id>",
"title": "Concurrency in Go",
"serial": 2,
"contents": []string{"channel", "concurrency_lab_1", "resouce_from_doc"}
}
```

### `mastering_golang.contents` collection
```
{
"_id": "channel",
"name": "Channel",
"type": "Video"
},
{
"_id": "concurrency_lab_1",
"name": "Hands-on the Go channel",
"type": "Lab"
},
{
"_id": "resouce_from_doc",
"name": "Additional learing resouces",
"type": "Written"
},
```

0 comments on commit 9b74072

Please sign in to comment.